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:
akotynski
2017-10-23 14:26:46 +02:00
48 changed files with 1835 additions and 649 deletions

View File

@@ -1,20 +1,25 @@
{
"id": null,
"title": "Template Linux Server",
"originalTitle": "Template Linux Server",
"tags": [
"zabbix",
"example"
"__inputs": [
{
"name": "DS_NAME",
"type": "datasource",
"pluginId": "alexanderzobnin-zabbix-datasource"
}
],
"style": "dark",
"timezone": "browser",
"title": "Zabbix Template Linux Server",
"revision": 1,
"annotations": {
"list": []
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"sharedCrosshair": false,
"id": null,
"links": [],
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
@@ -24,16 +29,13 @@
"CPU user time": "#EAB839"
},
"bars": false,
"datasource": "$datasource",
"dashLength": 10,
"dashes": false,
"datasource": "${DS_NAME}",
"editable": true,
"error": false,
"fill": 3,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"grid": {},
"id": 1,
"legend": {
"avg": false,
@@ -53,6 +55,7 @@
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": true,
"steppedLine": false,
@@ -61,6 +64,7 @@
"application": {
"filter": "CPU"
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
@@ -71,21 +75,31 @@
"item": {
"filter": "/CPU/"
},
"minSeverity": 3,
"mode": 0,
"options": {
"showDisabledItems": false
},
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "CPU",
"tooltip": {
"msResolution": false,
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"show": true
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
@@ -109,16 +123,13 @@
"Processor load (1 min average per core)": "#1F78C1"
},
"bars": false,
"datasource": "$datasource",
"dashLength": 10,
"dashes": false,
"datasource": "${DS_NAME}",
"editable": true,
"error": false,
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"grid": {},
"id": 2,
"legend": {
"avg": false,
@@ -138,6 +149,7 @@
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
@@ -146,6 +158,7 @@
"application": {
"filter": "CPU"
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
@@ -156,21 +169,31 @@
"item": {
"filter": "Processor load (15 min average per core)"
},
"minSeverity": 3,
"mode": 0,
"options": {
"showDisabledItems": false
},
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "System load",
"tooltip": {
"msResolution": false,
"shared": true,
"sort": 0,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
@@ -190,27 +213,27 @@
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": true,
"title": "CPU"
"title": "CPU",
"titleSize": "h6"
},
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"aliasColors": {},
"bars": false,
"datasource": "$datasource",
"dashLength": 10,
"dashes": false,
"datasource": "${DS_NAME}",
"editable": true,
"error": false,
"fill": 3,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"grid": {},
"id": 3,
"legend": {
"alignAsTable": false,
@@ -233,20 +256,14 @@
"points": false,
"renderer": "flot",
"repeat": "netif",
"scopedVars": {
"netif": {
"text": "eth0",
"value": "eth0",
"selected": false
}
},
"seriesOverrides": [
{
"alias": "/Incoming/",
"transform": "negative-Y"
}
],
"span": 6,
"spaceLength": 10,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
@@ -254,6 +271,7 @@
"application": {
"filter": ""
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
@@ -264,21 +282,31 @@
"item": {
"filter": "/$netif/"
},
"minSeverity": 3,
"mode": 0,
"options": {
"showDisabledItems": false
},
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Network traffic on $netif",
"tooltip": {
"msResolution": false,
"shared": true,
"sort": 0,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
@@ -296,113 +324,96 @@
"show": true
}
]
},
{
"aliasColors": {},
"bars": false,
"datasource": "$datasource",
"editable": true,
"error": false,
"fill": 3,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 4,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 2,
"links": [],
"minSpan": 4,
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeat": null,
"scopedVars": {
"netif": {
"text": "eth1",
"value": "eth1",
"selected": false
}
},
"seriesOverrides": [
{
"alias": "/Incoming/",
"transform": "negative-Y"
}
],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"application": {
"filter": ""
},
"functions": [],
"group": {
"filter": "$group"
},
"host": {
"filter": "$host"
},
"item": {
"filter": "/$netif/"
},
"mode": 0,
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Network traffic on $netif",
"tooltip": {
"msResolution": false,
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
},
"yaxes": [
{
"format": "bps",
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"repeatIteration": 1460635040618,
"repeatPanelId": 3
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": true,
"title": "Network"
"title": "Network",
"titleSize": "h6"
}
],
"schemaVersion": 14,
"style": "dark",
"tags": [
"zabbix",
"example"
],
"templating": {
"list": [
{
"allFormat": "regex values",
"allValue": null,
"current": {},
"datasource": "${DS_NAME}",
"hide": 0,
"includeAll": false,
"label": "Group",
"multi": false,
"multiFormat": "glob",
"name": "group",
"options": [],
"query": "*",
"refresh": 1,
"refresh_on_load": false,
"regex": "",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allFormat": "glob",
"allValue": null,
"current": {},
"datasource": "${DS_NAME}",
"hide": 0,
"includeAll": false,
"label": "Host",
"multi": false,
"multiFormat": "glob",
"name": "host",
"options": [],
"query": "$group.*",
"refresh": 1,
"refresh_on_load": false,
"regex": "",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allFormat": "regex values",
"allValue": null,
"current": {},
"datasource": "${DS_NAME}",
"hide": 0,
"hideLabel": false,
"includeAll": true,
"label": "Network interface",
"multi": true,
"multiFormat": "regex values",
"name": "netif",
"options": [],
"query": "*.$host.Network interfaces.*",
"refresh": 1,
"refresh_on_load": false,
"regex": "/(?:Incoming|Outgoing) network traffic on (.*)/",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-3h",
"to": "now"
@@ -432,77 +443,5 @@
"30d"
]
},
"templating": {
"list": [
{
"current": {},
"hide": 0,
"label": "Zabbix Data Source",
"name": "datasource",
"options": [],
"query": "alexanderzobnin-zabbix-datasource",
"refresh": 1,
"regex": "",
"type": "datasource"
},
{
"allFormat": "regex values",
"current": {},
"datasource": "$datasource",
"hide": 0,
"includeAll": false,
"label": "Group",
"multi": false,
"multiFormat": "glob",
"name": "group",
"options": [],
"query": "*",
"refresh": 1,
"refresh_on_load": false,
"regex": "",
"type": "query"
},
{
"allFormat": "glob",
"current": {},
"datasource": "$datasource",
"hide": 0,
"includeAll": false,
"label": "Host",
"multi": false,
"multiFormat": "glob",
"name": "host",
"options": [],
"query": "$group.*",
"refresh": 1,
"refresh_on_load": false,
"regex": "",
"type": "query"
},
{
"allFormat": "regex values",
"current": {},
"datasource": "$datasource",
"hide": 0,
"hideLabel": false,
"includeAll": true,
"label": "Network interface",
"multi": true,
"multiFormat": "regex values",
"name": "netif",
"options": [],
"query": "*.$host.Network interfaces.*",
"refresh": 1,
"refresh_on_load": false,
"regex": "/(?:Incoming|Outgoing) network traffic on (.*)/",
"type": "query"
}
]
},
"annotations": {
"list": []
},
"schemaVersion": 12,
"version": 9,
"links": []
"timezone": "browser"
}

View File

@@ -0,0 +1,371 @@
{
"__inputs": [
{
"name": "DS_NAME",
"type": "datasource",
"pluginId": "alexanderzobnin-zabbix-datasource"
}
],
"title": "Zabbix System Status",
"revision": "1.0",
"annotations": {
"list": []
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"id": null,
"links": [],
"rows": [
{
"collapse": false,
"height": 250,
"panels": [
{
"columns": [],
"datasource": "${DS_NAME}",
"fontSize": "100%",
"id": 9,
"links": [],
"pageSize": null,
"scroll": true,
"showHeader": true,
"sort": {
"col": 0,
"desc": true
},
"span": 12,
"styles": [
{
"alias": "Time",
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"pattern": "Time",
"type": "date"
},
{
"alias": "",
"colorMode": "cell",
"colors": [
"rgba(45, 172, 121, 0.97)",
"rgba(45, 172, 121, 0.97)",
"#58140c"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Disaster",
"thresholds": [
"0",
"1"
],
"type": "number",
"unit": "none"
},
{
"alias": "",
"colorMode": "cell",
"colors": [
"#99440a",
"rgba(45, 172, 121, 0.97)",
"#99440a"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "High",
"thresholds": [
"0",
"1"
],
"type": "number",
"unit": "short"
},
{
"alias": "",
"colorMode": "cell",
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(45, 172, 121, 0.97)",
"#c15c17"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Average",
"thresholds": [
"0",
"1"
],
"type": "number",
"unit": "short"
},
{
"alias": "",
"colorMode": "cell",
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(45, 172, 121, 0.97)",
"#cca300"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Warning",
"thresholds": [
"0",
"1"
],
"type": "number",
"unit": "short"
},
{
"alias": "",
"colorMode": "cell",
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(45, 172, 121, 0.97)",
"#64b0c8"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Information",
"thresholds": [
"0",
"1"
],
"type": "number",
"unit": "short"
},
{
"alias": "",
"colorMode": "cell",
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(45, 172, 121, 0.97)",
"rgb(176, 176, 176)"
],
"dateFormat": "YYYY-MM-DD HH:mm:ss",
"decimals": 0,
"pattern": "Not classified",
"thresholds": [
"0",
"1"
],
"type": "number",
"unit": "short"
},
{
"alias": "",
"colorMode": null,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"decimals": 0,
"pattern": "/.*/",
"thresholds": [],
"type": "number",
"unit": "none"
}
],
"targets": [
{
"application": {
"filter": ""
},
"countTriggers": false,
"functions": [],
"group": {
"filter": "/.*/"
},
"host": {
"filter": "/.*/"
},
"item": {
"filter": ""
},
"minSeverity": 0,
"mode": 4,
"options": {
"countTriggers": false,
"showDisabledItems": false
},
"refId": "A",
"target": ""
}
],
"title": "System status",
"transform": "table",
"type": "table"
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"
},
{
"collapse": false,
"height": "150px",
"panels": [
{
"cacheTimeout": null,
"colorBackground": true,
"colorValue": false,
"colors": [
"rgba(50, 172, 45, 0.97)",
"rgba(16, 154, 113, 0.97)",
"#890f02"
],
"datasource": "${DS_NAME}",
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"id": 1,
"interval": null,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"minSpan": 2,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"repeat": "group",
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"tableColumn": "",
"targets": [
{
"application": {
"filter": ""
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
},
"host": {
"filter": "/.*/"
},
"item": {
"filter": ""
},
"minSeverity": 3,
"mode": 4,
"options": {
"showDisabledItems": false
},
"refId": "A",
"target": ""
}
],
"thresholds": "0,1",
"title": "$group",
"type": "singlestat",
"valueFontSize": "120%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"
}
],
"schemaVersion": 14,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"allValue": null,
"current": {},
"datasource": "${DS_NAME}",
"hide": 0,
"includeAll": true,
"label": null,
"multi": true,
"name": "group",
"options": [],
"query": "*",
"refresh": 1,
"regex": "",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": ""
}

View File

@@ -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'}
];

View File

@@ -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 {

View File

@@ -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"

View File

@@ -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,

View File

@@ -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() {

View File

@@ -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.

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
@@ -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

View File

@@ -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');

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -26,8 +26,8 @@
{"name": "Metric Editor", "path": "img/screenshot-metric_editor.png"},
{"name": "Triggers", "path": "img/screenshot-triggers.png"}
],
"version": "3.6.1",
"updated": "2017-07-26"
"version": "3.7.0",
"updated": "2017-10-22"
},
"includes": [
@@ -45,12 +45,6 @@
"path": "dashboards/zabbix_server_dashboard.json",
"addToNav": true,
"defaultNav": true
},
{
"type": "dashboard",
"name": "Template Linux Server",
"path": "dashboards/template_linux_server.json",
"addToNav": true
}
],