2018-04-22 20:16:38 +00:00
|
|
|
/*
|
|
|
|
* Wazuh app - Agents controller
|
|
|
|
* Copyright (C) 2018 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.
|
|
|
|
*/
|
2018-09-03 09:46:55 +00:00
|
|
|
import { FilterHandler } from '../../utils/filter-handler';
|
2018-09-11 09:52:54 +00:00
|
|
|
import { generateMetric } from '../../utils/generate-metric';
|
|
|
|
import { TabNames } from '../../utils/tab-names';
|
2018-09-10 08:32:49 +00:00
|
|
|
import * as FileSaver from '../../services/file-saver';
|
2018-09-11 09:52:54 +00:00
|
|
|
import { TabDescription } from '../../../server/reporting/tab-description';
|
2018-09-10 08:32:49 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
metricsAudit,
|
|
|
|
metricsVulnerability,
|
|
|
|
metricsScap,
|
|
|
|
metricsCiscat,
|
|
|
|
metricsVirustotal
|
|
|
|
} from '../../utils/agents-metrics';
|
2018-04-21 11:31:47 +00:00
|
|
|
|
2018-09-26 09:10:43 +00:00
|
|
|
import { ConfigurationHandler } from '../../utils/config-handler';
|
2018-10-31 10:12:12 +00:00
|
|
|
import { timefilter } from 'ui/timefilter';
|
2017-01-16 12:29:48 +00:00
|
|
|
|
2018-11-02 18:59:51 +00:00
|
|
|
export class AgentsController {
|
2018-09-11 09:52:54 +00:00
|
|
|
constructor(
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope,
|
|
|
|
$location,
|
|
|
|
$rootScope,
|
|
|
|
appState,
|
|
|
|
apiReq,
|
|
|
|
errorHandler,
|
|
|
|
tabVisualizations,
|
|
|
|
shareAgent,
|
|
|
|
commonData,
|
|
|
|
reportingService,
|
|
|
|
visFactoryService,
|
|
|
|
csvReq,
|
2018-06-20 14:54:47 +00:00
|
|
|
wzTableFilter
|
2018-09-10 08:32:49 +00:00
|
|
|
) {
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope = $scope;
|
|
|
|
this.$location = $location;
|
|
|
|
this.$rootScope = $rootScope;
|
|
|
|
this.appState = appState;
|
|
|
|
this.apiReq = apiReq;
|
|
|
|
this.errorHandler = errorHandler;
|
|
|
|
this.tabVisualizations = tabVisualizations;
|
|
|
|
this.shareAgent = shareAgent;
|
|
|
|
this.commonData = commonData;
|
|
|
|
this.reportingService = reportingService;
|
|
|
|
this.visFactoryService = visFactoryService;
|
|
|
|
this.csvReq = csvReq;
|
|
|
|
this.wzTableFilter = wzTableFilter;
|
2018-09-24 07:02:42 +00:00
|
|
|
|
2018-09-26 09:10:43 +00:00
|
|
|
// Config on-demand
|
|
|
|
this.$scope.isArray = Array.isArray;
|
|
|
|
this.configurationHandler = new ConfigurationHandler(apiReq, errorHandler);
|
|
|
|
this.$scope.currentConfig = null;
|
|
|
|
this.$scope.configurationTab = '';
|
|
|
|
this.$scope.configurationSubTab = '';
|
|
|
|
this.$scope.integrations = {};
|
|
|
|
this.$scope.selectedItem = 0;
|
2018-10-03 14:14:51 +00:00
|
|
|
this.targetLocation = null;
|
2018-10-31 10:12:12 +00:00
|
|
|
this.ignoredTabs = ['syscollector', 'welcome', 'configuration'];
|
2018-09-11 09:52:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
this.$scope.TabDescription = TabDescription;
|
2018-06-12 13:23:26 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$rootScope.reportStatus = false;
|
2018-06-12 13:23:26 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$location.search('_a', null);
|
|
|
|
this.filterHandler = new FilterHandler(this.appState.getCurrentPattern());
|
|
|
|
this.visFactoryService.clearAll();
|
2018-05-15 14:11:35 +00:00
|
|
|
|
2018-10-01 07:05:15 +00:00
|
|
|
const currentApi = JSON.parse(this.appState.getCurrentAPI()).id;
|
|
|
|
const extensions = this.appState.getExtensions(currentApi);
|
|
|
|
this.$scope.extensions = extensions;
|
|
|
|
|
2018-10-03 14:14:51 +00:00
|
|
|
// Getting possible target location
|
|
|
|
this.targetLocation = this.shareAgent.getTargetLocation();
|
|
|
|
|
|
|
|
if (this.targetLocation && typeof this.targetLocation === 'object') {
|
|
|
|
this.$scope.tabView = this.targetLocation.subTab;
|
|
|
|
this.$scope.tab = this.targetLocation.tab;
|
|
|
|
} else {
|
|
|
|
this.$scope.tabView = this.commonData.checkTabViewLocation();
|
|
|
|
this.$scope.tab = this.commonData.checkTabLocation();
|
|
|
|
}
|
2018-06-07 14:44:36 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.tabHistory = [];
|
2018-10-31 10:12:12 +00:00
|
|
|
if (!this.ignoredTabs.includes(this.$scope.tab))
|
2018-09-11 09:52:54 +00:00
|
|
|
this.tabHistory.push(this.$scope.tab);
|
2018-06-07 08:32:53 +00:00
|
|
|
|
|
|
|
// Tab names
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.tabNames = TabNames;
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.tabVisualizations.assign('agents');
|
2018-01-09 18:53:42 +00:00
|
|
|
|
2018-09-28 13:23:47 +00:00
|
|
|
this.$scope.hostMonitoringTabs = ['general', 'fim', 'syscollector'];
|
2018-10-04 14:29:14 +00:00
|
|
|
this.$scope.systemAuditTabs = ['pm', 'audit', 'oscap', 'ciscat'];
|
|
|
|
this.$scope.securityTabs = ['vuls', 'virustotal', 'osquery'];
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.complianceTabs = ['pci', 'gdpr'];
|
2018-07-02 14:37:09 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.inArray = (item, array) =>
|
2018-09-10 08:32:49 +00:00
|
|
|
item && Array.isArray(array) && array.includes(item);
|
2018-07-02 14:37:09 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.switchSubtab = async (
|
2018-09-10 08:32:49 +00:00
|
|
|
subtab,
|
|
|
|
force = false,
|
|
|
|
onlyAgent = false,
|
|
|
|
sameTab = true,
|
|
|
|
preserveDiscover = false
|
2018-09-11 09:52:54 +00:00
|
|
|
) => this.switchSubtab(subtab, force, onlyAgent, sameTab, preserveDiscover);
|
2018-06-19 14:40:03 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.changeAgent = false;
|
2018-06-12 11:37:37 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.switchTab = (tab, force = false) => this.switchTab(tab, force);
|
2018-03-14 15:43:23 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.getAgentStatusClass = agentStatus =>
|
2018-09-10 08:32:49 +00:00
|
|
|
agentStatus === 'Active' ? 'teal' : 'red';
|
2018-01-09 18:53:42 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.formatAgentStatus = agentStatus => {
|
2018-09-10 08:32:49 +00:00
|
|
|
return ['Active', 'Disconnected'].includes(agentStatus)
|
|
|
|
? agentStatus
|
|
|
|
: 'Never connected';
|
2018-05-14 08:05:25 +00:00
|
|
|
};
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.getAgent = async newAgentId => this.getAgent(newAgentId);
|
2018-09-24 15:47:01 +00:00
|
|
|
this.$scope.goGroups = (agent, group) => this.goGroups(agent, group);
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.analyzeAgents = async searchTerm =>
|
|
|
|
this.analyzeAgents(searchTerm);
|
|
|
|
this.$scope.downloadCsv = async data_path => this.downloadCsv(data_path);
|
2018-01-09 18:53:42 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.search = (term, specificPath) =>
|
|
|
|
this.$scope.$broadcast('wazuhSearch', { term, specificPath });
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.startVis2Png = () => this.startVis2Png();
|
2018-01-09 18:53:42 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.$on('$destroy', () => {
|
|
|
|
this.visFactoryService.clearAll();
|
|
|
|
});
|
2018-06-19 14:40:03 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.isArray = Array.isArray;
|
2018-08-27 11:45:23 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.goGroup = () => {
|
|
|
|
this.shareAgent.setAgent(this.$scope.agent);
|
|
|
|
this.$location.path('/manager/groups');
|
|
|
|
};
|
2018-04-20 07:29:13 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
//Load
|
|
|
|
try {
|
|
|
|
this.$scope.getAgent();
|
|
|
|
} catch (e) {
|
|
|
|
this.errorHandler.handle(
|
|
|
|
'Unexpected exception loading controller',
|
|
|
|
'Agents'
|
|
|
|
);
|
|
|
|
}
|
2018-09-24 07:02:42 +00:00
|
|
|
|
2018-09-26 09:10:43 +00:00
|
|
|
// Config on demand
|
|
|
|
this.$scope.getXML = () => this.configurationHandler.getXML(this.$scope);
|
|
|
|
this.$scope.getJSON = () => this.configurationHandler.getJSON(this.$scope);
|
2018-09-24 07:02:42 +00:00
|
|
|
this.$scope.isString = item => typeof item === 'string';
|
2018-09-28 13:23:47 +00:00
|
|
|
this.$scope.hasSize = obj =>
|
|
|
|
obj && typeof obj === 'object' && Object.keys(obj).length;
|
2018-11-21 11:15:27 +00:00
|
|
|
this.$scope.switchConfigTab = (configurationTab, sections, navigate = true) => {
|
|
|
|
this.$scope.navigate = navigate;
|
|
|
|
this.$scope.configSubTab = JSON.stringify({ 'configurationTab': configurationTab, 'sections': sections });
|
|
|
|
if (!this.$location.search().configSubTab) {
|
2018-11-27 08:21:37 +00:00
|
|
|
sessionStorage.setItem("configSubTab", this.$scope.configSubTab);
|
|
|
|
this.$location.search('configSubTab', true);
|
2018-11-21 11:15:27 +00:00
|
|
|
}
|
2018-09-28 13:23:47 +00:00
|
|
|
this.configurationHandler.switchConfigTab(
|
|
|
|
configurationTab,
|
|
|
|
sections,
|
|
|
|
this.$scope,
|
|
|
|
this.$scope.agent.id
|
|
|
|
);
|
2018-11-21 11:15:27 +00:00
|
|
|
}
|
|
|
|
this.$scope.switchWodle = (wodleName, navigate = true) => {
|
|
|
|
this.$scope.navigate = navigate;
|
|
|
|
this.$scope.configWodle = wodleName;
|
|
|
|
if (!this.$location.search().configWodle) {
|
|
|
|
this.$location.search('configWodle', this.$scope.configWodle);
|
|
|
|
}
|
2018-09-28 13:23:47 +00:00
|
|
|
this.configurationHandler.switchWodle(
|
|
|
|
wodleName,
|
|
|
|
this.$scope,
|
|
|
|
this.$scope.agent.id
|
2018-11-21 11:15:27 +00:00
|
|
|
)
|
|
|
|
};
|
|
|
|
this.$scope.switchConfigurationTab = (configurationTab, navigate) => {
|
|
|
|
this.$scope.navigate = navigate;
|
2018-09-28 13:23:47 +00:00
|
|
|
this.configurationHandler.switchConfigurationTab(
|
|
|
|
configurationTab,
|
|
|
|
this.$scope
|
|
|
|
);
|
2018-11-21 11:15:27 +00:00
|
|
|
if (!this.$scope.navigate) {
|
2018-11-27 08:21:37 +00:00
|
|
|
const configSubTab = this.$location.search().configSubTab;
|
2018-11-21 11:15:27 +00:00
|
|
|
if (configSubTab) {
|
2018-11-27 08:21:37 +00:00
|
|
|
const config = sessionStorage.getItem("configSubTab");
|
|
|
|
const configSubTabObj = JSON.parse(config);
|
2018-11-21 11:15:27 +00:00
|
|
|
this.$scope.switchConfigTab(configSubTabObj.configurationTab, configSubTabObj.sections, false);
|
2018-11-27 08:21:37 +00:00
|
|
|
} else {
|
|
|
|
const configWodle = this.$location.search().configWodle;
|
2018-11-21 11:15:27 +00:00
|
|
|
if (configWodle) {
|
|
|
|
this.$scope.switchWodle(configWodle, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.$location.search('configSubTab', null);
|
2018-11-27 08:21:37 +00:00
|
|
|
sessionStorage.removeItem('configSubTab');
|
2018-11-21 11:15:27 +00:00
|
|
|
this.$location.search('configWodle', null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$scope.switchConfigurationSubTab = configurationSubTab => {
|
2018-09-28 13:23:47 +00:00
|
|
|
this.configurationHandler.switchConfigurationSubTab(
|
|
|
|
configurationSubTab,
|
|
|
|
this.$scope
|
|
|
|
);
|
2018-11-21 11:15:27 +00:00
|
|
|
}
|
2018-09-28 13:23:47 +00:00
|
|
|
this.$scope.updateSelectedItem = i => (this.$scope.selectedItem = i);
|
|
|
|
this.$scope.getIntegration = list =>
|
|
|
|
this.configurationHandler.getIntegration(list, this.$scope);
|
2018-09-11 09:52:54 +00:00
|
|
|
}
|
2018-01-09 18:53:42 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
createMetrics(metricsObject) {
|
|
|
|
for (let key in metricsObject) {
|
|
|
|
this.$scope[key] = () => generateMetric(metricsObject[key]);
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 18:53:42 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
checkMetrics(tab, subtab) {
|
|
|
|
if (subtab === 'panels') {
|
|
|
|
switch (tab) {
|
|
|
|
case 'audit':
|
|
|
|
this.createMetrics(metricsAudit);
|
|
|
|
break;
|
|
|
|
case 'vuls':
|
|
|
|
this.createMetrics(metricsVulnerability);
|
|
|
|
break;
|
|
|
|
case 'oscap':
|
|
|
|
this.createMetrics(metricsScap);
|
|
|
|
break;
|
|
|
|
case 'ciscat':
|
|
|
|
this.createMetrics(metricsCiscat);
|
|
|
|
break;
|
|
|
|
case 'virustotal':
|
|
|
|
this.createMetrics(metricsVirustotal);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-19 14:40:03 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
// Switch subtab
|
|
|
|
async switchSubtab(
|
|
|
|
subtab,
|
|
|
|
force = false,
|
|
|
|
onlyAgent = false,
|
|
|
|
sameTab = true,
|
|
|
|
preserveDiscover = false
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
if (this.$scope.tabView === subtab && !force) return;
|
2018-06-19 14:40:03 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.visFactoryService.clear(onlyAgent);
|
|
|
|
this.$location.search('tabView', subtab);
|
|
|
|
const localChange =
|
|
|
|
subtab === 'panels' && this.$scope.tabView === 'discover' && sameTab;
|
|
|
|
this.$scope.tabView = subtab;
|
2017-12-12 16:27:29 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
if (
|
2018-10-22 14:51:20 +00:00
|
|
|
(subtab === 'panels' ||
|
|
|
|
(this.targetLocation &&
|
|
|
|
typeof this.targetLocation === 'object' &&
|
|
|
|
this.targetLocation.subTab === 'discover' &&
|
|
|
|
subtab === 'discover')) &&
|
2018-10-31 10:12:12 +00:00
|
|
|
!this.ignoredTabs.includes(this.$scope.tab)
|
2018-10-03 14:14:51 +00:00
|
|
|
) {
|
|
|
|
const condition =
|
2018-10-03 14:44:28 +00:00
|
|
|
!this.changeAgent && (localChange || preserveDiscover);
|
|
|
|
|
2018-10-03 14:14:51 +00:00
|
|
|
await this.visFactoryService.buildAgentsVisualizations(
|
|
|
|
this.filterHandler,
|
|
|
|
this.$scope.tab,
|
|
|
|
subtab,
|
|
|
|
condition,
|
|
|
|
this.$scope.agent.id
|
|
|
|
);
|
2018-10-03 14:44:28 +00:00
|
|
|
|
2018-10-03 14:14:51 +00:00
|
|
|
this.changeAgent = false;
|
2018-09-11 09:52:54 +00:00
|
|
|
} else {
|
|
|
|
this.$rootScope.$emit('changeTabView', {
|
|
|
|
tabView: this.$scope.tabView
|
|
|
|
});
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.checkMetrics(this.$scope.tab, subtab);
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
return;
|
2018-09-11 09:52:54 +00:00
|
|
|
} catch (error) {
|
|
|
|
this.errorHandler.handle(error, 'Agents');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 17:07:27 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
// Switch tab
|
2018-10-25 09:52:33 +00:00
|
|
|
async switchTab(tab, force = false) {
|
2018-10-31 10:12:12 +00:00
|
|
|
if (this.ignoredTabs.includes(tab)) {
|
|
|
|
const timeFilterRefreshStatus = timefilter.getRefreshInterval();
|
|
|
|
const toggle =
|
|
|
|
timeFilterRefreshStatus &&
|
|
|
|
timeFilterRefreshStatus.value &&
|
|
|
|
!timeFilterRefreshStatus.pause;
|
|
|
|
if (toggle) timefilter.toggleRefresh();
|
|
|
|
}
|
|
|
|
|
2018-10-25 09:52:33 +00:00
|
|
|
try {
|
2018-10-25 16:12:58 +00:00
|
|
|
if (tab === 'pci') {
|
2018-10-25 13:55:57 +00:00
|
|
|
const pciTabs = await this.commonData.getPCI();
|
|
|
|
this.$scope.pciTabs = pciTabs;
|
|
|
|
this.$scope.selectedPciIndex = 0;
|
|
|
|
}
|
2018-10-25 16:12:58 +00:00
|
|
|
if (tab === 'gdpr') {
|
2018-10-25 13:55:57 +00:00
|
|
|
const gdprTabs = await this.commonData.getPCI();
|
|
|
|
this.$scope.gdprTabs = gdprTabs;
|
|
|
|
this.$scope.selectedGdprIndex = 0;
|
|
|
|
}
|
2018-10-25 16:12:58 +00:00
|
|
|
if (tab === 'syscollector')
|
|
|
|
await this.loadSyscollector(this.$scope.agent.id);
|
2018-10-25 09:52:33 +00:00
|
|
|
if (tab === 'configuration') {
|
2018-10-25 16:12:58 +00:00
|
|
|
const isSync = await this.apiReq.request(
|
|
|
|
'GET',
|
|
|
|
`/agents/${this.$scope.agent.id}/group/is_sync`,
|
|
|
|
{}
|
|
|
|
);
|
2018-10-25 10:01:25 +00:00
|
|
|
// Configuration synced
|
2018-10-25 16:12:58 +00:00
|
|
|
this.$scope.isSynchronized =
|
|
|
|
isSync && isSync.data && isSync.data.data && isSync.data.data.synced;
|
2018-10-25 09:52:33 +00:00
|
|
|
this.$scope.switchConfigurationTab('welcome');
|
|
|
|
} else {
|
|
|
|
this.configurationHandler.reset(this.$scope);
|
|
|
|
}
|
2018-10-31 10:12:12 +00:00
|
|
|
if (!this.ignoredTabs.includes(tab)) this.tabHistory.push(tab);
|
2018-10-25 16:12:58 +00:00
|
|
|
if (this.tabHistory.length > 2)
|
|
|
|
this.tabHistory = this.tabHistory.slice(-2);
|
2018-10-25 09:52:33 +00:00
|
|
|
this.tabVisualizations.setTab(tab);
|
|
|
|
if (this.$scope.tab === tab && !force) return;
|
|
|
|
const onlyAgent = this.$scope.tab === tab && force;
|
|
|
|
const sameTab = this.$scope.tab === tab;
|
|
|
|
this.$location.search('tab', tab);
|
|
|
|
const preserveDiscover =
|
|
|
|
this.tabHistory.length === 2 &&
|
|
|
|
this.tabHistory[0] === this.tabHistory[1] &&
|
|
|
|
!force;
|
|
|
|
this.$scope.tab = tab;
|
|
|
|
|
|
|
|
const targetSubTab =
|
|
|
|
this.targetLocation && typeof this.targetLocation === 'object'
|
|
|
|
? this.targetLocation.subTab
|
|
|
|
: 'panels';
|
|
|
|
|
2018-10-31 10:12:12 +00:00
|
|
|
if (!this.ignoredTabs.includes(this.$scope.tab)) {
|
2018-10-25 09:52:33 +00:00
|
|
|
this.$scope.switchSubtab(
|
|
|
|
targetSubTab,
|
|
|
|
true,
|
|
|
|
onlyAgent,
|
|
|
|
sameTab,
|
|
|
|
preserveDiscover
|
|
|
|
);
|
|
|
|
}
|
2018-10-03 14:14:51 +00:00
|
|
|
|
2018-10-25 09:52:33 +00:00
|
|
|
this.shareAgent.deleteTargetLocation();
|
|
|
|
this.targetLocation = null;
|
2018-10-25 16:12:58 +00:00
|
|
|
} catch (error) {
|
|
|
|
return Promise.reject(error);
|
2018-10-25 09:52:33 +00:00
|
|
|
}
|
2018-10-25 10:01:25 +00:00
|
|
|
if (!this.$scope.$$phase) this.$scope.$digest();
|
2018-09-11 09:52:54 +00:00
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
// Agent data
|
2018-06-19 15:36:37 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
validateRootCheck() {
|
|
|
|
const result = this.commonData.validateRange(this.$scope.agent.rootcheck);
|
|
|
|
this.$scope.agent.rootcheck = result;
|
|
|
|
}
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
validateSysCheck() {
|
|
|
|
const result = this.commonData.validateRange(this.$scope.agent.syscheck);
|
|
|
|
this.$scope.agent.syscheck = result;
|
|
|
|
}
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
async loadSyscollector(id) {
|
|
|
|
try {
|
2018-09-27 15:27:14 +00:00
|
|
|
// Check that Syscollector is enabled before proceeding
|
2018-09-28 13:23:47 +00:00
|
|
|
this.$scope.syscollectorEnabled = await this.configurationHandler.isWodleEnabled(
|
|
|
|
'syscollector',
|
|
|
|
id
|
|
|
|
);
|
2018-09-27 15:27:14 +00:00
|
|
|
|
|
|
|
// If Syscollector is disabled, stop loading
|
|
|
|
if (!this.$scope.syscollectorEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue API requests if we do have Syscollector enabled
|
2018-09-28 11:12:40 +00:00
|
|
|
// Fetch Syscollector data
|
2018-09-11 09:52:54 +00:00
|
|
|
const data = await Promise.all([
|
|
|
|
this.apiReq.request('GET', `/syscollector/${id}/hardware`, {}),
|
|
|
|
this.apiReq.request('GET', `/syscollector/${id}/os`, {}),
|
|
|
|
this.apiReq.request('GET', `/syscollector/${id}/netiface`, {}),
|
|
|
|
this.apiReq.request('GET', `/syscollector/${id}/ports`, {}),
|
|
|
|
this.apiReq.request('GET', `/syscollector/${id}/packages`, {
|
|
|
|
limit: 1,
|
|
|
|
select: 'scan_time'
|
2018-09-14 05:22:28 +00:00
|
|
|
}),
|
|
|
|
this.apiReq.request('GET', `/syscollector/${id}/processes`, {
|
|
|
|
limit: 1,
|
|
|
|
select: 'scan_time'
|
2018-09-11 09:52:54 +00:00
|
|
|
})
|
|
|
|
]);
|
2018-09-28 11:12:40 +00:00
|
|
|
|
2018-10-22 14:51:20 +00:00
|
|
|
const result = data.map(
|
|
|
|
item => (item && item.data && item.data.data ? item.data.data : false)
|
|
|
|
);
|
|
|
|
const [
|
|
|
|
hardwareResponse,
|
|
|
|
osResponse,
|
|
|
|
netifaceResponse,
|
|
|
|
portsResponse,
|
|
|
|
packagesDateResponse,
|
|
|
|
processesDateResponse
|
|
|
|
] = result;
|
|
|
|
|
2018-09-28 13:23:47 +00:00
|
|
|
// Before proceeding, syscollector data is an empty object
|
2018-09-28 11:12:40 +00:00
|
|
|
this.$scope.syscollector = {};
|
|
|
|
|
2018-10-22 14:51:20 +00:00
|
|
|
const packagesDate = packagesDateResponse
|
|
|
|
? { ...packagesDateResponse }
|
|
|
|
: false;
|
|
|
|
const processesDate = processesDateResponse
|
|
|
|
? { ...processesDateResponse }
|
|
|
|
: false;
|
2018-09-28 11:12:40 +00:00
|
|
|
|
|
|
|
// Fill syscollector object
|
|
|
|
this.$scope.syscollector = {
|
2018-10-22 14:51:20 +00:00
|
|
|
hardware:
|
|
|
|
typeof hardwareResponse === 'object' &&
|
2018-11-21 11:15:27 +00:00
|
|
|
Object.keys(hardwareResponse).length
|
2018-10-22 14:51:20 +00:00
|
|
|
? { ...hardwareResponse }
|
|
|
|
: false,
|
|
|
|
os:
|
|
|
|
typeof osResponse === 'object' && Object.keys(osResponse).length
|
|
|
|
? { ...osResponse }
|
|
|
|
: false,
|
|
|
|
netiface: netifaceResponse ? { ...netifaceResponse } : false,
|
|
|
|
ports: portsResponse ? { ...portsResponse } : false,
|
2018-09-28 11:12:40 +00:00
|
|
|
packagesDate:
|
|
|
|
packagesDate && packagesDate.items && packagesDate.items.length
|
|
|
|
? packagesDate.items[0].scan_time
|
|
|
|
: 'Unknown',
|
|
|
|
processesDate:
|
|
|
|
processesDate && processesDate.items && processesDate.items.length
|
|
|
|
? processesDate.items[0].scan_time
|
|
|
|
: 'Unknown'
|
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
return;
|
2018-09-11 09:52:54 +00:00
|
|
|
} catch (error) {
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
async getAgent(newAgentId) {
|
|
|
|
try {
|
2018-10-03 14:19:16 +00:00
|
|
|
this.$scope.isSynchronized = false;
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.load = true;
|
|
|
|
this.changeAgent = true;
|
2018-01-15 11:44:37 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
const globalAgent = this.shareAgent.getAgent();
|
2018-01-17 16:29:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
const id = this.commonData.checkLocationAgentId(newAgentId, globalAgent);
|
2018-01-15 15:11:45 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
const data = await Promise.all([
|
|
|
|
this.apiReq.request('GET', `/agents/${id}`, {}),
|
|
|
|
this.apiReq.request('GET', `/syscheck/${id}/last_scan`, {}),
|
2018-10-25 10:01:25 +00:00
|
|
|
this.apiReq.request('GET', `/rootcheck/${id}/last_scan`, {})
|
2018-09-11 09:52:54 +00:00
|
|
|
]);
|
|
|
|
|
2018-10-22 14:51:20 +00:00
|
|
|
const result = data.map(
|
|
|
|
item => (item && item.data && item.data.data ? item.data.data : false)
|
|
|
|
);
|
2018-10-25 16:12:58 +00:00
|
|
|
|
|
|
|
const [agentInfo, syscheckLastScan, rootcheckLastScan] = result;
|
2018-10-22 14:51:20 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
// Agent
|
2018-10-22 14:51:20 +00:00
|
|
|
this.$scope.agent = agentInfo;
|
2018-09-11 09:52:54 +00:00
|
|
|
if (this.$scope.agent.os) {
|
|
|
|
this.$scope.agentOS =
|
|
|
|
this.$scope.agent.os.name + ' ' + this.$scope.agent.os.version;
|
|
|
|
} else {
|
|
|
|
this.$scope.agentOS = 'Unknown';
|
|
|
|
}
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
// Syscheck
|
2018-10-22 14:51:20 +00:00
|
|
|
this.$scope.agent.syscheck = syscheckLastScan;
|
2018-09-11 09:52:54 +00:00
|
|
|
this.validateSysCheck();
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
// Rootcheck
|
2018-10-22 14:51:20 +00:00
|
|
|
this.$scope.agent.rootcheck = rootcheckLastScan;
|
2018-09-11 09:52:54 +00:00
|
|
|
this.validateRootCheck();
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-10-25 09:52:33 +00:00
|
|
|
await this.$scope.switchTab(this.$scope.tab, true);
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.load = false;
|
|
|
|
if (!this.$scope.$$phase) this.$scope.$digest();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
|
|
this.errorHandler.handle(error, 'Agents');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-24 15:47:01 +00:00
|
|
|
goGroups(agent, group) {
|
2018-09-11 09:52:54 +00:00
|
|
|
this.visFactoryService.clearAll();
|
2018-09-24 15:47:01 +00:00
|
|
|
this.shareAgent.setAgent(agent, group);
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$location.search('tab', 'groups');
|
|
|
|
this.$location.path('/manager');
|
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
async analyzeAgents(searchTerm) {
|
|
|
|
try {
|
|
|
|
if (searchTerm) {
|
|
|
|
const reqData = await this.apiReq.request('GET', '/agents', {
|
|
|
|
search: searchTerm
|
|
|
|
});
|
|
|
|
return reqData.data.data.items.filter(item => item.id !== '000');
|
|
|
|
} else {
|
|
|
|
const reqData = await this.apiReq.request('GET', '/agents', {});
|
|
|
|
return reqData.data.data.items.filter(item => item.id !== '000');
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-09-11 09:52:54 +00:00
|
|
|
} catch (error) {
|
|
|
|
this.errorHandler.handle(error, 'Agents');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
async downloadCsv(data_path) {
|
|
|
|
try {
|
|
|
|
this.errorHandler.info(
|
|
|
|
'Your download should begin automatically...',
|
|
|
|
'CSV'
|
|
|
|
);
|
|
|
|
const currentApi = JSON.parse(this.appState.getCurrentAPI()).id;
|
|
|
|
const output = await this.csvReq.fetch(
|
|
|
|
data_path,
|
|
|
|
currentApi,
|
|
|
|
this.wzTableFilter.get()
|
|
|
|
);
|
|
|
|
const blob = new Blob([output], { type: 'text/csv' }); // eslint-disable-line
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, 'packages.csv');
|
2018-05-14 08:05:25 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
|
|
this.errorHandler.handle(error, 'Download CSV');
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
async firstLoad() {
|
|
|
|
try {
|
|
|
|
const globalAgent = this.shareAgent.getAgent();
|
|
|
|
this.$scope.configurationError = false;
|
|
|
|
this.$scope.load = true;
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
const id = this.commonData.checkLocationAgentId(false, globalAgent);
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
const data = await this.apiReq.request('GET', `/agents/${id}`, {});
|
|
|
|
this.$scope.agent = data.data.data;
|
|
|
|
this.$scope.groupName = this.$scope.agent.group;
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
if (!this.$scope.groupName) {
|
|
|
|
this.$scope.configurationError = true;
|
|
|
|
this.$scope.load = false;
|
|
|
|
if (!this.$scope.$$phase) this.$scope.$digest();
|
2018-06-04 15:48:41 +00:00
|
|
|
return;
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-05-30 16:16:34 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
this.$scope.load = false;
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
if (this.$scope.tab !== 'configuration')
|
2018-10-25 09:52:33 +00:00
|
|
|
await this.$scope.switchTab(this.$scope.tab, true);
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
if (!this.$scope.$$phase) this.$scope.$digest();
|
2018-09-10 08:32:49 +00:00
|
|
|
return;
|
2018-09-11 09:52:54 +00:00
|
|
|
} catch (error) {
|
|
|
|
this.errorHandler.handle(error, 'Agents');
|
2018-06-07 10:37:16 +00:00
|
|
|
}
|
2018-09-11 09:52:54 +00:00
|
|
|
return;
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-09-11 09:52:54 +00:00
|
|
|
/** End of agent configuration */
|
2018-06-18 15:50:23 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
startVis2Png() {
|
|
|
|
const syscollectorFilters = [];
|
|
|
|
if (
|
|
|
|
this.$scope.tab === 'syscollector' &&
|
|
|
|
this.$scope.agent &&
|
|
|
|
this.$scope.agent.id
|
|
|
|
) {
|
|
|
|
syscollectorFilters.push(
|
|
|
|
this.filterHandler.managerQuery(
|
|
|
|
this.appState.getClusterInfo().cluster,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
|
|
|
syscollectorFilters.push(
|
|
|
|
this.filterHandler.agentQuery(this.$scope.agent.id)
|
2018-09-10 08:32:49 +00:00
|
|
|
);
|
2018-06-07 10:37:16 +00:00
|
|
|
}
|
2018-09-11 09:52:54 +00:00
|
|
|
this.reportingService.startVis2Png(
|
|
|
|
this.$scope.tab,
|
|
|
|
this.$scope.agent && this.$scope.agent.id ? this.$scope.agent.id : true,
|
|
|
|
syscollectorFilters.length ? syscollectorFilters : null
|
|
|
|
);
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-09-11 09:52:54 +00:00
|
|
|
}
|