2016-09-02 10:10:10 +00:00
|
|
|
// Require config
|
|
|
|
var app = require('ui/modules').get('app/wazuh', []);
|
|
|
|
|
2016-09-20 13:17:57 +00:00
|
|
|
app.controller('generalController', function ($scope, $q, DataFactory, $mdToast, appState, errlog, $window) {
|
2016-09-02 10:10:10 +00:00
|
|
|
//Initialisation
|
|
|
|
$scope.load = true;
|
|
|
|
$scope.search = '';
|
|
|
|
$scope.menuNavItem = 'agents';
|
|
|
|
$scope.submenuNavItem = '';
|
2016-09-15 09:03:03 +00:00
|
|
|
$scope.state = appState;
|
2016-09-02 10:10:10 +00:00
|
|
|
|
2016-09-20 08:55:43 +00:00
|
|
|
var objectsArray = [];
|
2016-09-02 10:10:10 +00:00
|
|
|
|
|
|
|
//Print Error
|
|
|
|
var printError = function (error) {
|
|
|
|
$mdToast.show({
|
|
|
|
template: '<md-toast>' + error.html + '</md-toast>',
|
|
|
|
position: 'bottom left',
|
|
|
|
hideDelay: 5000,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
//Functions
|
|
|
|
|
|
|
|
$scope.getAgentStatusClass = function (agentStatus) {
|
2016-09-12 10:20:39 +00:00
|
|
|
if (agentStatus == "active")
|
2016-09-02 10:10:10 +00:00
|
|
|
return "green"
|
2016-09-12 10:20:39 +00:00
|
|
|
else if (agentStatus == "disconnected")
|
2016-09-02 10:10:10 +00:00
|
|
|
return "red";
|
|
|
|
else
|
|
|
|
return "red";
|
|
|
|
};
|
2016-09-20 08:55:43 +00:00
|
|
|
|
|
|
|
$scope.formatAgentStatus = function (agentStatus) {
|
2016-09-12 10:20:39 +00:00
|
|
|
if (agentStatus == "active")
|
|
|
|
return "Active"
|
|
|
|
else if (agentStatus == "disconnected")
|
|
|
|
return "Disconnected";
|
|
|
|
else
|
|
|
|
return "Never connected";
|
|
|
|
};
|
2016-09-02 10:10:10 +00:00
|
|
|
|
|
|
|
$scope.agentsSearch = function (search) {
|
|
|
|
var defered = $q.defer();
|
|
|
|
var promise = defered.promise;
|
2016-09-20 08:55:43 +00:00
|
|
|
|
2016-09-02 10:10:10 +00:00
|
|
|
if (search) {
|
|
|
|
DataFactory.filters.set(objectsArray['/agents'], 'search', search);
|
|
|
|
} else {
|
|
|
|
DataFactory.filters.unset(objectsArray['/agents'], 'search');
|
|
|
|
}
|
|
|
|
|
|
|
|
DataFactory.get(objectsArray['/agents'])
|
|
|
|
.then(function (data) {
|
|
|
|
defered.resolve(data.data.items);
|
|
|
|
}, function (data) {
|
|
|
|
printError(data);
|
|
|
|
defered.reject();
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.applyAgent = function (agent) {
|
|
|
|
if (agent) {
|
2016-09-17 19:33:38 +00:00
|
|
|
$scope.submenuNavItem = 'overview';
|
2016-09-02 10:10:10 +00:00
|
|
|
$scope._agent = agent;
|
2016-09-14 13:58:41 +00:00
|
|
|
$scope.search = agent.name;
|
|
|
|
}
|
2016-09-02 10:10:10 +00:00
|
|
|
};
|
|
|
|
|
2016-09-20 08:55:43 +00:00
|
|
|
$scope.getDiscoverByAgent = function (agent) {
|
|
|
|
var _urlStr = '/app/kibana#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-7d,mode:quick,to:now))&_a=(columns:!(_source),filters:!((\'$state\':(store:appState),meta:(alias:!n,disabled:!f,index:\'ossec-*\',key:AgentName,negate:!f,value:\'';
|
|
|
|
var _urlStrSf = '\'),query:(match:(AgentName:(query:\'';
|
|
|
|
var _urlStrSSf = '\',type:phrase))))),index:\'ossec-*\',interval:auto,query:(query_string:(analyze_wildcard:!t,query:\'*\')),sort:!(\'@timestamp\',desc),vis:(aggs:!((params:(field:AgentName,orderBy:\'2\',size:20),schema:segment,type:terms),(id:\'2\',schema:metric,type:count)),type:histogram))&indexPattern=ossec-*&type=histogram';
|
|
|
|
|
|
|
|
return _urlStr + agent.name + _urlStrSf + agent.name + _urlStrSSf;
|
|
|
|
}
|
|
|
|
|
2016-09-20 13:17:57 +00:00
|
|
|
$scope.openDashboard = function (dashboard, filter) {
|
|
|
|
$scope.state.setDashboardsState(dashboard, filter);
|
|
|
|
$window.open('#/dashboards/', '_blank');
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:10:10 +00:00
|
|
|
|
2016-09-16 12:32:22 +00:00
|
|
|
var load = function () {
|
|
|
|
DataFactory.initialize('get', '/agents', {}, 256, 0)
|
|
|
|
.then(function (data) {
|
|
|
|
objectsArray['/agents'] = data;
|
|
|
|
DataFactory.get(data).then(function (data) {
|
|
|
|
DataFactory.filters.register(objectsArray['/agents'], 'search', 'string');
|
|
|
|
$scope.load = false;
|
|
|
|
}, printError);
|
2016-09-02 10:10:10 +00:00
|
|
|
}, printError);
|
2016-09-16 12:32:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Load
|
|
|
|
try {
|
|
|
|
load();
|
|
|
|
} catch (e) {
|
2016-09-16 12:43:54 +00:00
|
|
|
$mdToast.show({
|
|
|
|
template: '<md-toast> Unexpected exception loading controller </md-toast>',
|
|
|
|
position: 'bottom left',
|
|
|
|
hideDelay: 5000,
|
|
|
|
});
|
2016-09-16 12:32:22 +00:00
|
|
|
errlog.log('Unexpected exception loading controller', e);
|
|
|
|
}
|
2016-09-02 10:10:10 +00:00
|
|
|
|
|
|
|
//Destroy
|
|
|
|
$scope.$on("$destroy", function () {
|
|
|
|
angular.forEach(objectsArray, function (value) {
|
2016-09-20 08:55:43 +00:00
|
|
|
DataFactory.clean(value)
|
|
|
|
});
|
2016-09-02 10:10:10 +00:00
|
|
|
});
|
|
|
|
|
2016-09-14 13:58:41 +00:00
|
|
|
});
|
|
|
|
|
2016-09-15 09:03:03 +00:00
|
|
|
app.controller('stateController', function ($scope, appState) {
|
|
|
|
$scope.state = appState;
|
2016-09-20 13:17:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.controller('stateLocationController', function ($scope, appState, $window) {
|
|
|
|
$scope.state = appState;
|
|
|
|
|
|
|
|
$scope.openDashboard = function (dashboard, filter) {
|
|
|
|
$scope.state.setDashboardsState(dashboard, filter);
|
|
|
|
$window.open('#/dashboards/', '_blank');
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:12:24 +00:00
|
|
|
});
|