Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More optimizations #997

Merged
merged 4 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wazuh",
"version": "3.7.0",
"revision": "0413",
"code":"0413-3",
"code":"0413-4",
"kibana": {
"version": "6.4.2"
},
Expand Down
92 changes: 40 additions & 52 deletions public/controllers/overview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ app.controller('overviewController', function(
preserveDiscover = false
) => {
try {
if (
$scope.tab &&
$scope.tab === 'welcome' &&
typeof $scope.agentsCountTotal === 'undefined'
) {
await getSummary();
}

if ($scope.tabView === subtab && !force) return;

visFactoryService.clear();
Expand All @@ -146,12 +138,11 @@ app.controller('overviewController', function(
}

checkMetrics($scope.tab, subtab);

return;
} catch (error) {
errorHandler.handle(error, 'Overview');
return;
}
if (!$scope.$$phase) $scope.$digest();
return;
};

let wodlesConfiguration;
Expand Down Expand Up @@ -198,42 +189,45 @@ app.controller('overviewController', function(
};

// Switch tab
$scope.switchTab = (tab, force = false) => {
filterWodle(tab);
if (tab !== 'welcome') tabHistory.push(tab);
if (tabHistory.length > 2) tabHistory = tabHistory.slice(-2);
tabVisualizations.setTab(tab);
if ($scope.tab === tab && !force) return;
const sameTab = $scope.tab === tab;
$location.search('tab', tab);
const preserveDiscover =
tabHistory.length === 2 && tabHistory[0] === tabHistory[1];
$scope.tab = tab;

$scope.switchSubtab('panels', true, sameTab, preserveDiscover);
};

$scope.startVis2Png = () => reportingService.startVis2Png($scope.tab);

// PCI and GDPR requirements
const loadPciAndGDPR = async () => {
$scope.switchTab = async (tab, force = false) => {
try {
const data = await Promise.all([
commonData.getPCI(),
commonData.getGDPR()
]);
const [pciTabs, gdprTabs] = data;
$scope.pciTabs = pciTabs;
$scope.selectedPciIndex = 0;
$scope.gdprTabs = gdprTabs;
$scope.selectedGdprIndex = 0;

return;
if (tab !== 'welcome') {
await fetchWodles();
}
if (tab === 'welcome' && typeof $scope.agentsCountTotal === 'undefined') {
await getSummary();
}
if (tab === 'pci') {
const pciTabs = await commonData.getPCI();
$scope.pciTabs = pciTabs;
$scope.selectedPciIndex = 0;
}
if (tab === 'gdpr') {
const gdprTabs = await commonData.getGDPR();
$scope.gdprTabs = gdprTabs;
$scope.selectedGdprIndex = 0;
}
filterWodle(tab);
if (tab !== 'welcome') tabHistory.push(tab);
if (tabHistory.length > 2) tabHistory = tabHistory.slice(-2);
tabVisualizations.setTab(tab);
if ($scope.tab === tab && !force) return;
const sameTab = $scope.tab === tab;
$location.search('tab', tab);
const preserveDiscover =
tabHistory.length === 2 && tabHistory[0] === tabHistory[1];
$scope.tab = tab;

await $scope.switchSubtab('panels', true, sameTab, preserveDiscover);
} catch (error) {
return Promise.reject(error);
errorHandler.handle(error, 'Overview');
}
if (!$scope.$$phase) $scope.$digest();
return;
};

$scope.startVis2Png = () => reportingService.startVis2Png($scope.tab);

const getSummary = async () => {
try {
const data = await apiReq.request('GET', '/agents/summary', {});
Expand Down Expand Up @@ -270,19 +264,13 @@ app.controller('overviewController', function(

const init = async () => {
try {
await Promise.all([loadPciAndGDPR(), loadConfiguration(), fetchWodles()]);

$scope.switchTab($scope.tab, true);

await getSummary();

if (!$scope.$$phase) $scope.$digest();

return;
await loadConfiguration();
await $scope.switchTab($scope.tab, true);
} catch (error) {
errorHandler.handle(error, 'Overview (init)');
return;
}
if (!$scope.$$phase) $scope.$digest();
return;
};

init();
Expand Down
6 changes: 5 additions & 1 deletion public/services/pattern-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export class PatternHandler {

async getPatternList() {
try {
const patternList = await this.genericReq.request('GET', '/elastic/index-patterns', {});
const patternList = await this.genericReq.request(
'GET',
'/elastic/index-patterns',
{}
);

if (!patternList.data.data.length) {
this.wzMisc.setBlankScr('Sorry but no valid index patterns were found');
Expand Down
4 changes: 2 additions & 2 deletions public/services/resolves/get-ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export function getIp(

const { savedObjects } = savedObjectsData;

const data = await genericReq.request('GET', '/elastic/index-patterns');

let currentPattern = '';

if (appState.getCurrentPattern()) {
// There's cookie for the pattern
currentPattern = appState.getCurrentPattern();
} else {
const data = await genericReq.request('GET', '/elastic/index-patterns');

if (!data || !data.data || !data.data.data || !data.data.data.length) {
wzMisc.setBlankScr('Sorry but no valid index patterns were found');
$location.search('tab', null);
Expand Down
23 changes: 18 additions & 5 deletions server/controllers/wazuh-elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export class WazuhElasticCtrl {
.filter(item => item.includes('[') && item.includes(']'));
const pattern =
lastChar === '*' ? req.params.pattern.slice(0, -1) : req.params.pattern;
const isIncluded = array.filter(item => item.includes(pattern));
const isIncluded = array.filter(item => {
item = item.slice(1, -1);
const lastChar = item[item.length - 1];
item = lastChar === '*' ? item.slice(0, -1) : item;
return item.includes(pattern) || pattern.includes(item);
});

return isIncluded && Array.isArray(isIncluded) && isIncluded.length
? reply({
Expand Down Expand Up @@ -254,7 +259,7 @@ export class WazuhElasticCtrl {
async getlist(req, reply) {
try {
const config = getConfiguration();

const xpack = await this.wzWrapper.getPlugins();

const isXpackEnabled =
Expand All @@ -277,9 +282,17 @@ export class WazuhElasticCtrl {

if (data && data.hits && data.hits.hits) {
let list = this.validateIndexPattern(data.hits.hits);
if(config && config['ip.ignore'] && Array.isArray(config['ip.ignore']) && config['ip.ignore'].length){
list = list.filter(item => item && item.title && !config['ip.ignore'].includes(item.title));
}
if (
config &&
config['ip.ignore'] &&
Array.isArray(config['ip.ignore']) &&
config['ip.ignore'].length
) {
list = list.filter(
item =>
item && item.title && !config['ip.ignore'].includes(item.title)
);
}
return reply({
data:
isXpackEnabled && !isSuperUser
Expand Down