Skip to content

Commit

Permalink
Merge pull request #535 from wazuh/3.9-restart-nodes
Browse files Browse the repository at this point in the history
3.9 restart nodes
  • Loading branch information
Jesús Ángel authored Feb 8, 2019
2 parents 1c16db7 + 265f156 commit 6c12863
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 78 deletions.
34 changes: 34 additions & 0 deletions SplunkAppForWazuh/appserver/static/css/styles/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,38 @@
display: flex;
flex-direction: column;
flex: 1 1 100%;
}


/* -------------------------------------------------------------------------- */
/* ------------------------ md-dialog stylesheet ------------------------ */
/* -------------------------------------------------------------------------- */

md-dialog.modalTheme {
animation: none!important;
transition: none!important;
transform: none!important;
bottom: 0;
right: 0;
position: fixed;
width: 350px;
margin-bottom: 10px;
margin-right: 10px;
}

.md-dialog-body{
top: 0!important;
width: 100vw!important;
}
.md-dialog-body{
top: 0!important;
width: 100vw!important;
}
.md-dialog-body .md-scroll-mask{
display: none!important;
}
.md-dialog-body .md-dialog-container{
height: 0!important;
width: 0!important;

}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,36 @@ define(['../module'], function (module) {
onEnter: $navigationService => {
$navigationService.storeRoute('mg-conf')
},
controller: 'navTabCtrl'
controller: 'navTabCtrl',
resolve: {
isAdmin: [
'$currentDataService',
async $currentDataService => {
try {
const id = $currentDataService.getApi().id
const extensions = await $currentDataService.getExtensionsById(
id
)
return extensions['admin'] === 'true'
} catch (error) {
console.error('err : ', error)
return false
}
}
],
clusterEnabled: [
'$requestService',
async $requestService => {
try {
const result = await $requestService.apiReq('/cluster/status')
const clusterStatus = result.data.data.enabled === 'yes' ? true : false
return clusterStatus
} catch (error) {
return false
}
}
]
}
})

