Skip to content

Commit

Permalink
filter triggers by acknowledged status, #141
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Oct 24, 2017
1 parent 2b5af92 commit 611bd8b
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 44 deletions.
17 changes: 8 additions & 9 deletions dist/dashboards/zabbix_system_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
"application": {
"filter": ""
},
"countTriggers": false,
"functions": [],
"group": {
"filter": "/.*/"
Expand All @@ -182,11 +181,11 @@
"item": {
"filter": ""
},
"minSeverity": 0,
"mode": 4,
"options": {
"countTriggers": false,
"showDisabledItems": false
"triggers": {
"count": false,
"minSeverity": 0,
"acknowledged": 2
},
"refId": "A",
"target": ""
Expand Down Expand Up @@ -269,7 +268,6 @@
"application": {
"filter": ""
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
Expand All @@ -280,10 +278,11 @@
"item": {
"filter": ""
},
"minSeverity": 3,
"mode": 4,
"options": {
"showDisabledItems": false
"triggers": {
"count": true,
"minSeverity": 3,
"acknowledged": 2
},
"refId": "A",
"target": ""
Expand Down
9 changes: 8 additions & 1 deletion dist/datasource-zabbix/datasource.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource-zabbix/datasource.js.map

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions dist/datasource-zabbix/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,24 @@
<div class="gf-form-select-wrapper width-16">
<select class="gf-form-input"
ng-change="ctrl.onTargetBlur()"
ng-model="ctrl.target.minSeverity"
ng-model="ctrl.target.triggers.minSeverity"
ng-options="s.val as s.text for s in ctrl.triggerSeverity">
</select>
</div>
</div>
<div class="gf-form max-width-20" ng-show="ctrl.target.mode == editorMode.TRIGGERS">
<label class="gf-form-label query-keyword width-8">Acknowledged</label>
<div class="gf-form-select-wrapper width-12">
<select class="gf-form-input"
ng-change="ctrl.onTargetBlur()"
ng-model="ctrl.target.triggers.acknowledged"
ng-options="a.value as a.text for a in ctrl.ackFilters">
</select>
</div>
</div>

<gf-form-switch class="gf-form" label="Count" ng-show="ctrl.target.mode == editorMode.TRIGGERS"
checked="ctrl.target.countTriggers" on-change="ctrl.onTargetBlur()">
checked="ctrl.target.triggers.count" on-change="ctrl.onTargetBlur()">
</gf-form-switch>

<div class="gf-form gf-form--grow">
Expand Down
9 changes: 7 additions & 2 deletions dist/datasource-zabbix/query.controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource-zabbix/query.controller.js.map

Large diffs are not rendered by default.

34 changes: 31 additions & 3 deletions dist/datasource-zabbix/zabbixAPI.service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource-zabbix/zabbixAPI.service.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion dist/test/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,14 @@ var ZabbixAPIDatasource = function () {
if (hosts.length) {
var hostids = _lodash2.default.map(hosts, 'hostid');
var appids = _lodash2.default.map(apps, 'applicationid');
return _this7.zabbix.getHostAlerts(hostids, appids, target.minSeverity, target.countTriggers, timeFrom, timeTo).then(function (triggers) {
var options = {
minSeverity: target.triggers.minSeverity,
acknowledged: target.triggers.acknowledged,
count: target.triggers.count,
timeFrom: timeFrom,
timeTo: timeTo
};
return _this7.zabbix.getHostAlerts(hostids, appids, options).then(function (triggers) {
return _responseHandler2.default.handleTriggersResponse(triggers, timeRange);
});
} else {
Expand Down
9 changes: 7 additions & 2 deletions dist/test/datasource-zabbix/query.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl

_this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];

_this.ackFilters = [{ text: 'all triggers', value: 2 }, { text: 'unacknowledged', value: 0 }, { text: 'acknowledged', value: 1 }];

_this.triggerSeverity = c.TRIGGER_SEVERITY;

// Map functions for bs-typeahead
Expand Down Expand Up @@ -113,8 +115,11 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
'application': { 'filter': "" },
'item': { 'filter': "" },
'functions': [],
'minSeverity': 3,
'countTriggers': true,
'triggers': {
'count': true,
'minSeverity': 3,
'acknowledged': 2
},
'options': {
'showDisabledItems': false
}
Expand Down
34 changes: 31 additions & 3 deletions dist/test/datasource-zabbix/zabbixAPI.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,13 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
}
}, {
key: 'getHostAlerts',
value: function getHostAlerts(hostids, applicationids, minSeverity, count, timeFrom, timeTo) {
value: function getHostAlerts(hostids, applicationids, options) {
var minSeverity = options.minSeverity,
acknowledged = options.acknowledged,
count = options.count,
timeFrom = options.timeFrom,
timeTo = options.timeTo;

var params = {
output: 'extend',
hostids: hostids,
Expand All @@ -503,7 +509,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
selectHosts: ['host', 'name']
};

if (count) {
if (count && acknowledged !== 0 && acknowledged !== 1) {
params.countOutput = true;
}

Expand All @@ -516,7 +522,15 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
params.lastChangeTill = timeTo;
}

return this.request('trigger.get', params);
return this.request('trigger.get', params).then(function (triggers) {
if (!count || acknowledged === 0 || acknowledged === 1) {
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
if (count) {
triggers = triggers.length;
}
}
return triggers;
});
}
}]);

Expand All @@ -526,6 +540,20 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
return ZabbixAPI;
}

function filterTriggersByAcknowledge(triggers, acknowledged) {
if (acknowledged === 0) {
return _lodash2.default.filter(triggers, function (trigger) {
return trigger.lastEvent.acknowledged === "0";
});
} else if (acknowledged === 1) {
return _lodash2.default.filter(triggers, function (trigger) {
return trigger.lastEvent.acknowledged === "1";
});
} else {
return triggers;
}
}

function isNotAuthorized(message) {
return message === "Session terminated, re-login, please." || message === "Not authorised." || message === "Not authorized.";
}
Expand Down
17 changes: 8 additions & 9 deletions src/dashboards/zabbix_system_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
"application": {
"filter": ""
},
"countTriggers": false,
"functions": [],
"group": {
"filter": "/.*/"
Expand All @@ -182,11 +181,11 @@
"item": {
"filter": ""
},
"minSeverity": 0,
"mode": 4,
"options": {
"countTriggers": false,
"showDisabledItems": false
"triggers": {
"count": false,
"minSeverity": 0,
"acknowledged": 2
},
"refId": "A",
"target": ""
Expand Down Expand Up @@ -269,7 +268,6 @@
"application": {
"filter": ""
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
Expand All @@ -280,10 +278,11 @@
"item": {
"filter": ""
},
"minSeverity": 3,
"mode": 4,
"options": {
"showDisabledItems": false
"triggers": {
"count": true,
"minSeverity": 3,
"acknowledged": 2
},
"refId": "A",
"target": ""
Expand Down
9 changes: 8 additions & 1 deletion src/datasource-zabbix/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,14 @@ class ZabbixAPIDatasource {
if (hosts.length) {
let hostids = _.map(hosts, 'hostid');
let appids = _.map(apps, 'applicationid');
return this.zabbix.getHostAlerts(hostids, appids, target.minSeverity, target.countTriggers, timeFrom, timeTo)
let options = {
minSeverity: target.triggers.minSeverity,
acknowledged: target.triggers.acknowledged,
count: target.triggers.count,
timeFrom: timeFrom,
timeTo: timeTo
};
return this.zabbix.getHostAlerts(hostids, appids, options)
.then((triggers) => {
return responseHandler.handleTriggersResponse(triggers, timeRange);
});
Expand Down
14 changes: 12 additions & 2 deletions src/datasource-zabbix/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,24 @@
<div class="gf-form-select-wrapper width-16">
<select class="gf-form-input"
ng-change="ctrl.onTargetBlur()"
ng-model="ctrl.target.minSeverity"
ng-model="ctrl.target.triggers.minSeverity"
ng-options="s.val as s.text for s in ctrl.triggerSeverity">
</select>
</div>
</div>
<div class="gf-form max-width-20" ng-show="ctrl.target.mode == editorMode.TRIGGERS">
<label class="gf-form-label query-keyword width-8">Acknowledged</label>
<div class="gf-form-select-wrapper width-12">
<select class="gf-form-input"
ng-change="ctrl.onTargetBlur()"
ng-model="ctrl.target.triggers.acknowledged"
ng-options="a.value as a.text for a in ctrl.ackFilters">
</select>
</div>
</div>

<gf-form-switch class="gf-form" label="Count" ng-show="ctrl.target.mode == editorMode.TRIGGERS"
checked="ctrl.target.countTriggers" on-change="ctrl.onTargetBlur()">
checked="ctrl.target.triggers.count" on-change="ctrl.onTargetBlur()">
</gf-form-switch>

<div class="gf-form gf-form--grow">
Expand Down
13 changes: 11 additions & 2 deletions src/datasource-zabbix/query.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export class ZabbixQueryController extends QueryCtrl {
{name: "Down time", property: "downtimeTime"}
];

this.ackFilters = [
{text: 'all triggers', value: 2},
{text: 'unacknowledged', value: 0},
{text: 'acknowledged', value: 1},
];

this.triggerSeverity = c.TRIGGER_SEVERITY;

// Map functions for bs-typeahead
Expand Down Expand Up @@ -84,8 +90,11 @@ export class ZabbixQueryController extends QueryCtrl {
'application': { 'filter': "" },
'item': { 'filter': "" },
'functions': [],
'minSeverity': 3,
'countTriggers': true,
'triggers': {
'count': true,
'minSeverity': 3,
'acknowledged': 2
},
'options': {
'showDisabledItems': false
}
Expand Down
Loading

0 comments on commit 611bd8b

Please sign in to comment.