wazuh-kibana-app/public/services/config-handler.js
Jesús Ángel a78c564a80
Update numbered branch with latest additions from #1331 (#1338)
* Changed event logic along controllers and services

* Removed autocomplete. Fix Discover button

*  Adapt Wazuh app for Kibana v6.7.0 (#1334)

* Adapt kibana app for elastic 6.7.0

* Adapt kibana app for elastic 6.7.0

* Fixed discover

* Prettier

* Update 6.7 files

* Update 6.7 loader

* Prettier

* Minor style fixes

* Bump Kibana version, updated README

* Corrected interval from "h" to "auto"

* Overwrite top nav style for 6.7.0

* Backport app icon

* Fix $injector
2019-04-01 10:04:24 +02:00

141 lines
3.7 KiB
JavaScript

/*
* Wazuh app - Group handler service
* Copyright (C) 2015-2019 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
export class ConfigHandler {
constructor($rootScope, apiReq, errorHandler) {
this.apiReq = apiReq;
this.$rootScope = $rootScope;
this.errorHandler = errorHandler;
}
/**
* Send ossec.conf content for manager (single-node API call)
* @param {*} content XML raw content for ossec.conf file
*/
async saveManagerConfiguration(content) {
try {
const result = await this.apiReq.request(
'POST',
`/manager/files?path=etc/ossec.conf&overwrite=true`,
{ content, origin: 'xmleditor' }
);
return result;
} catch (error) {
return Promise.reject(error);
}
}
/**
* Send ossec.conf content for a cluster node
* @param {*} node Node name
* @param {*} content XML raw content for ossec.conf file
*/
async saveNodeConfiguration(node, content) {
try {
const result = await this.apiReq.request(
'POST',
`/cluster/${node}/files?path=etc/ossec.conf&overwrite=true`,
{ content, origin: 'xmleditor' }
);
return result;
} catch (error) {
return Promise.reject(error);
}
}
async performClusterRestart() {
try {
await this.apiReq.request('PUT', `/cluster/restart`, { delay: 15000 });
this.$rootScope.$broadcast('removeRestarting', {});
} catch (error) {
this.$rootScope.$broadcast('removeRestarting', {});
this.errorHandler.handle(error, 'Error restarting cluster');
}
}
/**
* Restart manager (single-node API call)
*/
async restartManager() {
try {
const validationError = await this.apiReq.request(
'GET',
`/manager/configuration/validation`,
{}
);
const data = ((validationError || {}).data || {}).data || {};
const isOk = data.status === 'OK';
if (!isOk && Array.isArray(data.details)) {
const str = data.details.join();
throw new Error(str);
}
const result = await this.apiReq.request('PUT', `/manager/restart`, {});
return result;
} catch (error) {
return Promise.reject(error);
}
}
/**
* Restart cluster
*/
async restartCluster() {
try {
const validationError = await this.apiReq.request(
'GET',
`/cluster/configuration/validation`,
{}
);
const data = ((validationError || {}).data || {}).data || {};
const isOk = data.status === 'OK';
if (!isOk && Array.isArray(data.details)) {
const str = data.details.join();
throw new Error(str);
}
this.performClusterRestart();
return { data: { data: 'Restarting cluster' } };
} catch (error) {
return Promise.reject(error);
}
}
/**
* Restart a cluster node
*/
async restartNode(node) {
try {
const validationError = await this.apiReq.request(
'GET',
`/cluster/${node}/configuration/validation`,
{}
);
const data = ((validationError || {}).data || {}).data || {};
const isOk = data.status === 'OK';
if (!isOk && Array.isArray(data.details)) {
const str = data.details.join();
throw new Error(str);
}
const result = await this.apiReq.request(
'PUT',
`/cluster/${node}/restart`,
{}
);
return result;
} catch (error) {
return Promise.reject(error);
}
}
}