Merge branch 'query-editor' into grafana-3.0
This commit is contained in:
@@ -191,34 +191,33 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
|||||||
|
|
||||||
// Query text data
|
// Query text data
|
||||||
else if (target.mode === 2) {
|
else if (target.mode === 2) {
|
||||||
|
return self.queryProcessor.build(groupFilter, hostFilter, appFilter, itemFilter)
|
||||||
// Find items by item names and perform queries
|
|
||||||
return this.zabbixAPI.itemFindQuery(groups, hosts, apps, "text")
|
|
||||||
.then(function(items) {
|
.then(function(items) {
|
||||||
items = _.filter(items, function (item) {
|
var deferred = $q.defer();
|
||||||
return _.contains(itemnames, zabbixHelperSrv.expandItemName(item));
|
if (items.length) {
|
||||||
});
|
self.zabbixAPI.getLastValue(items[0].itemid).then(function(lastvalue) {
|
||||||
return self.zabbixAPI.getHistory(items, from, to).then(function(history) {
|
|
||||||
return {
|
|
||||||
target: target.item.name,
|
|
||||||
datapoints: _.map(history, function (p) {
|
|
||||||
var value = p.value;
|
|
||||||
if (target.textFilter) {
|
if (target.textFilter) {
|
||||||
var text_extract_pattern = new RegExp(templateSrv.replace(target.textFilter, options.scopedVars));
|
var text_extract_pattern = new RegExp(templateSrv.replace(target.textFilter, options.scopedVars));
|
||||||
//var text_extract_pattern = new RegExp(target.textFilter);
|
var result = text_extract_pattern.exec(lastvalue);
|
||||||
var result = text_extract_pattern.exec(value);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
if (target.useCaptureGroups) {
|
if (target.useCaptureGroups) {
|
||||||
value = result[1];
|
result = result[1];
|
||||||
} else {
|
} else {
|
||||||
value = result[0];
|
result = result[0];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
deferred.resolve(result);
|
||||||
} else {
|
} else {
|
||||||
value = null;
|
deferred.resolve(lastvalue);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
deferred.resolve(null);
|
||||||
}
|
}
|
||||||
return [value, p.clock * 1000];
|
return deferred.promise.then(function(text) {
|
||||||
})
|
return {
|
||||||
|
target: target.item.name,
|
||||||
|
datapoints: [[text, to * 1000]]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -294,8 +293,8 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
|||||||
|
|
||||||
// Get items
|
// Get items
|
||||||
if (parts.length === 4) {
|
if (parts.length === 4) {
|
||||||
//var items = this.queryProcessor.filterItems(template.host, template.app, true);
|
return this.queryProcessor.filterItems(template.group, template.host,
|
||||||
return this.queryProcessor.filterItems(template.group, template.host, template.app, true)
|
template.app, 'all', true)
|
||||||
.then(function(items) {
|
.then(function(items) {
|
||||||
return _.map(items, formatMetric);
|
return _.map(items, formatMetric);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<i class="fa fa-bars"></i>
|
<i class="fa fa-bars"></i>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu pull-right" role="menu">
|
<ul class="dropdown-menu pull-right" role="menu">
|
||||||
|
|
||||||
<!-- Switch editor mode -->
|
<!-- Switch editor mode -->
|
||||||
<li role="menuitem" ng-show="target.mode">
|
<li role="menuitem" ng-show="target.mode">
|
||||||
<a class="pointer" tabindex="1"
|
<a class="pointer" tabindex="1"
|
||||||
@@ -75,15 +76,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul class="tight-form-list" role="menu" ng-hide="target.mode == 1">
|
<ul class="tight-form-list" role="menu" ng-hide="target.mode == 1">
|
||||||
<!-- Alias -->
|
|
||||||
<!-- <li>
|
|
||||||
<input type="text"
|
|
||||||
class="tight-form-input input-medium"
|
|
||||||
ng-model="target.alias"
|
|
||||||
spellcheck='false'
|
|
||||||
placeholder="Alias"
|
|
||||||
ng-blur="targetBlur()">
|
|
||||||
</li> -->
|
|
||||||
|
|
||||||
<!-- Select Host Group -->
|
<!-- Select Host Group -->
|
||||||
<li class="tight-form-item input-small" style="width: 5em">Group</li>
|
<li class="tight-form-item input-small" style="width: 5em">Group</li>
|
||||||
@@ -147,7 +139,7 @@
|
|||||||
<li class="tight-form-item" style="width: 44px"> </li>
|
<li class="tight-form-item" style="width: 44px"> </li>
|
||||||
|
|
||||||
<!-- Select Application -->
|
<!-- Select Application -->
|
||||||
<li class="tight-form-item input-small" style="width: 5em">Application</li>
|
<li class="tight-form-item" style="width: 5em">Application</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
ng-model="target.application.filter"
|
ng-model="target.application.filter"
|
||||||
@@ -180,21 +172,6 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="dropdown" add-metric-function>
|
<li class="dropdown" add-metric-function>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<!-- Scale -->
|
|
||||||
<!-- <li class="tight-form-item" ng-hide="target.mode == 2">
|
|
||||||
Scale
|
|
||||||
<i class="fa fa-question-circle"
|
|
||||||
bs-tooltip="'Set a custom multiplier for series values, for example -1 to invert series'"></i>
|
|
||||||
</li>
|
|
||||||
<li ng-hide="target.mode == 2">
|
|
||||||
<input type="text"
|
|
||||||
class="tight-form-input input-small"
|
|
||||||
ng-model="target.scale"
|
|
||||||
spellcheck='false'
|
|
||||||
placeholder="1"
|
|
||||||
ng-blur="targetBlur()">
|
|
||||||
</li> -->
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
@@ -213,12 +190,12 @@
|
|||||||
<ul class="tight-form-list" role="menu">
|
<ul class="tight-form-list" role="menu">
|
||||||
<li class="tight-form-item" style="width: 44px"> </li>
|
<li class="tight-form-item" style="width: 44px"> </li>
|
||||||
<!-- Text metric regex -->
|
<!-- Text metric regex -->
|
||||||
<li class="tight-form-item" ng-show="target.mode == 2">
|
<li class="tight-form-item" style="width: 5em" ng-show="target.mode == 2">
|
||||||
Text filter
|
Text filter
|
||||||
</li>
|
</li>
|
||||||
<li ng-show="target.mode == 2">
|
<li ng-show="target.mode == 2">
|
||||||
<input type="text"
|
<input type="text"
|
||||||
class="tight-form-input input-large" style="width: 20em"
|
class="tight-form-input" style="width: 417px"
|
||||||
ng-model="target.textFilter"
|
ng-model="target.textFilter"
|
||||||
spellcheck='false'
|
spellcheck='false'
|
||||||
placeholder="Text filter (regex)"
|
placeholder="Text filter (regex)"
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ define([
|
|||||||
$scope.init = function () {
|
$scope.init = function () {
|
||||||
$scope.targetLetters = targetLetters;
|
$scope.targetLetters = targetLetters;
|
||||||
|
|
||||||
if (!$scope.metric) {
|
var scopeDefaults = {
|
||||||
$scope.metric = {};
|
metric: {}
|
||||||
}
|
};
|
||||||
|
_.defaults($scope, scopeDefaults);
|
||||||
|
|
||||||
// Load default values
|
// Load default values
|
||||||
var targetDefaults = {
|
var targetDefaults = {
|
||||||
@@ -51,10 +52,7 @@ define([
|
|||||||
$scope.target.downsampleFunction = $scope.downsampleFunctionList[0];
|
$scope.target.downsampleFunction = $scope.downsampleFunctionList[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load metrics from cache
|
|
||||||
$scope.getMetricsFromCache().then(function() {
|
|
||||||
$scope.initFilters();
|
$scope.initFilters();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else if ($scope.target.mode === 1) {
|
else if ($scope.target.mode === 1) {
|
||||||
$scope.slaPropertyList = [
|
$scope.slaPropertyList = [
|
||||||
@@ -70,29 +68,12 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.initFilters = function () {
|
$scope.initFilters = function () {
|
||||||
|
$scope.filterGroups();
|
||||||
$scope.filterHosts();
|
$scope.filterHosts();
|
||||||
$scope.filterApplications();
|
$scope.filterApplications();
|
||||||
$scope.filterItems();
|
$scope.filterItems();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getMetricsFromCache = function() {
|
|
||||||
var item_type = $scope.editorModes[$scope.target.mode];
|
|
||||||
var promises = [
|
|
||||||
zabbixCache.getGroups(),
|
|
||||||
zabbixCache.getHosts(),
|
|
||||||
zabbixCache.getApplications(),
|
|
||||||
zabbixCache.getItems(item_type)
|
|
||||||
];
|
|
||||||
return $q.all(promises).then(function(results) {
|
|
||||||
$scope.metric = {
|
|
||||||
groupList: results[0],
|
|
||||||
hostList: results[1],
|
|
||||||
applicationList: results[2],
|
|
||||||
itemList: results[3]
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Get list of metric names for bs-typeahead directive
|
// Get list of metric names for bs-typeahead directive
|
||||||
function getMetricNames(scope, metricList) {
|
function getMetricNames(scope, metricList) {
|
||||||
return _.uniq(_.map(scope.metric[metricList], 'name'));
|
return _.uniq(_.map(scope.metric[metricList], 'name'));
|
||||||
@@ -111,6 +92,12 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.filterGroups = function() {
|
||||||
|
$scope.datasource.queryProcessor.filterGroups().then(function(groups) {
|
||||||
|
$scope.metric.groupList = groups;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
$scope.filterApplications = function () {
|
$scope.filterApplications = function () {
|
||||||
var groupFilter = templateSrv.replace($scope.target.group.filter);
|
var groupFilter = templateSrv.replace($scope.target.group.filter);
|
||||||
var hostFilter = templateSrv.replace($scope.target.host.filter);
|
var hostFilter = templateSrv.replace($scope.target.host.filter);
|
||||||
@@ -121,11 +108,12 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.filterItems = function () {
|
$scope.filterItems = function () {
|
||||||
|
var item_type = $scope.editorModes[$scope.target.mode];
|
||||||
var groupFilter = templateSrv.replace($scope.target.group.filter);
|
var groupFilter = templateSrv.replace($scope.target.group.filter);
|
||||||
var hostFilter = templateSrv.replace($scope.target.host.filter);
|
var hostFilter = templateSrv.replace($scope.target.host.filter);
|
||||||
var appFilter = templateSrv.replace($scope.target.application.filter);
|
var appFilter = templateSrv.replace($scope.target.application.filter);
|
||||||
$scope.datasource.queryProcessor.filterItems(groupFilter, hostFilter, appFilter,
|
$scope.datasource.queryProcessor.filterItems(groupFilter, hostFilter, appFilter,
|
||||||
$scope.target.showDisabledItems).then(function(items) {
|
item_type, $scope.target.showDisabledItems).then(function(items) {
|
||||||
$scope.metric.filteredItems = items;
|
$scope.metric.filteredItems = items;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ function (angular, _, utils) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.filterGroups = function(groupFilter) {
|
||||||
|
return self.cache.getGroups().then(function(groupList) {
|
||||||
|
return groupList;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
this.filterHosts = function(groupFilter) {
|
this.filterHosts = function(groupFilter) {
|
||||||
var groups = [];
|
var groups = [];
|
||||||
var hosts = [];
|
var hosts = [];
|
||||||
@@ -103,7 +109,7 @@ function (angular, _, utils) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.filterItems = function (groupFilter, hostFilter, appFilter, showDisabledItems) {
|
this.filterItems = function (groupFilter, hostFilter, appFilter, itemType, showDisabledItems) {
|
||||||
var hosts = [];
|
var hosts = [];
|
||||||
var apps = [];
|
var apps = [];
|
||||||
var items = [];
|
var items = [];
|
||||||
@@ -111,7 +117,7 @@ function (angular, _, utils) {
|
|||||||
var promises = [
|
var promises = [
|
||||||
this.filterHosts(groupFilter),
|
this.filterHosts(groupFilter),
|
||||||
this.filterApplications(groupFilter, hostFilter),
|
this.filterApplications(groupFilter, hostFilter),
|
||||||
this.cache.getItems(),
|
this.cache.getItems(itemType),
|
||||||
];
|
];
|
||||||
|
|
||||||
return $q.all(promises).then(function(results) {
|
return $q.all(promises).then(function(results) {
|
||||||
|
|||||||
@@ -132,7 +132,13 @@ function (angular, _) {
|
|||||||
|
|
||||||
p.getItems = function() {
|
p.getItems = function() {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'key_', 'value_type', 'hostid', 'status', 'state'],
|
output: [
|
||||||
|
'name', 'key_',
|
||||||
|
'value_type',
|
||||||
|
'hostid',
|
||||||
|
'status',
|
||||||
|
'state'
|
||||||
|
],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
selectApplications: []
|
selectApplications: []
|
||||||
};
|
};
|
||||||
@@ -140,6 +146,20 @@ function (angular, _) {
|
|||||||
return this.request('item.get', params);
|
return this.request('item.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
p.getLastValue = function(itemid) {
|
||||||
|
var params = {
|
||||||
|
output: ['lastvalue'],
|
||||||
|
itemids: itemid
|
||||||
|
};
|
||||||
|
return this.request('item.get', params).then(function(items) {
|
||||||
|
if (items.length) {
|
||||||
|
return items[0].lastvalue;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform history query from Zabbix API
|
* Perform history query from Zabbix API
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user