table mode with triggers stats, #141

This commit is contained in:
Alexander Zobnin
2017-10-22 19:01:46 +03:00
parent 6c64f21b1a
commit 1f5e261d4a
22 changed files with 224 additions and 98 deletions

View File

@@ -20,3 +20,12 @@ export const SHOW_OK_EVENTS = 1;
// Data point
export const DATAPOINT_VALUE = 0;
export const DATAPOINT_TS = 1;
export const TRIGGER_SEVERITY = [
{val: 0, text: 'Not classified'},
{val: 1, text: 'Information'},
{val: 2, text: 'Warning'},
{val: 3, text: 'Average'},
{val: 4, text: 'High'},
{val: 5, text: 'Disaster'}
];

View File

@@ -362,7 +362,7 @@ class ZabbixAPIDatasource {
if (hosts.length) {
let hostids = _.map(hosts, 'hostid');
let appids = _.map(apps, 'applicationid');
return this.zabbix.getHostAlerts(hostids, appids, target.minSeverity, target.options.countTriggers, timeFrom, timeTo)
return this.zabbix.getHostAlerts(hostids, appids, target.minSeverity, target.countTriggers, timeFrom, timeTo)
.then((triggers) => {
return responseHandler.handleTriggersResponse(triggers, timeRange);
});

View File

@@ -118,9 +118,9 @@
}">
</div>
<div class="gf-form max-width-20" ng-show="ctrl.target.mode == editorMode.TRIGGERS">
<div class="gf-form max-width-23" ng-show="ctrl.target.mode == editorMode.TRIGGERS">
<label class="gf-form-label query-keyword width-8">Min Severity</label>
<div class="gf-form-select-wrapper width-20">
<div class="gf-form-select-wrapper width-16">
<select class="gf-form-input"
ng-change="ctrl.onTargetBlur()"
ng-model="ctrl.target.minSeverity"
@@ -129,9 +129,12 @@
</div>
</div>
<gf-form-switch class="gf-form" label="Count" checked="ctrl.target.countTriggers" on-change="ctrl.onTargetBlur()">
</gf-form-switch>
<div class="gf-form gf-form--grow">
<label class="gf-form-label gf-form-label--grow">
<a ng-click="ctrl.toggleQueryOptions()">
<a ng-click="ctrl.toggleQueryOptions()" ng-hide="ctrl.target.mode == editorMode.TRIGGERS">
<i class="fa fa-caret-down" ng-show="ctrl.showQueryOptions"></i>
<i class="fa fa-caret-right" ng-hide="ctrl.showQueryOptions"></i>
{{ctrl.queryOptionsText}}
@@ -149,13 +152,6 @@
on-change="ctrl.onQueryOptionChange()">
</gf-form-switch>
</div>
<div class="gf-form offset-width-7" ng-show="ctrl.target.mode == editorMode.TRIGGERS">
<gf-form-switch class="gf-form"
label="Count triggers"
checked="ctrl.target.options.countTriggers"
on-change="ctrl.onQueryOptionChange()">
</gf-form-switch>
</div>
</div>
<!-- Item IDs editor mode -->

View File

@@ -45,11 +45,7 @@ export class ZabbixQueryController extends QueryCtrl {
{name: "Down time", property: "downtimeTime"}
];
this.triggerSeverity = [
{val: 0, text: 'Not classified'}, {val: 1, text:'Information'},
{val: 2, text: 'Warning'}, {val: 3, text: 'Average'},
{val: 4, text: 'High'}, {val: 5, text: 'Disaster'}
];
this.triggerSeverity = c.TRIGGER_SEVERITY;
// Map functions for bs-typeahead
this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');
@@ -89,9 +85,9 @@ export class ZabbixQueryController extends QueryCtrl {
'item': { 'filter': "" },
'functions': [],
'minSeverity': 3,
'countTriggers': true,
'options': {
'showDisabledItems': false,
'countTriggers': true
'showDisabledItems': false
}
};
_.defaults(target, targetDefaults);
@@ -293,8 +289,7 @@ export class ZabbixQueryController extends QueryCtrl {
renderQueryOptionsText() {
var optionsMap = {
showDisabledItems: "Show disabled items",
countTriggers: "Count Triggers"
showDisabledItems: "Show disabled items"
};
var options = [];
_.forOwn(this.target.options, (value, key) => {

View File

@@ -1,4 +1,6 @@
import _ from 'lodash';
import TableModel from 'app/core/table_model';
import * as c from './constants';
/**
* Convert Zabbix API history.get response to Grafana format
@@ -105,14 +107,40 @@ function handleTriggersResponse(triggers, timeRange) {
return {
target: "triggers count",
datapoints: [
[triggers, timeRange[1]]
[triggers, timeRange[1] * 1000]
]
};
} else {
return triggers;
let stats = getTriggerStats(triggers);
let table = new TableModel();
table.addColumn({text: 'Host group'});
_.each(_.orderBy(c.TRIGGER_SEVERITY, ['val'], ['desc']), (severity) => {
table.addColumn({text: severity.text});
});
_.each(stats, (severity_stats, group) => {
let row = _.map(_.orderBy(_.toPairs(severity_stats), (s) => s[0], ['desc']), (s) => s[1]);
row = _.concat([group], ...row);
table.rows.push(row);
});
return table;
}
}
function getTriggerStats(triggers) {
let groups = _.uniq(_.flattenDeep(_.map(triggers, (trigger) => _.map(trigger.groups, 'name'))));
// let severity = _.map(c.TRIGGER_SEVERITY, 'text');
let stats = {};
_.each(groups, (group) => {
stats[group] = {0:0, 1:0, 2:0, 3:0, 4:0, 5:0}; // severity:count
});
_.each(triggers, (trigger) => {
_.each(trigger.groups, (group) => {
stats[group.name][trigger.priority]++;
});
});
return stats;
}
function convertHistoryPoint(point) {
// Value must be a number for properly work
return [

View File

@@ -445,7 +445,9 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
expandComment: true,
monitored: true,
skipDependent: true,
selectLastEvent: 'extend'
selectLastEvent: 'extend',
selectGroups: 'extend',
selectHosts: ['host', 'name']
};
if (count) {