iss #71 - Implemented text metrics query.

This commit is contained in:
Alexander Zobnin
2015-08-18 23:24:15 +03:00
parent 9ec32b26e8
commit 1f6ecd5aed
3 changed files with 105 additions and 80 deletions

View File

@@ -94,7 +94,7 @@ function (angular, _, kbn) {
// Create request for each 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
if (target.hide || !target.group || !target.host
|| !target.application || !target.item) {
@@ -119,8 +119,12 @@ function (angular, _, kbn) {
var delete_hostname_pattern = /(?:\[[\w\.]+]:\s)/g;
var itemnames = zabbixHelperSrv.splitMetrics(itemname.replace(delete_hostname_pattern, ''));
// Find items by item names and perform queries
var self = this;
// Query numeric data
if (!target.mode) {
// Find items by item names and perform queries
return this.zabbixAPI.itemFindQuery(groups, hosts, apps)
.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
else if (target.mode === 1) {
// Don't show undefined and hidden targets
@@ -211,11 +236,6 @@ function (angular, _, kbn) {
.then(_.bind(zabbixHelperSrv.handleSLAResponse, zabbixHelperSrv, target.itservice, target.slaProperty));
}
}
// Text metrics mode
else if (target.mode === 2) {
return [];
}
}, this);
return $q.all(_.flatten(promises)).then(function (results) {

View File

@@ -13,7 +13,7 @@ define([
$scope.init = function () {
$scope.targetLetters = targetLetters;
if (!$scope.target.mode || $scope.target.mode === 0) {
if (!$scope.target.mode || $scope.target.mode !== 1) {
$scope.downsampleFunctionList = [
{name: "avg", value: "avg"},
{name: "min", value: "min"},
@@ -224,8 +224,9 @@ define([
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).then(function (items) {
$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);

View File

@@ -294,7 +294,7 @@ function (angular, _) {
* @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',
@@ -309,6 +309,10 @@ function (angular, _) {
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);
});
};