wazuh-kibana-app/public/services/pattern-handler.js
2018-04-22 22:16:38 +02:00

51 lines
1.9 KiB
JavaScript

/*
* Wazuh app - Pattern handler service
* 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.
*/
require('ui/modules').get('app/wazuh', [])
.service('patternHandler', function ($rootScope, $location, genericReq, appState, errorHandler) {
return {
getPatternList: async () => {
try {
const patternList = await genericReq.request('GET','/get-list',{});
if(!patternList.data.data.length){
$rootScope.blankScreenError = 'Sorry but no valid index patterns were found'
$location.search('tab',null);
$location.path('/blank-screen');
return;
}
if(appState.getCurrentPattern()){
let filtered = patternList.data.data.filter(item => item.id.includes(appState.getCurrentPattern()))
if(!filtered.length) appState.setCurrentPattern(patternList.data.data[0].id)
}
return patternList.data.data;
} catch (error) {
errorHandler.handle(error,'Pattern Handler (getPatternList)');
if(!$rootScope.$$phase) $rootScope.$digest();
}
},
changePattern: async selectedPattern => {
try {
appState.setCurrentPattern(selectedPattern);
await genericReq.request('GET',`/refresh-fields/${selectedPattern}`,{})
return appState.getCurrentPattern();
} catch (error) {
errorHandler.handle(error,'Pattern Handler (changePattern)');
if(!$rootScope.$$phase) $rootScope.$digest();
}
}
};
});