// Manager - Configuration - Overview
Expand Down Expand Up @@ -309,7 +338,7 @@ define(['../module'], function (module) {
try {
const info = {}
const clusterStatus = await $requestService.apiReq('/cluster/status')
if (clusterStatus.data.data.running === 'yes') {
if (clusterStatus.data.data.enabled === 'yes' && clusterStatus.data.data.running === 'yes') {
const nodesList = await $requestService.apiReq('/cluster/nodes')
Object.assign(info, { clusterEnabled: true, nodes: nodesList })
} else {
Expand Down Expand Up @@ -548,52 +577,6 @@ define(['../module'], function (module) {
]
}
})
// ossec.conf edition
/*.state('mg-edition', {
templateUrl:
BASE_URL +
'static/app/SplunkAppForWazuh/js/controllers/management/edition/edition.html',
onEnter: $navigationService => {
$navigationService.storeRoute('mg-edition')
},
controller: 'editionCtrl',
resolve: {
isAdmin: [
'$currentDataService',
async $currentDataService => {
try {
const id = $currentDataService.getApi().id
const extensions = await $currentDataService.getExtensionsById(
id
)
return extensions['admin'] === 'true'
} catch (error) {
console.error('err : ', error)
return false
}
}
],
clusterInfo: [
'$requestService',
'$state',
async ($requestService, $state) => {
try {
const info = {}
const clusterStatus = await $requestService.apiReq('/cluster/status')
if (clusterStatus.data.data.running === 'yes') {
const nodesList = await $requestService.apiReq('/cluster/nodes')
Object.assign(info, { clusterEnabled: true, nodes: nodesList })
} else {
Object.assign(info, { clusterEnabled: false })
}
return info
} catch (error) {
$state.go('manager')
}
}
]
}
})*/
}
])
})
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ define([
extensions,
$cdbEditor,
cdbInfo,
$filter
$filter,
$mdDialog
) {
super(
$scope,
Expand All @@ -49,6 +50,7 @@ define([
this.pagination = pagination
this.checkGap = checkGap
this.filter = $filter
this.mdDialog = $mdDialog
try {
this.filters = JSON.parse(window.localStorage.cdb) || []
} catch (err) {
Expand Down Expand Up @@ -215,7 +217,7 @@ define([
this.scope.items = this.cdbToArr()
this.contentToFilter = this.scope.items
this.initPagination()
this.toast("CDB list updated.")
await this.showRestartDialog('CDB list updated')
if (!this.scope.$$phase) this.scope.$digest()
} catch (error) {
this.toast(error)
Expand Down Expand Up @@ -257,6 +259,53 @@ define([
this.scope.searchTable()
}

async showRestartDialog(msg) {
const confirm = this.mdDialog.confirm({
controller: function ($scope, myScope, $notificationService, $mdDialog, $restartService) {
$scope.myScope = myScope;
$scope.closeDialog = () => {
$mdDialog.hide();
$('body').removeClass('md-dialog-body');
};
$scope.confirmDialog = () => {
$mdDialog.hide();
$restartService.restart()
.then(data => {
$('body').removeClass('md-dialog-body');
$notificationService.showSimpleToast(data);
$scope.myScope.$applyAsync();
})
.catch(error =>
$notificationService.showSimpleToast(error.message || error, 'Error restarting manager'));
}
},
template:
'<md-dialog class="modalTheme euiToast euiToast--success euiGlobalToastListItem">' +
'<md-dialog-content>' +
'<div class="euiToastHeader">' +
'<i class="fa fa-check"></i>' +
'<span class="euiToastHeader__title">' +
`${msg}` +
`. Do you want to restart now?` +
'</span>' +
'</div>' +
'</md-dialog-content>' +
'<md-dialog-actions>' +
'<button class="md-primary md-cancel-button md-button ng-scope md-default-theme md-ink-ripple" type="button" ng-click="closeDialog()">I will do it later</button>' +
'<button class="md-primary md-confirm-button md-button md-ink-ripple md-default-theme" type="button" ng-click="confirmDialog()">Restart</button>' +
'</md-dialog-actions>' +
'</md-dialog>',
hasBackdrop: false,
clickOutsideToClose: true,
disableParentScroll: true,
locals: {
myScope: this.scope,
}
});
$('body').addClass('md-dialog-body');
this.mdDialog.show(confirm);
}

}
controllers.controller('managerCdbIdCtrl', CdbListId)
})
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
<span flex></span>
<!-- End separator -->

<!-- Restart button -->
<button ng-if="isAdmin" ng-click="restart()" class="btn btn-primary pull-right ng-scope">
<span aria-hidden="false"><i aria-hidden="true" class="fa fa-fw fa-refresh"></i>
Restart {{node}}
</span>
</button>

<!-- Help button -->
<md-button md-no-ink class="md-icon-button small" tooltip="About and help" tooltip-placement="left" ui-sref="settings.about"
aria-label="Link to open app about section">
Expand All @@ -67,9 +74,12 @@
<div layout="row" layout-padding>
<md-nav-bar style="width:100%" class="wz-nav-bar" md-selected-nav-item="tabName" nav-bar-aria-label="Ruleset navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('overview')" ui-sref="mg-conf.overview" name="overview">Overview</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('editConfig')" ui-sref="mg-conf.editConfig" name="editConfig">Edit configuration</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('editRuleset')" ui-sref="mg-conf.editRuleset" name="editRuleset">Edit ruleset</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('editGroups')" ui-sref="mg-conf.editGroups" name="editGroups">Edit groups</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('editConfig')" ui-sref="mg-conf.editConfig" name="editConfig">Edit
configuration</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('editRuleset')" ui-sref="mg-conf.editRuleset" name="editRuleset">Edit
ruleset</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('editGroups')" ui-sref="mg-conf.editGroups" name="editGroups">Edit
groups</md-nav-item>
</md-nav-bar>
</div>
<!-- End nav bar tabs -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ define(['../../../module'], function (controllers) {
'use strict'

class NavTabCtrl {
constructor($scope, $navigationService) {
constructor($scope, $navigationService, $restartService, $notificationService, $requestService, isAdmin, clusterEnabled) {
this.navigationService = $navigationService
this.scope = $scope
this.scope.tabName = ''
this.isAdmin = isAdmin
this.clusterEnabled = clusterEnabled
this.restartService = $restartService
this.toast = $notificationService.showSimpleToast
this.apiReq = $requestService.apiReq
}

$onInit() {
this.scope.isAdmin = this.isAdmin
this.scope.node = this.clusterEnabled ? 'cluster' : 'manager'

const lastState = this.navigationService.getLastState()
switch (lastState) {
case 'mg-conf.overview':
Expand All @@ -35,8 +43,11 @@ define(['../../../module'], function (controllers) {
this.scope.switchTab = name => {
this.scope.sectionName = this.getSectionName(name)
this.scope.tabName = name
this.refreshClusterStatus()
if (!this.scope.$$phase) this.scope.$digest()
}

this.scope.restart = (node) => this.restart(node)
}

getSectionName(name) {
Expand All @@ -57,6 +68,33 @@ define(['../../../module'], function (controllers) {
}
return sectionName
}

async restart(node = false) {
try {
let result = ''
if (this.clusterEnabled && node) {
result = await this.restartService.restartNode(node)
} else {
result = await this.restartService.restart()
}
this.toast(result)
this.refreshClusterStatus()
} catch (error) {
this.toast(error)
}
}

async refreshClusterStatus(){
try {
const clusterStatus = await this.apiReq('/cluster/status')
this.clusterEnabled = clusterStatus.data.data.enabled === 'yes' && clusterStatus.data.data.running === 'yes' ? true : false
this.scope.node = this.clusterEnabled ? 'cluster' : 'manager'
} catch (error) {
return Promise.reject(error)
}

}

}
controllers.controller('navTabCtrl', NavTabCtrl)
})
Loading

0 comments on commit 6c12863

Please sign in to comment.