Cleaning agent controllers

This commit is contained in:
Pedro S 2017-01-13 04:24:05 -08:00
parent f012ff377a
commit a0453ce945
7 changed files with 29 additions and 351 deletions

View File

@ -3,12 +3,7 @@ var app = require('ui/modules').get('app/wazuh', []);
app.controller('fimController', function ($scope, $q, DataFactory, $mdToast, errlog) {
//Initialisation
$scope.load = true;
var objectsArray = [];
var loadWatch;
$scope._fimEvent = 'all'
$scope.files = [];
//Print error
var printError = function (error) {
@ -17,152 +12,5 @@ app.controller('fimController', function ($scope, $q, DataFactory, $mdToast, err
position: 'bottom left',
hideDelay: 5000,
});
if ($scope._files_blocked) {
$scope._files_blocked = false;
}
};
//Functions
$scope.setSort = function (field) {
if ($scope._sort === field) {
if ($scope._sortOrder) {
$scope._sortOrder = false;
$scope._sort = '';
DataFactory.filters.unset(objectsArray['/files'], 'filter-sort');
} else {
$scope._sortOrder = true;
DataFactory.filters.set(objectsArray['/files'], 'filter-sort', field);
}
} else {
$scope._sortOrder = false;
$scope._sort = field;
DataFactory.filters.set(objectsArray['/files'], 'filter-sort', '-' + field);
}
}
$scope.fileSearchFilter = function (search) {
if (search) {
DataFactory.filters.set(objectsArray['/files'], 'search', search);
} else {
DataFactory.filters.unset(objectsArray['/files'], 'search');
}
};
$scope.fileEventFilter = function (event) {
if (event == 'all') {
DataFactory.filters.unset(objectsArray['/files'], 'event');
} else {
DataFactory.filters.set(objectsArray['/files'], 'event', event);
}
};
$scope.filesObj = {
//Obj with methods for virtual scrolling
getItemAtIndex: function (index) {
if ($scope._files_blocked) {
return null;
}
var _pos = index - DataFactory.getOffset(objectsArray['/files']);
if (DataFactory.filters.flag(objectsArray['/files'])) {
$scope._files_blocked = true;
DataFactory.scrollTo(objectsArray['/files'], 50)
.then(function (data) {
$scope.files.length = 0;
$scope.files = data.data.items;
DataFactory.filters.unflag(objectsArray['/files']);
$scope._files_blocked = false;
}, printError);
} else if ((_pos > 70) || (_pos < 0)) {
$scope._files_blocked = true;
DataFactory.scrollTo(objectsArray['/files'], index)
.then(function (data) {
$scope.files.length = 0;
$scope.files = data.data.items;
$scope._files_blocked = false;
}, printError);
} else {
return $scope.files[_pos];
}
},
getLength: function () {
return DataFactory.getTotalItems(objectsArray['/files']);
},
};
$scope.changeType = function () {
$scope.showFilesRegistry = !$scope.showFilesRegistry;
fileTypeFilter();
};
var fileTypeFilter = function () {
DataFactory.filters.set(objectsArray['/files'], 'filetype', $scope.showFilesRegistry ? 'registry' : 'file');
};
var createWatch = function () {
loadWatch = $scope.$watch(function () {
return $scope.$parent._agent;
}, function () {
DataFactory.initialize('get', '/syscheck/' + $scope.$parent._agent.id, {}, 100, 0)
.then(function (data) {
DataFactory.clean(objectsArray['/files']);
objectsArray['/files'] = data;
DataFactory.get(objectsArray['/files'])
.then(function (data) {
$scope.files.length = 0;
$scope.files = data.data.items;
DataFactory.filters.register(objectsArray['/files'], 'search', 'string');
DataFactory.filters.register(objectsArray['/files'], 'event', 'string');
DataFactory.filters.register(objectsArray['/files'], 'filter-sort', 'string');
DataFactory.filters.register(objectsArray['/files'], 'filetype', 'string');
$scope._sort = '';
$scope.fileSearchFilter($scope._fileSearch);
$scope.fileEventFilter($scope._fimEvent);
fileTypeFilter();
}, printError);
}, printError);
});
};
var load = function () {
DataFactory.initialize('get', '/syscheck/' + $scope.$parent._agent.id, {}, 100, 0)
.then(function (data) {
objectsArray['/files'] = data;
DataFactory.get(objectsArray['/files'])
.then(function (data) {
$scope.files = data.data.items;
DataFactory.filters.register(objectsArray['/files'], 'search', 'string');
DataFactory.filters.register(objectsArray['/files'], 'event', 'string');
DataFactory.filters.register(objectsArray['/files'], 'filter-sort', 'string');
DataFactory.filters.register(objectsArray['/files'], 'filetype', 'string');
DataFactory.filters.set(objectsArray['/files'], 'filetype', 'file');
createWatch();
$scope.load = false;
}, printError);
}, printError);
};
//Load
try {
load();
} catch (e) {
$mdToast.show({
template: '<md-toast> Unexpected exception loading controller </md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
errlog.log('Unexpected exception loading controller', e);
}
//Destroy
$scope.$on("$destroy", function () {
angular.forEach(objectsArray, function (value) {
DataFactory.clean(value)
});
$scope.files.length = 0;
loadWatch();
});
});

View File

@ -5,11 +5,9 @@ app.controller('agentsController', function ($scope, DataFactory, $mdToast) {
//Initialisation
$scope.load = true;
$scope.agentInfo = [];
var objectsArray = [];
var loadWatch;
$scope.agentInfo = $scope.$parent._agent;
var loadWatch;
//Print Error
var printError = function (error) {
$mdToast.show({
@ -17,14 +15,9 @@ app.controller('agentsController', function ($scope, DataFactory, $mdToast) {
position: 'bottom left',
hideDelay: 5000,
});
if ($scope.blocked) {
$scope.blocked = false;
}
};
//Functions
$scope.fetchAgent = function (agent) {
DataFactory.getAndClean('get', '/agents/' + agent.id, {})
.then(function (data) {
@ -39,37 +32,18 @@ app.controller('agentsController', function ($scope, DataFactory, $mdToast) {
}, printError);
}
}, printError);
$scope.fetchFim(agent);
$scope.fetchRootcheck(agent);
};
$scope.fetchFim = function (agent) {
DataFactory.getAndClean('get', '/syscheck/' + agent.id, { 'offset': 0, 'limit': 5 })
.then(function (data) {
$scope.agentInfo.syscheckEvents = data.data.items;
}, printError);
};
$scope.fetchRootcheck = function (agent) {
DataFactory.getAndClean('get', '/rootcheck/' + agent.id, { 'offset': 0, 'limit': 5 })
.then(function (data) {
$scope.agentInfo.rootcheckEvents = data.data.items;
}, printError);
};
//Load
loadWatch = $scope.$watch(function () {
loadWatch = $scope.$watch(function () {
return $scope.$parent._agent;
}, function () {
console.log($scope.$parent._agent);
$scope.fetchAgent($scope.$parent._agent);
});
//Destroy
//Destroy
$scope.$on("$destroy", function () {
angular.forEach(objectsArray, function (value) {
DataFactory.clean(value)
});
//loadWatch();
loadWatch();
});
});

View File

@ -3,11 +3,7 @@ var app = require('ui/modules').get('app/wazuh', []);
app.controller('pmController', function ($scope, DataFactory, $mdToast, errlog, appState) {
//Initialisation
$scope.load = true;
var objectsArray = [];
var loadWatch;
$scope.defaultManagerName = appState.getDefaultManager().name;
$scope.events = [];
//Print Error
var printError = function (error) {
@ -16,141 +12,6 @@ app.controller('pmController', function ($scope, DataFactory, $mdToast, errlog,
position: 'bottom left',
hideDelay: 5000,
});
if ($scope._eblocked) {
$scope._eblocked = false;
}
}
//Functions
$scope.setTimer = function (time) {
$scope.timerFilterValue = time;
};
$scope.setSort = function (field) {
if ($scope._sort === field) {
if ($scope._sortOrder) {
$scope._sortOrder = false;
$scope._sort = '';
DataFactory.filters.unset(objectsArray['/rootcheck'], 'filter-sort');
} else {
$scope._sortOrder = true;
DataFactory.filters.set(objectsArray['/rootcheck'], 'filter-sort', field);
}
} else {
$scope._sortOrder = false;
$scope._sort = field;
DataFactory.filters.set(objectsArray['/rootcheck'], 'filter-sort', '-' + field);
}
}
$scope.eventSearchFilter = function (search) {
if (search) {
DataFactory.filters.set(objectsArray['/rootcheck'], 'search', search);
} else {
DataFactory.filters.unset(objectsArray['/rootcheck'], 'search');
}
};
$scope.eventsObj = {
//Obj with methods for virtual scrolling
getItemAtIndex: function (index) {
if ($scope._eblocked) {
return null;
}
var _pos = index - DataFactory.getOffset(objectsArray['/rootcheck']);
if (DataFactory.filters.flag(objectsArray['/rootcheck'])) {
$scope._eblocked = true;
DataFactory.scrollTo(objectsArray['/rootcheck'], 200)
.then(function (data) {
$scope.events.length = 0;
$scope.events = data.data.items;
DataFactory.filters.unflag(objectsArray['/rootcheck']);
$scope._eblocked = false;
}, printError);
} else if ((_pos > 150) || (_pos < 0)) {
$scope._eblocked = true;
DataFactory.scrollTo(objectsArray['/rootcheck'], index)
.then(function (data) {
$scope.events.length = 0;
$scope.events = data.data.items;
$scope._eblocked = false;
}, printError);
} else {
return $scope.events[_pos];
}
},
getLength: function () {
return DataFactory.getTotalItems(objectsArray['/rootcheck']);
},
};
var createWatch = function () {
loadWatch = $scope.$watch(function () {
return $scope.$parent._agent;
}, function () {
DataFactory.initialize('get', '/rootcheck/' + $scope.$parent._agent.id, {}, 200, 0)
.then(function (data) {
DataFactory.clean(objectsArray['/rootcheck']);
objectsArray['/rootcheck'] = data;
DataFactory.get(objectsArray['/rootcheck'])
.then(function (data) {
$scope.events.length = 0;
$scope.events = data.data.items;
DataFactory.filters.register(objectsArray['/rootcheck'], 'search', 'string');
DataFactory.filters.register(objectsArray['/rootcheck'], 'filter-sort', 'string');
$scope._sort = '';
$scope.eventSearchFilter($scope._eventSearch);
}, printError);
}, printError);
});
};
var load = function () {
DataFactory.initialize('get', '/rootcheck/' + $scope.$parent._agent.id, {}, 200, 0)
.then(function (data) {
objectsArray['/rootcheck'] = data;
DataFactory.get(objectsArray['/rootcheck'])
.then(function (data) {
$scope.events = data.data.items;
$scope.totalEvents = data.data.totalItems;
DataFactory.filters.register(objectsArray['/rootcheck'], 'search', 'string');
DataFactory.filters.register(objectsArray['/rootcheck'], 'filter-sort', 'string');
createWatch();
$scope.load = false;
}, printError);
}, printError);
};
//Load
try {
load();
$scope.setTimer($scope.$parent.timeFilter);
} catch (e) {
$mdToast.show({
template: '<md-toast> Unexpected exception loading controller </md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
errlog.log('Unexpected exception loading controller', e);
}
// Timer filter watch
var timerWatch = $scope.$watch(function () {
return $scope.$parent.timeFilter;
}, function () {
$scope.setTimer($scope.$parent.timeFilter);
});
//Destroy
$scope.$on("$destroy", function () {
angular.forEach(objectsArray, function (value) {
DataFactory.clean(value)
});
$scope.events.length = 0;
loadWatch();
timerWatch();
});
})
});

View File

@ -108,9 +108,6 @@ app.controller('agentsPreviewController', function ($scope, DataFactory, $mdToas
}, printError);
// Tops
var date = new Date();
date.setDate(date.getDate() - 1);
var timeAgo = date.getTime();
genericReq.request('GET', '/api/wazuh-elastic/top/'+$scope.defaultManager+'/AgentName')
.then(function (data) {
if(data.data == ""){

View File

@ -62,10 +62,7 @@ require('ui/modules').get('app/wazuh', []).controller('VisController', function
var visState = {};
$scope.newVis.init().then(function () {
// For the first vis, we reload index pattern
//if($rootScope.visCounter == 0)
//$scope.newVis.vis.indexPattern.refreshFields();
// Render visualization
$rootScope.visCounter++;
renderVisualization();
@ -74,10 +71,6 @@ require('ui/modules').get('app/wazuh', []).controller('VisController', function
}
);
function renderVisualization() {
$scope.loadBeforeShow = false;
@ -198,10 +191,15 @@ require('ui/modules').get('app/wazuh', []).controller('VisController', function
$scope.fetch();
});
// Listen for destroy
// Watcher
// Destroy
$scope.$on('$destroy', function () {
$scope.newVis.destroy();
});
$scope.$on('$destroy', updateQueryWatch);
$scope.$on('$destroy', fetchVisualizationWatch);

View File

@ -1,4 +1,4 @@
<md-content ng-if="submenuNavItem == 'overview' && tabView == 'panels'" ng-if="_agent">
<md-content ng-if="submenuNavItem == 'overview' && tabView == 'panels'" ng-if="agentInfo">
<kbn-searchbar></kbn-searchbar>
<div ng-controller="agentsController">
@ -11,7 +11,7 @@
</md-card-title>
<md-card-content>
<kbn-vis vis-height="154px" vis-type="pie" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(field:rule.description,order:desc,orderBy:'1',size:5),schema:segment,type:terms)),listeners:(),params:(addLegend:!t,addTooltip:!t,isDonut:!t,shareYAxis:!t),title:'Top 5',type:pie))"
vis-filter="{{_agent.name ? 'agent.name:'+_agent.name : '*'}}">
vis-filter="{{agentInfo.name ? 'agent.name:'+agentInfo.name : '*'}}">
</kbn-vis>
</md-card-content>
</md-card>
@ -23,7 +23,7 @@
</md-card-title>
<md-card-content>
<kbn-vis vis-height="154px" vis-type="pie" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(field:rule.groups,order:desc,orderBy:'1',size:5),schema:segment,type:terms)),listeners:(),params:(addLegend:!t,addTooltip:!t,isDonut:!t,shareYAxis:!t),title:'Top',type:pie))"
vis-filter="{{_agent.name ? 'agent.name:'+_agent.name : '*'}}">
vis-filter="{{agentInfo.name ? 'agent.name:'+agentInfo.name : '*'}}">
</kbn-vis>
</md-card-content>
</md-card>
@ -35,7 +35,7 @@
</md-card-title>
<md-card-content>
<kbn-vis vis-height="154px" vis-type="histogram" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(vis:(legendOpen:!f)),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(field:rule.pci_dss,order:desc,orderBy:'1',size:5),schema:segment,type:terms)),listeners:(),params:(addLegend:!t,addTooltip:!t,isDonut:!t,shareYAxis:!t),title:'Top',type:pie))"
vis-filter="{{_agent.name ? 'agent.name:'+_agent.name : '*'}}">
vis-filter="{{agentInfo.name ? 'agent.name:'+agentInfo.name : '*'}}">
</kbn-vis>
</md-card-content>
</md-card>
@ -50,7 +50,7 @@
</md-card-title>
<md-card-content>
<kbn-vis vis-height="200px" vis-type="histogram" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(vis:(legendOpen:!f)),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(customInterval:'1h',customLabel:'Agent alerts',extended_bounds:(),field:'@timestamp',interval:h,min_doc_count:1),schema:segment,type:date_histogram)),listeners:(),params:(addLegend:!t,addTimeMarker:!f,addTooltip:!t,defaultYExtents:!f,mode:stacked,scale:linear,setYExtents:!f,shareYAxis:!t,times:!(),yAxis:()),title:'Agentbalerts last 24 days',type:histogram))"
vis-filter="{{_agent.name ? 'agent.name:'+_agent.name : '*'}}">
vis-filter="{{agentInfo.name ? 'agent.name:'+agentInfo.name : '*'}}">
</kbn-vis>
</md-card-content>
</md-card>
@ -59,13 +59,13 @@
<md-card flex="40">
<md-card-content>
<div layout="column" flex>
<p><b style="margin-right: 5px;">Hostname:</b> {{_agent.name ? _agent.name : '-'}}</p>
<p ng-if="_agent.ip"><b style="margin-right: 5px;">IP address:</b> {{_agent.ip ? _agent.ip : '-'}}</p>
<p><b style="margin-right: 5px;">Hostname:</b> {{agentInfo.name ? agentInfo.name : '-'}}</p>
<p ng-if="agentInfo.ip"><b style="margin-right: 5px;">IP address:</b> {{agentInfo.ip ? agentInfo.ip : '-'}}</p>
<p><b style="margin-right: 5px;">Agent version:</b> {{agentInfo.version ? agentInfo.version : '-'}}</p>
<p><b style="margin-right: 5px;">Operating system:</b> {{agentInfo.os ? agentInfo.os : '-'}}</p>
<p ng-show="_agent.id != '000'"><b style="margin-right: 5px;">Last keep alive:</b> {{agentInfo.lastKeepAlive ? agentInfo.lastKeepAlive : '-'}}</p>
<p ng-show="_agent.id != '000'" ng-click="showKey = !showKey"><b style="margin-right: 5px;">Agent key <i ng-show="!showKey" class="fa fa-caret-down" aria-hidden="true"></i><i ng-show="showKey" class="fa fa-caret-up" aria-hidden="true"></i></b></p>
<pre ng-if="showKey && _agent.id != '000'" flex="80">{{agentInfo.key}}</pre>
<p ng-show="agentInfo.id != '000'"><b style="margin-right: 5px;">Last keep alive:</b> {{agentInfo.lastKeepAlive ? agentInfo.lastKeepAlive : '-'}}</p>
<p ng-show="agentInfo.id != '000'" ng-click="showKey = !showKey"><b style="margin-right: 5px;">Agent key <i ng-show="!showKey" class="fa fa-caret-down" aria-hidden="true"></i><i ng-show="showKey" class="fa fa-caret-up" aria-hidden="true"></i></b></p>
<pre ng-if="showKey && agentInfo.id != '000'" flex="80">{{agentInfo.key}}</pre>
</div>
</md-card-content>
</md-card>
@ -77,7 +77,7 @@
</md-card-title>
<md-card-content>
<kbn-vis vis-height="200px" vis-type="line" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(customInterval:'1h',extended_bounds:(),field:'@timestamp',interval:h,min_doc_count:1),schema:segment,type:date_histogram),(enabled:!t,id:'3',params:(field:rule.level,order:desc,orderBy:'1',size:10),schema:group,type:terms)),listeners:(),params:(addLegend:!t,addTimeMarker:!f,addTooltip:!t,defaultYExtents:!f,drawLinesBetweenPoints:!t,interpolate:linear,radiusRatio:9,scale:linear,setYExtents:!f,shareYAxis:!t,showCircles:!t,smoothLines:!f,times:!(),yAxis:()),title:'Alert level evolution',type:line))"
vis-filter="{{_agent.name ? 'agent.name:'+_agent.name : '*'}}">
vis-filter="{{agentInfo.name ? 'agent.name:'+agentInfo.name : '*'}}">
</kbn-vis>
</md-card-content>
</md-card>
@ -93,7 +93,7 @@
</md-card-title>
<md-card-content>
<kbn-vis vis-height="460px" vis-type="table" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(vis:(params:(sort:(columnIndex:!n,direction:!n)))),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(customLabel:'Rule ID',field:rule.id,order:desc,orderBy:'1',size:20),schema:bucket,type:terms),(enabled:!t,id:'3',params:(customLabel:Description,field:rule.description,order:desc,orderBy:'1',size:1),schema:bucket,type:terms),(enabled:!t,id:'4',params:(customLabel:Level,field:rule.level,order:desc,orderBy:'1',size:1),schema:bucket,type:terms),(enabled:!t,id:'5',params:(customLabel:Groups,field:rule.groups,order:desc,orderBy:'1',size:1),schema:bucket,type:terms),(enabled:!t,id:'6',params:(customLabel:'PCI DSS',field:rule.pci_dss,order:desc,orderBy:'1',size:1),schema:bucket,type:terms)),listeners:(),params:(perPage:10,showMeticsAtAllLevels:!f,showPartialRows:!f,showTotal:!f,sort:(columnIndex:!n,direction:!n),totalFunc:sum),title:'New%20Visualization',type:table))"
vis-filter="{{_agent.name ? 'agent.name:'+_agent.name : '*'}}">
vis-filter="{{agentInfo.name ? 'agent.name:'+agentInfo.name : '*'}}">
</kbn-vis>
</md-card-content>
</md-card>

