Skip to content

Commit

Permalink
fix(compatibility): fix the platform index name
Browse files Browse the repository at this point in the history
  • Loading branch information
Desvelao committed Nov 7, 2022
1 parent 690cddb commit 1410f29
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
18 changes: 13 additions & 5 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ declare module 'kibana/server' {

export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
private readonly logger: Logger;
private savedObjectsIndex: string

constructor(private readonly initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
this.savedObjectsIndex = '';
}

public async setup(core: CoreSetup, plugins: PluginSetup) {
this.logger.debug('Wazuh-wui: Setup');
this.savedObjectsIndex = core.savedObjects.getKibanaIndex();

const serverInfo = core.http.getServerInfo();

Expand Down Expand Up @@ -132,7 +135,8 @@ export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
logger: this.logger.get('initialize'),
api: wazuhApiClient
},
server: contextServer
server: contextServer,
savedObjectsIndex: this.savedObjectsIndex
});

// Migration tasks
Expand All @@ -142,7 +146,8 @@ export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
logger: this.logger.get('migration-task'),
api: wazuhApiClient
},
server: contextServer
server: contextServer,
savedObjectsIndex: this.savedObjectsIndex
});

// Monitoring
Expand All @@ -152,7 +157,8 @@ export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
logger: this.logger.get('monitoring'),
api: wazuhApiClient
},
server: contextServer
server: contextServer,
savedObjectsIndex: this.savedObjectsIndex
});

// Scheduler
Expand All @@ -162,7 +168,8 @@ export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
logger: this.logger.get('cron-scheduler'),
api: wazuhApiClient
},
server: contextServer
server: contextServer,
savedObjectsIndex: this.savedObjectsIndex
});

// Queue
Expand All @@ -172,7 +179,8 @@ export class WazuhPlugin implements Plugin<WazuhPluginSetup, WazuhPluginStart> {
logger: this.logger.get('queue'),
api: wazuhApiClient
},
server: contextServer
server: contextServer,
savedObjectsIndex: this.savedObjectsIndex
});
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions server/start/cron-scheduler/scheduler-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const checkPluginPlatformStatus = async function (context) {
const checkElasticsearchServer = async function (context) {
try {
const data = await context.core.elasticsearch.client.asInternalUser.indices.exists({
index: context.server.config.kibana.index
index: context.savedObjectsIndex
});

return data.body;
return data;
} catch (error) {
log('scheduler-handler:checkElasticsearchServer', error.message || error);
return Promise.reject(error);
Expand Down
4 changes: 2 additions & 2 deletions server/start/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getSettingDefaultValue, getSettingsDefault } from '../../../common/serv


export function jobInitializeRun(context) {
const PLUGIN_PLATFORM_INDEX = context.server.config.kibana.index;
const PLUGIN_PLATFORM_INDEX = context.savedObjectsIndex;
log('initialize', `${PLUGIN_PLATFORM_NAME} index: ${PLUGIN_PLATFORM_INDEX}`, 'info');
log('initialize', `App revision: ${packageJSON.revision}`, 'info');

Expand Down Expand Up @@ -274,7 +274,7 @@ export function jobInitializeRun(context) {
const response = await context.core.elasticsearch.client.asInternalUser.indices.exists({
index: PLUGIN_PLATFORM_INDEX
});
if (response.body) {
if (response) {
// It exists, initialize!
await init();
} else {
Expand Down
4 changes: 2 additions & 2 deletions server/start/monitoring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ async function checkPluginPlatformStatus(context) {
async function checkElasticsearchServer(context) {
try {
const data = await context.core.elasticsearch.client.asInternalUser.indices.exists({
index: context.server.config.kibana.index
index: context.savedObjectsIndex
});

return data.body;
return data;
// TODO: check if Elasticsearch can receive requests
// if (data) {
// const pluginsData = await this.server.plugins.elasticsearch.waitUntilReady();
Expand Down

0 comments on commit 1410f29

Please sign in to comment.