Merge remote-tracking branch 'upstream/master' into threshold_regex
# Conflicts: # dist/datasource-zabbix/datasource.js # dist/datasource-zabbix/datasource.js.map # dist/datasource-zabbix/specs/test-main.js # dist/test/datasource-zabbix/datasource.js # dist/test/datasource-zabbix/specs/test-main.js
This commit is contained in:
@@ -3,6 +3,7 @@ export const MODE_METRICS = 0;
|
||||
export const MODE_ITSERVICE = 1;
|
||||
export const MODE_TEXT = 2;
|
||||
export const MODE_ITEMID = 3;
|
||||
export const MODE_TRIGGERS = 4;
|
||||
|
||||
// Triggers severity
|
||||
export const SEV_NOT_CLASSIFIED = 0;
|
||||
@@ -19,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'}
|
||||
];
|
||||
|
||||
@@ -28,26 +28,28 @@ class ZabbixAPIDatasource {
|
||||
this.basicAuth = instanceSettings.basicAuth;
|
||||
this.withCredentials = instanceSettings.withCredentials;
|
||||
|
||||
const jsonData = instanceSettings.jsonData;
|
||||
|
||||
// Zabbix API credentials
|
||||
this.username = instanceSettings.jsonData.username;
|
||||
this.password = instanceSettings.jsonData.password;
|
||||
this.username = jsonData.username;
|
||||
this.password = jsonData.password;
|
||||
|
||||
// Use trends instead history since specified time
|
||||
this.trends = instanceSettings.jsonData.trends;
|
||||
this.trendsFrom = instanceSettings.jsonData.trendsFrom || '7d';
|
||||
this.trendsRange = instanceSettings.jsonData.trendsRange || '4d';
|
||||
this.trends = jsonData.trends;
|
||||
this.trendsFrom = jsonData.trendsFrom || '7d';
|
||||
this.trendsRange = jsonData.trendsRange || '4d';
|
||||
|
||||
// Set cache update interval
|
||||
var ttl = instanceSettings.jsonData.cacheTTL || '1h';
|
||||
var ttl = jsonData.cacheTTL || '1h';
|
||||
this.cacheTTL = utils.parseInterval(ttl);
|
||||
|
||||
// Alerting options
|
||||
this.alertingEnabled = instanceSettings.jsonData.alerting;
|
||||
this.addThresholds = instanceSettings.jsonData.addThresholds;
|
||||
this.alertingMinSeverity = instanceSettings.jsonData.alertingMinSeverity || c.SEV_WARNING;
|
||||
this.alertingEnabled = jsonData.alerting;
|
||||
this.addThresholds = jsonData.addThresholds;
|
||||
this.alertingMinSeverity = jsonData.alertingMinSeverity || c.SEV_WARNING;
|
||||
|
||||
// Direct DB Connection options
|
||||
let dbConnectionOptions = instanceSettings.jsonData.dbConnection || {};
|
||||
let dbConnectionOptions = jsonData.dbConnection || {};
|
||||
this.enableDirectDBConnection = dbConnectionOptions.enable;
|
||||
this.sqlDatasourceId = dbConnectionOptions.datasourceId;
|
||||
|
||||
@@ -134,6 +136,10 @@ class ZabbixAPIDatasource {
|
||||
} else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// IT services mode
|
||||
return this.queryITServiceData(target, timeRange, options);
|
||||
} else if (target.mode === c.MODE_TRIGGERS) {
|
||||
return this.queryTriggersData(target, timeRange);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -348,6 +354,24 @@ class ZabbixAPIDatasource {
|
||||
});
|
||||
}
|
||||
|
||||
queryTriggersData(target, timeRange) {
|
||||
let [timeFrom, timeTo] = timeRange;
|
||||
return this.zabbix.getHostsFromTarget(target)
|
||||
.then((results) => {
|
||||
let [hosts, apps] = results;
|
||||
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)
|
||||
.then((triggers) => {
|
||||
return responseHandler.handleTriggersResponse(triggers, timeRange);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connection to Zabbix API
|
||||
* @return {object} Connection status and Zabbix API version
|
||||
@@ -378,13 +402,13 @@ class ZabbixAPIDatasource {
|
||||
return {
|
||||
status: "error",
|
||||
title: error.message,
|
||||
message: error.data
|
||||
message: error.message
|
||||
};
|
||||
} else if (error.data && error.data.message) {
|
||||
return {
|
||||
status: "error",
|
||||
title: "Connection failed",
|
||||
message: error.data.message
|
||||
message: "Connection failed: " + error.data.message
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT || ctrl.target.mode == editorMode.TRIGGERS">
|
||||
<!-- Select Group -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Group</label>
|
||||
@@ -66,7 +66,7 @@
|
||||
</div>
|
||||
<!-- Select Host -->
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Host</label>
|
||||
<label class="gf-form-label query-keyword width-8">Host</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.target.host.filter"
|
||||
bs-typeahead="ctrl.getHostNames"
|
||||
@@ -85,7 +85,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT || ctrl.target.mode == editorMode.TRIGGERS">
|
||||
<!-- Select Application -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Application</label>
|
||||
@@ -103,8 +103,8 @@
|
||||
</div>
|
||||
|
||||
<!-- Select Item -->
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Item</label>
|
||||
<div class="gf-form" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<label class="gf-form-label query-keyword width-8">Item</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.target.item.filter"
|
||||
bs-typeahead="ctrl.getItemNames"
|
||||
@@ -117,9 +117,25 @@
|
||||
'zbx-regex': ctrl.isRegex(ctrl.target.item.filter)
|
||||
}">
|
||||
</div>
|
||||
|
||||
<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-16">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.minSeverity"
|
||||
ng-options="s.val as s.text for s in ctrl.triggerSeverity">
|
||||
</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()">
|
||||
</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}}
|
||||
@@ -130,7 +146,7 @@
|
||||
|
||||
<!-- Query options -->
|
||||
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
|
||||
<div class="gf-form offset-width-7">
|
||||
<div class="gf-form offset-width-7" ng-hide="ctrl.target.mode == editorMode.TRIGGERS">
|
||||
<gf-form-switch class="gf-form"
|
||||
label="Show disabled items"
|
||||
checked="ctrl.target.options.showDisabledItems"
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
"name": "Zabbix",
|
||||
"id": "alexanderzobnin-zabbix-datasource",
|
||||
|
||||
"includes": [
|
||||
{
|
||||
"type": "dashboard",
|
||||
"name": "Zabbix System Status",
|
||||
"path": "../dashboards/zabbix_system_status.json"
|
||||
},
|
||||
{
|
||||
"type": "dashboard",
|
||||
"name": "Zabbix Template Linux Server",
|
||||
"path": "../dashboards/template_linux_server.json"
|
||||
}
|
||||
],
|
||||
|
||||
"metrics": true,
|
||||
"annotations": true,
|
||||
|
||||
|
||||
@@ -25,14 +25,16 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
{value: 'num', text: 'Metrics', mode: c.MODE_METRICS},
|
||||
{value: 'text', text: 'Text', mode: c.MODE_TEXT},
|
||||
{value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE},
|
||||
{value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID}
|
||||
{value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID},
|
||||
{value: 'triggers', text: 'Triggers', mode: c.MODE_TRIGGERS}
|
||||
];
|
||||
|
||||
this.$scope.editorMode = {
|
||||
METRICS: c.MODE_METRICS,
|
||||
TEXT: c.MODE_TEXT,
|
||||
ITSERVICE: c.MODE_ITSERVICE,
|
||||
ITEMID: c.MODE_ITEMID
|
||||
ITEMID: c.MODE_ITEMID,
|
||||
TRIGGERS: c.MODE_TRIGGERS
|
||||
};
|
||||
|
||||
this.slaPropertyList = [
|
||||
@@ -43,6 +45,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
{name: "Down time", property: "downtimeTime"}
|
||||
];
|
||||
|
||||
this.triggerSeverity = c.TRIGGER_SEVERITY;
|
||||
|
||||
// Map functions for bs-typeahead
|
||||
this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');
|
||||
this.getHostNames = _.bind(this.getMetricNames, this, 'hostList', true);
|
||||
@@ -80,6 +84,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
'application': { 'filter': "" },
|
||||
'item': { 'filter': "" },
|
||||
'functions': [],
|
||||
'minSeverity': 3,
|
||||
'countTriggers': true,
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
}
|
||||
@@ -92,8 +98,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
});
|
||||
|
||||
if (target.mode === c.MODE_METRICS ||
|
||||
target.mode === c.MODE_TEXT) {
|
||||
|
||||
target.mode === c.MODE_TEXT ||
|
||||
target.mode === c.MODE_TRIGGERS) {
|
||||
this.initFilters();
|
||||
}
|
||||
else if (target.mode === c.MODE_ITSERVICE) {
|
||||
@@ -103,6 +109,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
};
|
||||
|
||||
this.init();
|
||||
this.queryOptionsText = this.renderQueryOptionsText();
|
||||
}
|
||||
|
||||
initFilters() {
|
||||
|
||||
@@ -26,3 +26,6 @@ This mode is suitable for rendering charts in grafana by passing itemids as url
|
||||
1. Save dashboard.
|
||||
1. Click to graph title and select _Share_ -> _Direct link rendered image_.
|
||||
1. Use this URL for graph png image and set `var-itemids` param to desired IDs. Note, for multiple IDs you should pass multiple params, like `&var-itemids=28276&var-itemids=28277`.
|
||||
|
||||
##### Triggers
|
||||
Active triggers count for selected hosts or table data like Zabbix _System status_ panel on the main dashboard.
|
||||
|
||||
@@ -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
|
||||
@@ -100,6 +102,45 @@ function handleSLAResponse(itservice, slaProperty, slaObject) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleTriggersResponse(triggers, timeRange) {
|
||||
if (_.isNumber(triggers)) {
|
||||
return {
|
||||
target: "triggers count",
|
||||
datapoints: [
|
||||
[triggers, timeRange[1] * 1000]
|
||||
]
|
||||
};
|
||||
} else {
|
||||
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 [
|
||||
@@ -141,7 +182,8 @@ export default {
|
||||
convertHistory: convertHistory,
|
||||
handleTrends: handleTrends,
|
||||
handleText: handleText,
|
||||
handleSLAResponse: handleSLAResponse
|
||||
handleSLAResponse: handleSLAResponse,
|
||||
handleTriggersResponse: handleTriggersResponse
|
||||
};
|
||||
|
||||
// Fix for backward compatibility with lodash 2.4
|
||||
|
||||
@@ -32,6 +32,7 @@ prunk.mock('app/plugins/sdk', {
|
||||
QueryCtrl: null
|
||||
});
|
||||
prunk.mock('app/core/utils/datemath', datemathMock);
|
||||
prunk.mock('app/core/table_model', {});
|
||||
prunk.mock('angular', angularMocks);
|
||||
prunk.mock('jquery', 'module not found');
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector)
|
||||
this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);
|
||||
this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);
|
||||
this.getAlerts = this.zabbixAPI.getAlerts.bind(this.zabbixAPI);
|
||||
this.getHostAlerts = this.zabbixAPI.getHostAlerts.bind(this.zabbixAPI);
|
||||
this.getAcknowledges = this.zabbixAPI.getAcknowledges.bind(this.zabbixAPI);
|
||||
this.getITService = this.zabbixAPI.getITService.bind(this.zabbixAPI);
|
||||
this.getSLA = this.zabbixAPI.getSLA.bind(this.zabbixAPI);
|
||||
@@ -59,6 +60,21 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector)
|
||||
return this.getItems(...filters, options);
|
||||
}
|
||||
|
||||
getHostsFromTarget(target) {
|
||||
let parts = ['group', 'host', 'application'];
|
||||
let filters = _.map(parts, p => target[p].filter);
|
||||
return Promise.all([
|
||||
this.getHosts(...filters),
|
||||
this.getApps(...filters),
|
||||
]).then((results) => {
|
||||
let [hosts, apps] = results;
|
||||
if (apps.appFilterEmpty) {
|
||||
apps = [];
|
||||
}
|
||||
return [hosts, apps];
|
||||
});
|
||||
}
|
||||
|
||||
getAllGroups() {
|
||||
return this.cachingProxy.getGroups();
|
||||
}
|
||||
|
||||
@@ -433,6 +433,38 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
|
||||
return this.request('trigger.get', params);
|
||||
}
|
||||
|
||||
getHostAlerts(hostids, applicationids, minSeverity, count, timeFrom, timeTo) {
|
||||
var params = {
|
||||
output: 'extend',
|
||||
hostids: hostids,
|
||||
min_severity: minSeverity,
|
||||
filter: { value: 1 },
|
||||
expandDescription: true,
|
||||
expandData: true,
|
||||
expandComment: true,
|
||||
monitored: true,
|
||||
skipDependent: true,
|
||||
selectLastEvent: 'extend',
|
||||
selectGroups: 'extend',
|
||||
selectHosts: ['host', 'name']
|
||||
};
|
||||
|
||||
if (count) {
|
||||
params.countOutput = true;
|
||||
}
|
||||
|
||||
if (applicationids && applicationids.length) {
|
||||
params.applicationids = applicationids;
|
||||
}
|
||||
|
||||
if (timeFrom || timeTo) {
|
||||
params.lastChangeSince = timeFrom;
|
||||
params.lastChangeTill = timeTo;
|
||||
}
|
||||
|
||||
return this.request('trigger.get', params);
|
||||
}
|
||||
}
|
||||
|
||||
return ZabbixAPI;
|
||||
|
||||
@@ -53,7 +53,7 @@ class ZabbixAPICoreService {
|
||||
|
||||
datasourceRequest(requestOptions) {
|
||||
return this.backendSrv.datasourceRequest(requestOptions)
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
if (!response.data) {
|
||||
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
|
||||
} else if (response.data.error) {
|
||||
@@ -64,9 +64,6 @@ class ZabbixAPICoreService {
|
||||
|
||||
// Success
|
||||
return response.data.result;
|
||||
})
|
||||
.catch(() => {
|
||||
return Promise.reject(new ZabbixAPIError({data: "Connection Error"}));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,14 +91,14 @@ class ZabbixAPICoreService {
|
||||
// Define zabbix API exception type
|
||||
export class ZabbixAPIError {
|
||||
constructor(error) {
|
||||
this.code = error.code;
|
||||
this.name = error.data;
|
||||
this.message = error.data;
|
||||
this.data = error.data;
|
||||
this.code = error.code || null;
|
||||
this.name = error.message || "";
|
||||
this.data = error.data || "";
|
||||
this.message = "Zabbix API Error: " + this.name + " " + this.data;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.name + ": " + this.message;
|
||||
return this.name + " " + this.data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user