mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 18:05:20 +00:00
Healthcheck - "controller as"
This commit is contained in:
parent
48217d86d4
commit
2b908c04a0
@ -39,7 +39,7 @@ class HealthCheck {
|
||||
this.errorHandler = errorHandler;
|
||||
this.wazuhConfig = wazuhConfig;
|
||||
this.$window = $window;
|
||||
this.$scope.results = [];
|
||||
this.results = [];
|
||||
|
||||
this.savedObjectsClient = Private(SavedObjectsClientProvider);
|
||||
|
||||
@ -50,13 +50,17 @@ class HealthCheck {
|
||||
template: true
|
||||
};
|
||||
|
||||
this.$scope.errors = [];
|
||||
this.$scope.processedChecks = 0;
|
||||
this.$scope.totalChecks = 0;
|
||||
this.errors = [];
|
||||
this.processedChecks = 0;
|
||||
this.totalChecks = 0;
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
handleError(error) {
|
||||
this.$scope.errors.push(
|
||||
this.errors.push(
|
||||
this.errorHandler.handle(error, 'Health Check', false, true)
|
||||
);
|
||||
}
|
||||
@ -70,34 +74,34 @@ class HealthCheck {
|
||||
const patternTitle = data.attributes.title;
|
||||
|
||||
if (this.checks.pattern) {
|
||||
const i = this.$scope.results.map(item => item.id).indexOf(2);
|
||||
const i = this.results.map(item => item.id).indexOf(2);
|
||||
const patternData = await this.genericReq.request(
|
||||
'GET',
|
||||
`/elastic/index-patterns/${patternTitle}`
|
||||
);
|
||||
if (!patternData.data.status) {
|
||||
this.$scope.errors.push('The selected index-pattern is not present.');
|
||||
this.$scope.results[i].status = 'Error';
|
||||
this.errors.push('The selected index-pattern is not present.');
|
||||
this.results[i].status = 'Error';
|
||||
} else {
|
||||
this.$scope.processedChecks++;
|
||||
this.$scope.results[i].status = 'Ready';
|
||||
this.processedChecks++;
|
||||
this.results[i].status = 'Ready';
|
||||
}
|
||||
}
|
||||
|
||||
if (this.checks.template) {
|
||||
const i = this.$scope.results.map(item => item.id).indexOf(3);
|
||||
const i = this.results.map(item => item.id).indexOf(3);
|
||||
const templateData = await this.genericReq.request(
|
||||
'GET',
|
||||
`/elastic/template/${patternTitle}`
|
||||
);
|
||||
if (!templateData.data.status) {
|
||||
this.$scope.errors.push(
|
||||
this.errors.push(
|
||||
'No template found for the selected index-pattern.'
|
||||
);
|
||||
this.$scope.results[i].status = 'Error';
|
||||
this.results[i].status = 'Error';
|
||||
} else {
|
||||
this.$scope.processedChecks++;
|
||||
this.$scope.results[i].status = 'Ready';
|
||||
this.processedChecks++;
|
||||
this.results[i].status = 'Ready';
|
||||
}
|
||||
}
|
||||
if (!this.$scope.$$phase) this.$scope.$digest();
|
||||
@ -119,13 +123,13 @@ class HealthCheck {
|
||||
JSON.stringify({ name: apiRaw.name, id: data.data.idChanged })
|
||||
);
|
||||
}
|
||||
const i = this.$scope.results.map(item => item.id).indexOf(0);
|
||||
const i = this.results.map(item => item.id).indexOf(0);
|
||||
if (data.data.error || data.data.data.apiIsDown) {
|
||||
this.$scope.errors.push('Error connecting to the API.');
|
||||
this.$scope.results[i].status = 'Error';
|
||||
this.errors.push('Error connecting to the API.');
|
||||
this.results[i].status = 'Error';
|
||||
} else {
|
||||
this.$scope.processedChecks++;
|
||||
this.$scope.results[i].status = 'Ready';
|
||||
this.processedChecks++;
|
||||
this.results[i].status = 'Ready';
|
||||
if (this.checks.setup) {
|
||||
const versionData = await this.apiReq.request(
|
||||
'GET',
|
||||
@ -142,26 +146,26 @@ class HealthCheck {
|
||||
'Error fetching app version or API version',
|
||||
'Health Check'
|
||||
);
|
||||
this.$scope.errors.push('Error fetching version');
|
||||
this.errors.push('Error fetching version');
|
||||
}
|
||||
const apiSplit = apiVersion.split('v')[1].split('.');
|
||||
const appSplit = setupData.data.data['app-version'].split('.');
|
||||
|
||||
const i = this.$scope.results.map(item => item.id).indexOf(1);
|
||||
const i = this.results.map(item => item.id).indexOf(1);
|
||||
if (apiSplit[0] !== appSplit[0] || apiSplit[1] !== appSplit[1]) {
|
||||
this.$scope.errors.push(
|
||||
this.errors.push(
|
||||
'API version mismatch. Expected v' +
|
||||
setupData.data.data['app-version']
|
||||
);
|
||||
this.$scope.results[i].status = 'Error';
|
||||
this.results[i].status = 'Error';
|
||||
} else {
|
||||
this.$scope.processedChecks++;
|
||||
this.$scope.results[i].status = 'Ready';
|
||||
this.processedChecks++;
|
||||
this.results[i].status = 'Ready';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.checks.setup) this.$scope.processedChecks++;
|
||||
if (this.checks.setup) this.processedChecks++;
|
||||
}
|
||||
if (!this.$scope.$$phase) this.$scope.$digest();
|
||||
return;
|
||||
@ -181,36 +185,33 @@ class HealthCheck {
|
||||
this.checks.api = configuration['checks.api'];
|
||||
this.checks.setup = configuration['checks.setup'];
|
||||
|
||||
this.$scope.results.push({
|
||||
this.results.push({
|
||||
id: 0,
|
||||
description: 'Check Wazuh API connection',
|
||||
status: this.checks.api ? 'Checking...' : 'disabled'
|
||||
});
|
||||
this.$scope.results.push({
|
||||
},{
|
||||
id: 1,
|
||||
description: 'Check for Wazuh API version',
|
||||
status: this.checks.setup ? 'Checking...' : 'disabled'
|
||||
});
|
||||
this.$scope.results.push({
|
||||
},{
|
||||
id: 2,
|
||||
description: 'Check Elasticsearch index pattern',
|
||||
status: this.checks.pattern ? 'Checking...' : 'disabled'
|
||||
});
|
||||
this.$scope.results.push({
|
||||
},{
|
||||
id: 3,
|
||||
description: 'Check Elasticsearch template',
|
||||
status: this.checks.template ? 'Checking...' : 'disabled'
|
||||
});
|
||||
|
||||
for (let key in this.checks)
|
||||
this.$scope.totalChecks += this.checks[key] ? 1 : 0;
|
||||
this.totalChecks += this.checks[key] ? 1 : 0;
|
||||
|
||||
if (this.$scope.totalChecks == 0) this.$scope.zeroChecks = true;
|
||||
if (this.totalChecks == 0) this.zeroChecks = true;
|
||||
|
||||
await Promise.all([this.checkPatterns(), this.checkApiConnection()]);
|
||||
|
||||
this.$scope.checksDone = true;
|
||||
if (!this.$scope.errors || !this.$scope.errors.length) {
|
||||
this.checksDone = true;
|
||||
if (!this.errors || !this.errors.length) {
|
||||
await this.$timeout(800);
|
||||
this.$window.location.assign(
|
||||
'/app/wazuh#' + this.$rootScope.previousLocation || ''
|
||||
@ -225,12 +226,10 @@ class HealthCheck {
|
||||
}
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.$scope.goApp = () =>
|
||||
this.$window.location.assign(
|
||||
'/app/wazuh#' + this.$rootScope.previousLocation || ''
|
||||
);
|
||||
this.load();
|
||||
goApp () {
|
||||
this.$window.location.assign(
|
||||
'/app/wazuh#' + this.$rootScope.previousLocation || ''
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<md-content flex="auto" layout="column" layout-align="center" ng-controller="healthCheck">
|
||||
<md-content flex="auto" layout="column" layout-align="center" ng-controller="healthCheck as ctrl">
|
||||
<div class="height-150" layout="row" layout-align="center">
|
||||
<img aria-hidden="true" kbn-src="/plugins/wazuh/img/icon_blue.svg"></img>
|
||||
<img aria-hidden="true" kbn-src="/plugins/wazuh/img/icon_blue.svg"/>
|
||||
</div>
|
||||
<div layout="row" class="layout-align-center margin-top-30">
|
||||
<table flex="50" class="table">
|
||||
@ -9,7 +9,7 @@
|
||||
<th>Status</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="result in results">
|
||||
<tr ng-repeat="result in ctrl.results">
|
||||
<td>{{result.description}}</td>
|
||||
<td ng-if="result.status === 'disabled'" class="discover-field-details">
|
||||
Disabled
|
||||
@ -25,13 +25,13 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div layout="row" ng-if="errors.length" class="layout-align-center margin-top-30">
|
||||
<div layout="row" ng-if="ctrl.errors.length" class="layout-align-center margin-top-30">
|
||||
<ul>
|
||||
<li class="wz-text-red" ng-repeat='error in errors'>{{error}}</li>
|
||||
<li class="wz-text-red" ng-repeat='error in ctrl.errors'>{{error}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div ng-if="errors.length" layout="row" class="layout-align-center margin-top-30">
|
||||
<md-button class="wz-button md-raised md-primary" ng-click="goApp()" aria-label="Go app">
|
||||
<div ng-if="ctrl.errors.length" layout="row" class="layout-align-center margin-top-30">
|
||||
<md-button class="wz-button md-raised md-primary" ng-click="ctrl.goApp()" aria-label="Go app">
|
||||
<i class="fa fa-fw fa-sign-out"></i> Open the app
|
||||
</md-button>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user