\ No newline at end of file
diff --git a/zabbix/queryCtrl.js b/zabbix/queryCtrl.js
index 0a02a5893..92e676a3f 100644
--- a/zabbix/queryCtrl.js
+++ b/zabbix/queryCtrl.js
@@ -1,212 +1,271 @@
define([
- 'angular',
- 'lodash',
- './helperFunctions'
-],
-function (angular, _) {
- 'use strict';
-
- var module = angular.module('grafana.controllers');
- var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
-
- module.controller('ZabbixAPIQueryCtrl', function($scope, $sce, templateSrv, zabbixHelperSrv) {
-
- $scope.init = function() {
- $scope.targetLetters = targetLetters;
- $scope.metric = {
- hostGroupList: [],
- hostList: [{name: '*', visible_name: 'All'}],
- applicationList: [{name: '*', visible_name: 'All'}],
- itemList: [{name: 'All'}]
- };
+ 'angular',
+ 'lodash',
+ './helperFunctions'
+ ],
+ function (angular, _) {
+ 'use strict';
- // Update host group, host, application and item lists
- $scope.updateGroupList();
- $scope.updateHostList();
- $scope.updateAppList();
- $scope.updateItemList();
+ var module = angular.module('grafana.controllers');
+ var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- setItemAlias();
+ module.controller('ZabbixAPIQueryCtrl', function ($scope, $sce, templateSrv, zabbixHelperSrv) {
- $scope.target.errors = validateTarget($scope.target);
- };
+ $scope.init = function () {
+ $scope.targetLetters = targetLetters;
+ if (!$scope.target.mode || $scope.target.mode !== 1) {
+ $scope.downsampleFunctionList = [
+ {name: "avg", value: "avg"},
+ {name: "min", value: "min"},
+ {name: "max", value: "max"}
+ ];
- /**
- * Take alias from item name by default
- */
- function setItemAlias() {
- if (!$scope.target.alias && $scope.target.item) {
- $scope.target.alias = $scope.target.item.name;
- }
- }
-
- $scope.targetBlur = function() {
- setItemAlias();
- $scope.target.errors = validateTarget($scope.target);
- if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
- $scope.oldTarget = angular.copy($scope.target);
- $scope.get_data();
- }
- };
-
- /**
- * Call when host group selected
- */
- $scope.selectHostGroup = function() {
- $scope.updateHostList();
- $scope.updateAppList();
- $scope.updateItemList();
-
- $scope.target.errors = validateTarget($scope.target);
- if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
- $scope.oldTarget = angular.copy($scope.target);
- $scope.get_data();
- }
- };
-
- /**
- * Call when host selected
- */
- $scope.selectHost = function() {
- $scope.updateAppList();
- $scope.updateItemList();
-
- $scope.target.errors = validateTarget($scope.target);
- if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
- $scope.oldTarget = angular.copy($scope.target);
- $scope.get_data();
- }
- };
-
- /**
- * Call when application selected
- */
- $scope.selectApplication = function() {
- $scope.updateItemList();
-
- $scope.target.errors = validateTarget($scope.target);
- if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
- $scope.oldTarget = angular.copy($scope.target);
- $scope.get_data();
- }
- };
-
- /**
- * Call when item selected
- */
- $scope.selectItem = function() {
- setItemAlias();
- $scope.target.errors = validateTarget($scope.target);
- if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
- $scope.oldTarget = angular.copy($scope.target);
- $scope.get_data();
+ // Set avg by default
+ if (!$scope.target.downsampleFunction) {
+ $scope.target.downsampleFunction = $scope.downsampleFunctionList[0];
+ }
+ if (!$scope.metric) {
+ $scope.metric = {
+ hostGroupList: [],
+ hostList: [{name: '*', visible_name: 'All'}],
+ applicationList: [{name: '*', visible_name: 'All'}],
+ itemList: [{name: 'All'}]
+ };
+ }
+
+ // Update host group, host, application and item lists
+ $scope.updateGroupList();
+ $scope.updateHostList();
+ $scope.updateAppList();
+ $scope.updateItemList();
+
+ setItemAlias();
+ }
+ else if ($scope.target.mode === 1) {
+ $scope.slaPropertyList = [
+ {name: "Status", property: "status"},
+ {name: "SLA", property: "sla"},
+ {name: "OK time", property: "okTime"},
+ {name: "Problem time", property: "problemTime"},
+ {name: "Down time", property: "downtimeTime"}
+ ];
+ $scope.itserviceList = [{name: "test"}];
+ $scope.updateITServiceList();
+ }
+
+ $scope.target.errors = validateTarget($scope.target);
+ };
+
+ /**
+ * Switch query editor to specified mode.
+ * Modes:
+ * 0 - items
+ * 1 - IT services
+ */
+ $scope.switchEditorMode = function (mode) {
+ $scope.target.mode = mode;
+ $scope.init();
+ };
+
+ /**
+ * Take alias from item name by default
+ */
+ function setItemAlias() {
+ if (!$scope.target.alias && $scope.target.item) {
+ $scope.target.alias = $scope.target.item.name;
+ }
}
- };
-
- $scope.duplicate = function() {
- var clone = angular.copy($scope.target);
- $scope.panel.targets.push(clone);
- };
-
- $scope.moveMetricQuery = function(fromIndex, toIndex) {
- _.move($scope.panel.targets, fromIndex, toIndex);
- };
-
- //////////////////////////////
- // SUGGESTION QUERIES
- //////////////////////////////
-
- /**
- * Update list of host groups
- */
- $scope.updateGroupList = function() {
- $scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
- $scope.metric.groupList = [{name: '*', visible_name: 'All'}];
- addTemplatedVariables($scope.metric.groupList);
- $scope.metric.groupList = $scope.metric.groupList.concat(groups);
- });
- };
-
- /**
- * Update list of hosts
- */
- $scope.updateHostList = function() {
- var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
- if (groups) {
- $scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) {
- $scope.metric.hostList = [{name: '*', visible_name: 'All'}];
- addTemplatedVariables($scope.metric.hostList);
- $scope.metric.hostList = $scope.metric.hostList.concat(hosts);
+
+ $scope.targetBlur = function () {
+ setItemAlias();
+ $scope.target.errors = validateTarget($scope.target);
+ if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
+ $scope.oldTarget = angular.copy($scope.target);
+ $scope.get_data();
+ }
+ };
+
+ /**
+ * Call when IT service is selected.
+ */
+ $scope.selectITService = function () {
+ $scope.target.errors = validateTarget($scope.target);
+ if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
+ $scope.oldTarget = angular.copy($scope.target);
+ $scope.get_data();
+ }
+ };
+
+ /**
+ * Call when host group selected
+ */
+ $scope.selectHostGroup = function () {
+ $scope.updateHostList();
+ $scope.updateAppList();
+ $scope.updateItemList();
+
+ $scope.target.errors = validateTarget($scope.target);
+ if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
+ $scope.oldTarget = angular.copy($scope.target);
+ $scope.get_data();
+ }
+ };
+
+ /**
+ * Call when host selected
+ */
+ $scope.selectHost = function () {
+ $scope.updateAppList();
+ $scope.updateItemList();
+
+ $scope.target.errors = validateTarget($scope.target);
+ if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
+ $scope.oldTarget = angular.copy($scope.target);
+ $scope.get_data();
+ }
+ };
+
+ /**
+ * Call when application selected
+ */
+ $scope.selectApplication = function () {
+ $scope.updateItemList();
+
+ $scope.target.errors = validateTarget($scope.target);
+ if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
+ $scope.oldTarget = angular.copy($scope.target);
+ $scope.get_data();
+ }
+ };
+
+ /**
+ * Call when item selected
+ */
+ $scope.selectItem = function () {
+ setItemAlias();
+ $scope.target.errors = validateTarget($scope.target);
+ if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
+ $scope.oldTarget = angular.copy($scope.target);
+ $scope.get_data();
+ }
+ };
+
+ $scope.duplicate = function () {
+ var clone = angular.copy($scope.target);
+ $scope.panel.targets.push(clone);
+ };
+
+ $scope.moveMetricQuery = function (fromIndex, toIndex) {
+ _.move($scope.panel.targets, fromIndex, toIndex);
+ };
+
+ //////////////////////////////
+ // SUGGESTION QUERIES
+ //////////////////////////////
+
+ /**
+ * Update list of IT services
+ */
+ $scope.updateITServiceList = function () {
+ $scope.datasource.zabbixAPI.getITService().then(function (iteservices) {
+ $scope.itserviceList = [];
+ $scope.itserviceList = $scope.itserviceList.concat(iteservices);
});
- }
- };
-
- /**
- * Update list of host applications
- */
- $scope.updateAppList = function() {
- var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
- var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
- if (groups && hosts) {
- $scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
- apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
- return {name: appname};
- });
- $scope.metric.applicationList = [{name: '*', visible_name: 'All'}];
- addTemplatedVariables($scope.metric.applicationList);
- $scope.metric.applicationList = $scope.metric.applicationList.concat(apps);
+ };
+
+ /**
+ * Update list of host groups
+ */
+ $scope.updateGroupList = function () {
+ $scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
+ $scope.metric.groupList = [{name: '*', visible_name: 'All'}];
+ addTemplatedVariables($scope.metric.groupList);
+ $scope.metric.groupList = $scope.metric.groupList.concat(groups);
});
- }
- };
-
- /**
- * Update list of items
- */
- $scope.updateItemList = function() {
- var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
- var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
- var apps = $scope.target.application ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
- if (groups && hosts && apps) {
- $scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
- // Show only unique item names
- var uniq_items = _.map(_.uniq(items, function (item) {
- return zabbixHelperSrv.expandItemName(item);
- }), function (item) {
- return {name: zabbixHelperSrv.expandItemName(item)};
+ };
+
+ /**
+ * Update list of hosts
+ */
+ $scope.updateHostList = function () {
+ var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
+ if (groups) {
+ $scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) {
+ $scope.metric.hostList = [{name: '*', visible_name: 'All'}];
+ addTemplatedVariables($scope.metric.hostList);
+ $scope.metric.hostList = $scope.metric.hostList.concat(hosts);
+ });
+ }
+ };
+
+ /**
+ * Update list of host applications
+ */
+ $scope.updateAppList = function () {
+ var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
+ var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
+ if (groups && hosts) {
+ $scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
+ apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
+ return {name: appname};
+ });
+ $scope.metric.applicationList = [{name: '*', visible_name: 'All'}];
+ addTemplatedVariables($scope.metric.applicationList);
+ $scope.metric.applicationList = $scope.metric.applicationList.concat(apps);
+ });
+ }
+ };
+
+ /**
+ * Update list of items
+ */
+ $scope.updateItemList = function () {
+ var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
+ var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
+ var apps = $scope.target.application ?
+ zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
+ var itemtype = $scope.target.mode === 2 ? "text" : "numeric";
+ if (groups && hosts && apps) {
+ $scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps, itemtype).then(function (items) {
+ // Show only unique item names
+ var uniq_items = _.map(_.uniq(items, function (item) {
+ return zabbixHelperSrv.expandItemName(item);
+ }), function (item) {
+ return {name: zabbixHelperSrv.expandItemName(item)};
+ });
+ $scope.metric.itemList = [{name: 'All'}];
+ addTemplatedVariables($scope.metric.itemList);
+ $scope.metric.itemList = $scope.metric.itemList.concat(uniq_items);
+ });
+ }
+ };
+
+ /**
+ * Add templated variables to list of available metrics
+ *
+ * @param {Array} metricList List of metrics which variables add to
+ */
+ function addTemplatedVariables(metricList) {
+ _.each(templateSrv.variables, function (variable) {
+ metricList.push({
+ name: '$' + variable.name,
+ templated: true
});
- $scope.metric.itemList = [{name: 'All'}];
- addTemplatedVariables($scope.metric.itemList);
- $scope.metric.itemList = $scope.metric.itemList.concat(uniq_items);
});
}
- };
-
- /**
- * Add templated variables to list of available metrics
- *
- * @param {Array} metricList List of metrics which variables add to
- */
- function addTemplatedVariables(metricList) {
- _.each(templateSrv.variables, function(variable) {
- metricList.push({
- name: '$' + variable.name,
- templated: true
- });
- });
- }
- //////////////////////////////
- // VALIDATION
- //////////////////////////////
+ //////////////////////////////
+ // VALIDATION
+ //////////////////////////////
- function validateTarget(target) {
- var errs = {};
- if (!target) {
- errs = 'Not defined';
+ function validateTarget(target) {
+ var errs = {};
+ if (!target) {
+ errs = 'Not defined';
+ }
+ return errs;
}
- return errs;
- }
- });
+ });
-});
+ });
diff --git a/zabbix/zabbixAPIWrapper.js b/zabbix/zabbixAPIWrapper.js
index 45a14d1ef..8a89ccc02 100644
--- a/zabbix/zabbixAPIWrapper.js
+++ b/zabbix/zabbixAPIWrapper.js
@@ -1,7 +1,7 @@
define([
'angular',
- 'lodash',
-],
+ 'lodash'
+ ],
function (angular, _) {
'use strict';
@@ -94,7 +94,7 @@ function (angular, _) {
},
auth: null,
id: 1
- },
+ }
};
if (this.basicAuth || this.withCredentials) {
@@ -245,8 +245,8 @@ function (angular, _) {
/**
* Get the list of hosts
*
- * @param {array} groupids
- * @return {array} array of Zabbix host objects
+ * @param {string|string[]} groupids
+ * @return {Object} array of Zabbix host objects
*/
p.performHostSuggestQuery = function(groupids) {
var params = {
@@ -269,7 +269,7 @@ function (angular, _) {
*
* @param {array} hostids
* @param {array} groupids
- * @return {array} array of Zabbix application objects
+ * @return {Object} array of Zabbix application objects
*/
p.performAppSuggestQuery = function(hostids, /* optional */ groupids) {
var params = {
@@ -289,12 +289,12 @@ function (angular, _) {
/**
* Items request
*
- * @param {string or Array} hostids ///////////////////////////
- * @param {string or Array} applicationids // Zabbix API parameters //
- * @param {string or Array} groupids ///////////////////////////
- * @return {string or Array} Array of Zabbix API item objects
+ * @param {string|string[]} hostids ///////////////////////////
+ * @param {string|string[]} applicationids // Zabbix API parameters //
+ * @param {string|string[]} groupids ///////////////////////////
+ * @return {string|string[]} Array of Zabbix API item objects
*/
- p.performItemSuggestQuery = function(hostids, applicationids, /* optional */ groupids) {
+ p.performItemSuggestQuery = function(hostids, applicationids, groupids, itemtype) {
var params = {
output: ['name', 'key_', 'value_type', 'delay'],
sortfield: 'name',
@@ -302,13 +302,17 @@ function (angular, _) {
webitems: true,
// Return only numeric items
filter: {
- value_type: [0,3]
+ value_type: [0, 3]
},
// Return only enabled items
monitored: true,
searchByAny: true
};
+ if (itemtype === "text") {
+ params.filter.value_type = [1, 2, 4];
+ }
+
// Filter by hosts or by groups
if (hostids) {
params.hostids = hostids;
@@ -409,7 +413,7 @@ function (angular, _) {
* @param {string or array} apps
* @return {array} array of Zabbix API item objects
*/
- p.itemFindQuery = function(groups, hosts, apps) {
+ p.itemFindQuery = function(groups, hosts, apps, itemtype) {
var promises = [];
// Get hostids from names
@@ -447,7 +451,7 @@ function (angular, _) {
}), 'applicationid');
}
- return self.performItemSuggestQuery(hostids, applicationids, groupids);
+ return self.performItemSuggestQuery(hostids, applicationids, groupids, itemtype);
});
};
@@ -508,6 +512,25 @@ function (angular, _) {
});
};
+ p.getITService = function(/* optional */ serviceids) {
+ var params = {
+ output: 'extend',
+ serviceids: serviceids
+ };
+ return this.performZabbixAPIRequest('service.get', params);
+ };
+
+ p.getSLA = function(serviceids, from, to) {
+ var params = {
+ serviceids: serviceids,
+ intervals: [{
+ from: from,
+ to: to
+ }]
+ };
+ return this.performZabbixAPIRequest('service.getsla', params);
+ };
+
return ZabbixAPI;
});