View File

@ -48,7 +48,7 @@
</md-card-title-text>
</md-card-title>
<kbn-vis vis-height="600px" vis-type="table" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(vis:(params:(sort:(columnIndex:3,direction:desc)))),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(customLabel:'Agent%20name',field:agent.name,order:desc,orderBy:'1',size:999999999),schema:bucket,type:terms),(enabled:!t,id:'3',params:(customLabel:'Rule%20description',field:rule.description,order:desc,orderBy:'1',size:999999999),schema:bucket,type:terms),(enabled:!t,id:'4',params:(customLabel:Control,field:title,order:desc,orderBy:'1',size:999999999),schema:bucket,type:terms)),listeners:(),params:(perPage:10,showMeticsAtAllLevels:!f,showPartialRows:!f,showTotal:!f,sort:(columnIndex:!n,direction:!n),totalFunc:sum),title:'New%20Visualization',type:table))"
<kbn-vis vis-height="600px" vis-type="table" vis-index-pattern="wazuh-alerts-*" vis-a="(filters:!(),linked:!f,query:(query_string:(analyze_wildcard:!t,query:'*')),uiState:(vis:(params:(sort:(columnIndex:3,direction:desc)))),vis:(aggs:!((enabled:!t,id:'1',params:(),schema:metric,type:count),(enabled:!t,id:'2',params:(customLabel:'Agent name',field:agent.name,order:desc,orderBy:'1',size:999999999),schema:bucket,type:terms),(enabled:!t,id:'3',params:(customLabel:'Rule description',field:rule.description,order:desc,orderBy:'1',size:999999999),schema:bucket,type:terms),(enabled:!t,id:'4',params:(customLabel:Control,field:title,order:desc,orderBy:'1',size:999999999),schema:bucket,type:terms)),listeners:(),params:(perPage:10,showMeticsAtAllLevels:!f,showPartialRows:!f,showTotal:!f,sort:(columnIndex:!n,direction:!n),totalFunc:sum),title:'New%20Visualization',type:table))"
vis-filter="rule.groups: rootcheck AND {{'agent.name:'+_agent.name}}">
</kbn-vis>