Skip to content

Commit

Permalink
Before creating a watcher from a visualization delete all properties …
Browse files Browse the repository at this point in the history
…starting with '$' prefix in its search request.

Get exact index names.
  • Loading branch information
sergibondarenko committed May 7, 2018
1 parent 4d11f11 commit 49450ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
15 changes: 6 additions & 9 deletions public/dashboard_spy_button/alarm_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* limitations under the License.
*/

import { stripObjectPropertiesByNameRegex } from '../lib/sentinl_helper';

import _ from 'lodash';
import { SpyModesRegistryProvider } from 'ui/registry/spy_modes';
import EMAILWATCHER from '../constants/email_watcher';
Expand All @@ -37,15 +39,8 @@ const dashboardSpyButton = function ($scope, config) {
$scope.indices = [];

if (req.fetchParams && req.fetchParams.index) {
const idx = req.fetchParams.index.toString();
indexPattern = $scope.searchSource.get('index');
if (indexPattern.getTimeField()) {
const tmp = idx.replace(/\*/g, '');
$scope.indices.push(`<${tmp}{now/d}>`);
$scope.indices.push(`<${tmp}{now/d-1d}>`);
} else {
$scope.indices.push(idx);
}
const index = req.fetchParams.index.toString();
$scope.indices.push(index);
}

$scope.createWatcher = function () {
Expand Down Expand Up @@ -79,6 +74,8 @@ const dashboardSpyButton = function ($scope, config) {
}
});
}

stripObjectPropertiesByNameRegex(alarm._source.input.search, /\$.*/);
window.localStorage.setItem('sentinl_saved_query', JSON.stringify(alarm));
};

Expand Down
31 changes: 31 additions & 0 deletions public/lib/sentinl_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const isObject = function (arg) {
return arg != null && typeof arg === 'object';
};

const stripObjectPropertiesByNameRegex = function (obj, nameRegex) {
if (!isObject(obj)) return;

for (let key in obj) {
if (!!key.match(nameRegex)) {
delete obj[key];
}

if (Array.isArray(obj[key])) {
let i = obj[key].length;
while (i--) {
if (typeof obj[key][i] === 'string' && !!obj[key][i].match(nameRegex)) {
obj[key].splice(i, 1);
}
}
}

if (isObject(obj[key])) {
stripObjectPropertiesByNameRegex(obj[key], nameRegex);
}
}
};

export {
stripObjectPropertiesByNameRegex,
isObject,
};

0 comments on commit 49450ac

Please sign in to comment.