iss #71 - Implemented text metrics query.
This commit is contained in:
@@ -94,7 +94,7 @@ function (angular, _, kbn) {
|
|||||||
// Create request for each target
|
// Create request for each target
|
||||||
var promises = _.map(options.targets, function(target) {
|
var promises = _.map(options.targets, function(target) {
|
||||||
|
|
||||||
if (!target.mode || target.mode === 0) {
|
if (target.mode !== 1) {
|
||||||
// Don't show undefined and hidden targets
|
// Don't show undefined and hidden targets
|
||||||
if (target.hide || !target.group || !target.host
|
if (target.hide || !target.group || !target.host
|
||||||
|| !target.application || !target.item) {
|
|| !target.application || !target.item) {
|
||||||
@@ -119,8 +119,12 @@ function (angular, _, kbn) {
|
|||||||
var delete_hostname_pattern = /(?:\[[\w\.]+]:\s)/g;
|
var delete_hostname_pattern = /(?:\[[\w\.]+]:\s)/g;
|
||||||
var itemnames = zabbixHelperSrv.splitMetrics(itemname.replace(delete_hostname_pattern, ''));
|
var itemnames = zabbixHelperSrv.splitMetrics(itemname.replace(delete_hostname_pattern, ''));
|
||||||
|
|
||||||
// Find items by item names and perform queries
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// Query numeric data
|
||||||
|
if (!target.mode) {
|
||||||
|
|
||||||
|
// Find items by item names and perform queries
|
||||||
return this.zabbixAPI.itemFindQuery(groups, hosts, apps)
|
return this.zabbixAPI.itemFindQuery(groups, hosts, apps)
|
||||||
.then(function (items) {
|
.then(function (items) {
|
||||||
|
|
||||||
@@ -201,6 +205,27 @@ function (angular, _, kbn) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query text data
|
||||||
|
else if (target.mode === 2) {
|
||||||
|
|
||||||
|
// Find items by item names and perform queries
|
||||||
|
return this.zabbixAPI.itemFindQuery(groups, hosts, apps, "text")
|
||||||
|
.then(function (items) {
|
||||||
|
items = _.filter(items, function (item) {
|
||||||
|
return _.contains(itemnames, zabbixHelperSrv.expandItemName(item));
|
||||||
|
});
|
||||||
|
return self.zabbixAPI.getHistory(items, from, to).then(function(history) {
|
||||||
|
return {
|
||||||
|
target: target.item.name,
|
||||||
|
datapoints: _.map(history, function (p) {
|
||||||
|
return [p.value, p.clock * 1000];
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// IT services mode
|
// IT services mode
|
||||||
else if (target.mode === 1) {
|
else if (target.mode === 1) {
|
||||||
// Don't show undefined and hidden targets
|
// Don't show undefined and hidden targets
|
||||||
@@ -211,11 +236,6 @@ function (angular, _, kbn) {
|
|||||||
.then(_.bind(zabbixHelperSrv.handleSLAResponse, zabbixHelperSrv, target.itservice, target.slaProperty));
|
.then(_.bind(zabbixHelperSrv.handleSLAResponse, zabbixHelperSrv, target.itservice, target.slaProperty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Text metrics mode
|
|
||||||
else if (target.mode === 2) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
return $q.all(_.flatten(promises)).then(function (results) {
|
return $q.all(_.flatten(promises)).then(function (results) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ define([
|
|||||||
|
|
||||||
$scope.init = function () {
|
$scope.init = function () {
|
||||||
$scope.targetLetters = targetLetters;
|
$scope.targetLetters = targetLetters;
|
||||||
if (!$scope.target.mode || $scope.target.mode === 0) {
|
if (!$scope.target.mode || $scope.target.mode !== 1) {
|
||||||
$scope.downsampleFunctionList = [
|
$scope.downsampleFunctionList = [
|
||||||
{name: "avg", value: "avg"},
|
{name: "avg", value: "avg"},
|
||||||
{name: "min", value: "min"},
|
{name: "min", value: "min"},
|
||||||
@@ -224,8 +224,9 @@ define([
|
|||||||
var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
|
var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
|
||||||
var apps = $scope.target.application ?
|
var apps = $scope.target.application ?
|
||||||
zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
|
zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
|
||||||
|
var itemtype = $scope.target.mode === 2 ? "text" : "numeric";
|
||||||
if (groups && hosts && apps) {
|
if (groups && hosts && apps) {
|
||||||
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
|
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps, itemtype).then(function (items) {
|
||||||
// Show only unique item names
|
// Show only unique item names
|
||||||
var uniq_items = _.map(_.uniq(items, function (item) {
|
var uniq_items = _.map(_.uniq(items, function (item) {
|
||||||
return zabbixHelperSrv.expandItemName(item);
|
return zabbixHelperSrv.expandItemName(item);
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ function (angular, _) {
|
|||||||
* @param {string|string[]} groupids ///////////////////////////
|
* @param {string|string[]} groupids ///////////////////////////
|
||||||
* @return {string|string[]} Array of Zabbix API item objects
|
* @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 = {
|
var params = {
|
||||||
output: ['name', 'key_', 'value_type', 'delay'],
|
output: ['name', 'key_', 'value_type', 'delay'],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
@@ -302,13 +302,17 @@ function (angular, _) {
|
|||||||
webitems: true,
|
webitems: true,
|
||||||
// Return only numeric items
|
// Return only numeric items
|
||||||
filter: {
|
filter: {
|
||||||
value_type: [0,3]
|
value_type: [0, 3]
|
||||||
},
|
},
|
||||||
// Return only enabled items
|
// Return only enabled items
|
||||||
monitored: true,
|
monitored: true,
|
||||||
searchByAny: true
|
searchByAny: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (itemtype === "text") {
|
||||||
|
params.filter.value_type = [1, 2, 4];
|
||||||
|
}
|
||||||
|
|
||||||
// Filter by hosts or by groups
|
// Filter by hosts or by groups
|
||||||
if (hostids) {
|
if (hostids) {
|
||||||
params.hostids = hostids;
|
params.hostids = hostids;
|
||||||
@@ -409,7 +413,7 @@ function (angular, _) {
|
|||||||
* @param {string or array} apps
|
* @param {string or array} apps
|
||||||
* @return {array} array of Zabbix API item objects
|
* @return {array} array of Zabbix API item objects
|
||||||
*/
|
*/
|
||||||
p.itemFindQuery = function(groups, hosts, apps) {
|
p.itemFindQuery = function(groups, hosts, apps, itemtype) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
// Get hostids from names
|
// Get hostids from names
|
||||||
@@ -447,7 +451,7 @@ function (angular, _) {
|
|||||||
}), 'applicationid');
|
}), 'applicationid');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.performItemSuggestQuery(hostids, applicationids, groupids);
|
return self.performItemSuggestQuery(hostids, applicationids, groupids, itemtype);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user