Resolved #19 - Zabbix IT services metrics.
This commit is contained in:
@@ -94,93 +94,103 @@ 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) {
|
||||||
|
|
||||||
// Don't show undefined and hidden targets
|
if (!target.ITService) {
|
||||||
if (target.hide || !target.group || !target.host
|
// Don't show undefined and hidden targets
|
||||||
|| !target.application || !target.item) {
|
if (target.hide || !target.group || !target.host
|
||||||
return [];
|
|| !target.application || !target.item) {
|
||||||
}
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// Replace templated variables
|
// Replace templated variables
|
||||||
var groupname = templateSrv.replace(target.group.name);
|
var groupname = templateSrv.replace(target.group.name);
|
||||||
var hostname = templateSrv.replace(target.host.name);
|
var hostname = templateSrv.replace(target.host.name);
|
||||||
var appname = templateSrv.replace(target.application.name);
|
var appname = templateSrv.replace(target.application.name);
|
||||||
var itemname = templateSrv.replace(target.item.name);
|
var itemname = templateSrv.replace(target.item.name);
|
||||||
|
|
||||||
// Extract zabbix groups, hosts and apps from string:
|
// Extract zabbix groups, hosts and apps from string:
|
||||||
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
|
// "{host1,host2,...,hostN}" --> [host1, host2, ..., hostN]
|
||||||
var groups = zabbixHelperSrv.splitMetrics(groupname);
|
var groups = zabbixHelperSrv.splitMetrics(groupname);
|
||||||
var hosts = zabbixHelperSrv.splitMetrics(hostname);
|
var hosts = zabbixHelperSrv.splitMetrics(hostname);
|
||||||
var apps = zabbixHelperSrv.splitMetrics(appname);
|
var apps = zabbixHelperSrv.splitMetrics(appname);
|
||||||
|
|
||||||
// Remove hostnames from item names and then
|
// Remove hostnames from item names and then
|
||||||
// extract item names
|
// extract item names
|
||||||
// "hostname: itemname" --> "itemname"
|
// "hostname: itemname" --> "itemname"
|
||||||
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
|
// Find items by item names and perform queries
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.zabbixAPI.itemFindQuery(groups, hosts, apps)
|
return this.zabbixAPI.itemFindQuery(groups, hosts, apps)
|
||||||
.then(function (items) {
|
.then(function (items) {
|
||||||
|
|
||||||
// Filter hosts by regex
|
// Filter hosts by regex
|
||||||
if (target.host.visible_name === 'All') {
|
if (target.host.visible_name === 'All') {
|
||||||
if (target.hostFilter && _.every(items, _.identity.hosts)) {
|
if (target.hostFilter && _.every(items, _.identity.hosts)) {
|
||||||
|
|
||||||
// Use templated variables in filter
|
// Use templated variables in filter
|
||||||
var host_pattern = new RegExp(templateSrv.replace(target.hostFilter));
|
var host_pattern = new RegExp(templateSrv.replace(target.hostFilter));
|
||||||
items = _.filter(items, function (item) {
|
items = _.filter(items, function (item) {
|
||||||
return _.some(item.hosts, function (host) {
|
return _.some(item.hosts, function (host) {
|
||||||
return host_pattern.test(host.name);
|
return host_pattern.test(host.name);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (itemnames[0] === 'All') {
|
if (itemnames[0] === 'All') {
|
||||||
|
|
||||||
// Filter items by regex
|
// Filter items by regex
|
||||||
if (target.itemFilter) {
|
if (target.itemFilter) {
|
||||||
|
|
||||||
// Use templated variables in filter
|
// Use templated variables in filter
|
||||||
var item_pattern = new RegExp(templateSrv.replace(target.itemFilter));
|
var item_pattern = new RegExp(templateSrv.replace(target.itemFilter));
|
||||||
|
return _.filter(items, function (item) {
|
||||||
|
return item_pattern.test(zabbixHelperSrv.expandItemName(item));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Filtering items
|
||||||
return _.filter(items, function (item) {
|
return _.filter(items, function (item) {
|
||||||
return item_pattern.test(zabbixHelperSrv.expandItemName(item));
|
return _.contains(itemnames, zabbixHelperSrv.expandItemName(item));
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
} else {
|
}).then(function (items) {
|
||||||
|
|
||||||
// Filtering items
|
// Don't perform query for high number of items
|
||||||
return _.filter(items, function (item) {
|
// to prevent Grafana slowdown
|
||||||
return _.contains(itemnames, zabbixHelperSrv.expandItemName(item));
|
if (items.length > self.limitmetrics) {
|
||||||
});
|
var message = "Try to increase limitmetrics parameter in datasource config.<br>"
|
||||||
}
|
+ "Current limitmetrics value is " + self.limitmetrics;
|
||||||
}).then(function (items) {
|
alertSrv.set("Metrics limit exceeded", message, "warning", 10000);
|
||||||
|
return [];
|
||||||
// Don't perform query for high number of items
|
|
||||||
// to prevent Grafana slowdown
|
|
||||||
if (items.length > self.limitmetrics) {
|
|
||||||
var message = "Try to increase limitmetrics parameter in datasource config.<br>"
|
|
||||||
+ "Current limitmetrics value is " + self.limitmetrics;
|
|
||||||
alertSrv.set("Metrics limit exceeded", message, "warning", 10000);
|
|
||||||
return [];
|
|
||||||
} else {
|
|
||||||
items = _.flatten(items);
|
|
||||||
|
|
||||||
// Use alias only for single metric, otherwise use item names
|
|
||||||
var alias = target.item.name === 'All' || itemnames.length > 1 ? undefined : templateSrv.replace(target.alias);
|
|
||||||
|
|
||||||
if ((from < useTrendsFrom) && self.trends) {
|
|
||||||
return self.zabbixAPI.getTrends(items, from, to)
|
|
||||||
.then(_.bind(zabbixHelperSrv.handleTrendResponse, zabbixHelperSrv, items, alias, target.scale));
|
|
||||||
} else {
|
} else {
|
||||||
return self.zabbixAPI.getHistory(items, from, to)
|
items = _.flatten(items);
|
||||||
.then(_.bind(zabbixHelperSrv.handleHistoryResponse, zabbixHelperSrv, items, alias, target.scale));
|
|
||||||
|
// Use alias only for single metric, otherwise use item names
|
||||||
|
var alias = target.item.name === 'All' || itemnames.length > 1 ? undefined : templateSrv.replace(target.alias);
|
||||||
|
|
||||||
|
if ((from < useTrendsFrom) && self.trends) {
|
||||||
|
return self.zabbixAPI.getTrends(items, from, to)
|
||||||
|
.then(_.bind(zabbixHelperSrv.handleTrendResponse, zabbixHelperSrv, items, alias, target.scale));
|
||||||
|
} else {
|
||||||
|
return self.zabbixAPI.getHistory(items, from, to)
|
||||||
|
.then(_.bind(zabbixHelperSrv.handleHistoryResponse, zabbixHelperSrv, items, alias, target.scale));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
} else {
|
||||||
|
// Don't show undefined and hidden targets
|
||||||
|
if (target.hide || !target.itservice || !target.slaProperty) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
return this.zabbixAPI.getSLA(target.itservice.serviceid, from, to)
|
||||||
|
.then(_.bind(zabbixHelperSrv.handleSLAResponse, zabbixHelperSrv, target.itservice, target.slaProperty));
|
||||||
|
}
|
||||||
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
return $q.all(_.flatten(promises)).then(function (results) {
|
return $q.all(_.flatten(promises)).then(function (results) {
|
||||||
|
|||||||
@@ -109,6 +109,35 @@ function (angular, _) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Zabbix API service.getsla response to Grafana format
|
||||||
|
*
|
||||||
|
* @param itservice
|
||||||
|
* @param slaProperty
|
||||||
|
* @param slaObject
|
||||||
|
* @returns {{target: *, datapoints: *[]}}
|
||||||
|
*/
|
||||||
|
this.handleSLAResponse = function (itservice, slaProperty, slaObject) {
|
||||||
|
var targetSLA = slaObject[itservice.serviceid].sla[0];
|
||||||
|
if (slaProperty.property === 'status') {
|
||||||
|
var targetStatus = slaObject[itservice.serviceid].status;
|
||||||
|
return {
|
||||||
|
target: itservice.name + ' ' + slaProperty.name,
|
||||||
|
datapoints: [
|
||||||
|
[targetStatus, targetSLA.to * 1000]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
target: itservice.name + ' ' + slaProperty.name,
|
||||||
|
datapoints: [
|
||||||
|
[targetSLA[slaProperty.property], targetSLA.from * 1000],
|
||||||
|
[targetSLA[slaProperty.property], targetSLA.to * 1000]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expand item parameters, for example:
|
* Expand item parameters, for example:
|
||||||
* CPU $2 time ($3) --> CPU system time (avg1)
|
* CPU $2 time ($3) --> CPU system time (avg1)
|
||||||
|
|||||||
@@ -16,6 +16,16 @@
|
|||||||
<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 to IT Services editor -->
|
||||||
|
<li role="menuitem" ng-hide="target.mode == 1">
|
||||||
|
<a class="pointer" tabindex="1"
|
||||||
|
ng-click="switchEditorMode(1)">IT services</a>
|
||||||
|
</li>
|
||||||
|
<li role="menuitem" ng-show="target.mode">
|
||||||
|
<a class="pointer" tabindex="1"
|
||||||
|
ng-click="switchEditorMode(0)">Items</a>
|
||||||
|
</li>
|
||||||
|
<li class="divider" role="menuitem"></li>
|
||||||
<li role="menuitem"><a tabindex="1" ng-click="duplicate()">Duplicate</a></li>
|
<li role="menuitem"><a tabindex="1" ng-click="duplicate()">Duplicate</a></li>
|
||||||
<li role="menuitem"><a tabindex="1" ng-click="moveMetricQuery($index, $index-1)">Move up</a></li>
|
<li role="menuitem"><a tabindex="1" ng-click="moveMetricQuery($index, $index-1)">Move up</a></li>
|
||||||
<li role="menuitem"><a tabindex="1" ng-click="moveMetricQuery($index, $index+1)">Move down</a></li>
|
<li role="menuitem"><a tabindex="1" ng-click="moveMetricQuery($index, $index+1)">Move down</a></li>
|
||||||
@@ -42,7 +52,30 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul class="tight-form-list" role="menu">
|
<!-- IT Service editor -->
|
||||||
|
<ul class="tight-form-list" role="menu" ng-show="target.mode == 1">
|
||||||
|
<li class="tight-form-item input-small">IT Service</li>
|
||||||
|
<li>
|
||||||
|
<select class="tight-form-input input-large"
|
||||||
|
ng-change="selectITService()"
|
||||||
|
ng-model="target.itservice"
|
||||||
|
bs-tooltip="target.itservice.name.length > 25 ? target.itservice.name : ''"
|
||||||
|
ng-options="itservice.name for itservice in itserviceList track by itservice.name">
|
||||||
|
<option value="">-- Select IT service --</option>
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
|
<li class="tight-form-item input-medium">IT service property</li>
|
||||||
|
<li>
|
||||||
|
<select class="tight-form-input input-medium"
|
||||||
|
ng-change="selectITService()"
|
||||||
|
ng-model="target.slaProperty"
|
||||||
|
ng-options="slaProperty.name for slaProperty in slaPropertyList track by slaProperty.name">
|
||||||
|
<option value="">-- Property --</option>
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ul class="tight-form-list" role="menu" ng-hide="target.mode">
|
||||||
<!-- Alias -->
|
<!-- Alias -->
|
||||||
<li>
|
<li>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
@@ -55,15 +88,13 @@
|
|||||||
<!-- 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>
|
||||||
<li>
|
<li>
|
||||||
<label>
|
<select class="tight-form-input input-large"
|
||||||
<select class="tight-form-input input-large"
|
ng-change="selectHostGroup()"
|
||||||
ng-change="selectHostGroup()"
|
ng-model="target.group"
|
||||||
ng-model="target.group"
|
bs-tooltip="target.group.name.length > 25 ? target.group.name : ''"
|
||||||
bs-tooltip="target.group.name.length > 25 ? target.group.name : ''"
|
ng-options="group.visible_name ? group.visible_name : group.name for group in metric.groupList track by group.name">
|
||||||
ng-options="group.visible_name ? group.visible_name : group.name for group in metric.groupList track by group.name">
|
<option value="">-- Select host group --</option>
|
||||||
<option value="">-- Select host group --</option>
|
</select>
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<a bs-tooltip="target.errors.metric"
|
<a bs-tooltip="target.errors.metric"
|
||||||
style="color: rgb(229, 189, 28)"
|
style="color: rgb(229, 189, 28)"
|
||||||
ng-show="target.errors.metric">
|
ng-show="target.errors.metric">
|
||||||
@@ -73,15 +104,13 @@
|
|||||||
<!-- Select Host -->
|
<!-- Select Host -->
|
||||||
<li class="tight-form-item input-small" style="width: 3em">Host</li>
|
<li class="tight-form-item input-small" style="width: 3em">Host</li>
|
||||||
<li>
|
<li>
|
||||||
<label>
|
<select class="tight-form-input input-large"
|
||||||
<select class="tight-form-input input-large"
|
ng-change="selectHost()"
|
||||||
ng-change="selectHost()"
|
ng-model="target.host"
|
||||||
ng-model="target.host"
|
bs-tooltip="target.host.name.length > 25 ? target.host.name : ''"
|
||||||
bs-tooltip="target.host.name.length > 25 ? target.host.name : ''"
|
ng-options="host.visible_name ? host.visible_name : host.name for host in metric.hostList track by host.name">
|
||||||
ng-options="host.visible_name ? host.visible_name : host.name for host in metric.hostList track by host.name">
|
<option value="">-- Select host --</option>
|
||||||
<option value="">-- Select host --</option>
|
</select>
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<a bs-tooltip="target.errors.metric"
|
<a bs-tooltip="target.errors.metric"
|
||||||
style="color: rgb(229, 189, 28)"
|
style="color: rgb(229, 189, 28)"
|
||||||
ng-show="target.errors.metric">
|
ng-show="target.errors.metric">
|
||||||
@@ -105,7 +134,9 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tight-form" ng-hide="target.mode">
|
||||||
<ul class="tight-form-list" role="menu">
|
<ul class="tight-form-list" role="menu">
|
||||||
<li class="tight-form-item" style="min-width: 15px; text-align: center"> </li>
|
<li class="tight-form-item" style="min-width: 15px; text-align: center"> </li>
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
@@ -116,15 +147,13 @@
|
|||||||
<!-- Select Application -->
|
<!-- Select Application -->
|
||||||
<li class="tight-form-item input-small" style="width: 5em">Application</li>
|
<li class="tight-form-item input-small" style="width: 5em">Application</li>
|
||||||
<li>
|
<li>
|
||||||
<label>
|
<select class="tight-form-input input-large"
|
||||||
<select class="tight-form-input input-large"
|
ng-change="selectApplication()"
|
||||||
ng-select="selectApplication()"
|
ng-model="target.application"
|
||||||
ng-model="target.application"
|
bs-tooltip="target.application.name.length > 15 ? target.application.name : ''"
|
||||||
bs-tooltip="target.application.name.length > 15 ? target.application.name : ''"
|
ng-options="app.visible_name ? app.visible_name : app.name for app in metric.applicationList track by app.name">
|
||||||
ng-options="app.visible_name ? app.visible_name : app.name for app in metric.applicationList track by app.name">
|
<option value="">-- Select application --</option>
|
||||||
<option value="">-- Select application --</option>
|
</select>
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<a bs-tooltip="target.errors.metric"
|
<a bs-tooltip="target.errors.metric"
|
||||||
style="color: rgb(229, 189, 28)"
|
style="color: rgb(229, 189, 28)"
|
||||||
ng-show="target.errors.metric">
|
ng-show="target.errors.metric">
|
||||||
@@ -134,15 +163,13 @@
|
|||||||
<!-- Select Item -->
|
<!-- Select Item -->
|
||||||
<li class="tight-form-item input-small" style="width: 3em">Item</li>
|
<li class="tight-form-item input-small" style="width: 3em">Item</li>
|
||||||
<li>
|
<li>
|
||||||
<label>
|
<select class="tight-form-input input-large"
|
||||||
<select class="tight-form-input input-large"
|
ng-change="selectItem()"
|
||||||
ng-change="selectItem()"
|
ng-model="target.item"
|
||||||
ng-model="target.item"
|
bs-tooltip="target.item.name.length > 25 ? target.item.name : ''"
|
||||||
bs-tooltip="target.item.name.length > 25 ? target.item.name : ''"
|
ng-options="item.name for item in metric.itemList track by item.name">
|
||||||
ng-options="item.name for item in metric.itemList track by item.name">
|
<option value="">-- Select item --</option>
|
||||||
<option value="">-- Select item --</option>
|
</select>
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<a bs-tooltip="target.errors.metric"
|
<a bs-tooltip="target.errors.metric"
|
||||||
style="color: rgb(229, 189, 28)"
|
style="color: rgb(229, 189, 28)"
|
||||||
ng-show="target.errors.metric">
|
ng-show="target.errors.metric">
|
||||||
@@ -178,6 +205,7 @@
|
|||||||
ng-blur="targetBlur()">
|
ng-blur="targetBlur()">
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -213,7 +241,17 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
<a ng-click="toggleEditorHelp(1)" bs-tooltip="'click to show helpful info'" data-placement="bottom">
|
<a ng-click="toggleEditorHelp(1)" bs-tooltip="'click to show helpful info'" data-placement="bottom">
|
||||||
max data points
|
Max data points
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="tight-form-item">
|
||||||
|
<a ng-click="toggleEditorHelp(2)" bs-tooltip="'click to show helpful info'" data-placement="bottom">
|
||||||
|
IT services
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="tight-form-item">
|
||||||
|
<a ng-click="toggleEditorHelp(3)" bs-tooltip="'click to show helpful info'" data-placement="bottom">
|
||||||
|
IT service property
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -237,5 +275,23 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="grafana-info-box span6" ng-if="editorHelpIndex === 2">
|
||||||
|
<h5>IT services</h5>
|
||||||
|
<p>
|
||||||
|
Select "IT services" in targets menu to activate IT services mode.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grafana-info-box span6" ng-if="editorHelpIndex === 3">
|
||||||
|
<h5>IT service property</h5>
|
||||||
|
<ul>
|
||||||
|
<li>Zabbix returns the following availability information about IT service</li>
|
||||||
|
<li>Status - current status of the IT service</li>
|
||||||
|
<li>SLA - SLA for the given time interval</li>
|
||||||
|
<li>OK time - time the service was in OK state, in seconds</li>
|
||||||
|
<li>Problem time - time the service was in problem state, in seconds</li>
|
||||||
|
<li>Down time - time the service was in scheduled downtime, in seconds</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1,212 +1,257 @@
|
|||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
'./helperFunctions'
|
'./helperFunctions'
|
||||||
],
|
],
|
||||||
function (angular, _) {
|
function (angular, _) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.controllers');
|
var module = angular.module('grafana.controllers');
|
||||||
var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
|
||||||
module.controller('ZabbixAPIQueryCtrl', function($scope, $sce, templateSrv, zabbixHelperSrv) {
|
module.controller('ZabbixAPIQueryCtrl', function ($scope, $sce, templateSrv, zabbixHelperSrv) {
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function () {
|
||||||
$scope.targetLetters = targetLetters;
|
$scope.targetLetters = targetLetters;
|
||||||
$scope.metric = {
|
if ($scope.target.mode === 1) {
|
||||||
hostGroupList: [],
|
$scope.slaPropertyList = [
|
||||||
hostList: [{name: '*', visible_name: 'All'}],
|
{name: "Status", property: "status"},
|
||||||
applicationList: [{name: '*', visible_name: 'All'}],
|
{name: "SLA", property: "sla"},
|
||||||
itemList: [{name: 'All'}]
|
{name: "OK time", property: "okTime"},
|
||||||
|
{name: "Problem time", property: "problemTime"},
|
||||||
|
{name: "Down time", property: "downtimeTime"}
|
||||||
|
];
|
||||||
|
$scope.itserviceList = [{name: "test"}];
|
||||||
|
$scope.updateITServiceList();
|
||||||
|
} else {
|
||||||
|
$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();
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update host group, host, application and item lists
|
/**
|
||||||
$scope.updateGroupList();
|
* Switch query editor to specified mode.
|
||||||
$scope.updateHostList();
|
* Modes:
|
||||||
$scope.updateAppList();
|
* 0 - items
|
||||||
$scope.updateItemList();
|
* 1 - IT services
|
||||||
|
*/
|
||||||
|
$scope.switchEditorMode = function (mode) {
|
||||||
|
$scope.target.mode = mode;
|
||||||
|
$scope.init();
|
||||||
|
};
|
||||||
|
|
||||||
setItemAlias();
|
/**
|
||||||
|
* Take alias from item name by default
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
*/
|
||||||
};
|
function setItemAlias() {
|
||||||
|
if (!$scope.target.alias && $scope.target.item) {
|
||||||
/**
|
$scope.target.alias = $scope.target.item.name;
|
||||||
* 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() {
|
$scope.targetBlur = function () {
|
||||||
setItemAlias();
|
setItemAlias();
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
$scope.oldTarget = angular.copy($scope.target);
|
$scope.oldTarget = angular.copy($scope.target);
|
||||||
$scope.get_data();
|
$scope.get_data();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call when host group selected
|
* Call when IT service is selected.
|
||||||
*/
|
*/
|
||||||
$scope.selectHostGroup = function() {
|
$scope.selectITService = function () {
|
||||||
$scope.updateHostList();
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
$scope.updateAppList();
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
$scope.updateItemList();
|
$scope.oldTarget = angular.copy($scope.target);
|
||||||
|
$scope.get_data();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
/**
|
||||||
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
* Call when host group selected
|
||||||
$scope.oldTarget = angular.copy($scope.target);
|
*/
|
||||||
$scope.get_data();
|
$scope.selectHostGroup = function () {
|
||||||
}
|
$scope.updateHostList();
|
||||||
};
|
$scope.updateAppList();
|
||||||
|
$scope.updateItemList();
|
||||||
|
|
||||||
/**
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
* Call when host selected
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
*/
|
$scope.oldTarget = angular.copy($scope.target);
|
||||||
$scope.selectHost = function() {
|
$scope.get_data();
|
||||||
$scope.updateAppList();
|
}
|
||||||
$scope.updateItemList();
|
};
|
||||||
|
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
/**
|
||||||
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
* Call when host selected
|
||||||
$scope.oldTarget = angular.copy($scope.target);
|
*/
|
||||||
$scope.get_data();
|
$scope.selectHost = function () {
|
||||||
}
|
$scope.updateAppList();
|
||||||
};
|
$scope.updateItemList();
|
||||||
|
|
||||||
/**
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
* Call when application selected
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
*/
|
$scope.oldTarget = angular.copy($scope.target);
|
||||||
$scope.selectApplication = function() {
|
$scope.get_data();
|
||||||
$scope.updateItemList();
|
}
|
||||||
|
};
|
||||||
|
|
||||||
$scope.target.errors = validateTarget($scope.target);
|
/**
|
||||||
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
* Call when application selected
|
||||||
$scope.oldTarget = angular.copy($scope.target);
|
*/
|
||||||
$scope.get_data();
|
$scope.selectApplication = function () {
|
||||||
}
|
$scope.updateItemList();
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
$scope.target.errors = validateTarget($scope.target);
|
||||||
* Call when item selected
|
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
|
||||||
*/
|
$scope.oldTarget = angular.copy($scope.target);
|
||||||
$scope.selectItem = function() {
|
$scope.get_data();
|
||||||
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);
|
* Call when item selected
|
||||||
$scope.panel.targets.push(clone);
|
*/
|
||||||
};
|
$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.moveMetricQuery = function(fromIndex, toIndex) {
|
$scope.duplicate = function () {
|
||||||
_.move($scope.panel.targets, fromIndex, toIndex);
|
var clone = angular.copy($scope.target);
|
||||||
};
|
$scope.panel.targets.push(clone);
|
||||||
|
};
|
||||||
|
|
||||||
//////////////////////////////
|
$scope.moveMetricQuery = function (fromIndex, toIndex) {
|
||||||
// SUGGESTION QUERIES
|
_.move($scope.panel.targets, fromIndex, toIndex);
|
||||||
//////////////////////////////
|
};
|
||||||
|
|
||||||
/**
|
//////////////////////////////
|
||||||
* Update list of host groups
|
// SUGGESTION QUERIES
|
||||||
*/
|
//////////////////////////////
|
||||||
$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
|
* Update list of IT services
|
||||||
*/
|
*/
|
||||||
$scope.updateHostList = function() {
|
$scope.updateITServiceList = function () {
|
||||||
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
|
$scope.datasource.zabbixAPI.getITService().then(function (iteservices) {
|
||||||
if (groups) {
|
$scope.itserviceList = [];
|
||||||
$scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) {
|
$scope.itserviceList = $scope.itserviceList.concat(iteservices);
|
||||||
$scope.metric.hostList = [{name: '*', visible_name: 'All'}];
|
|
||||||
addTemplatedVariables($scope.metric.hostList);
|
|
||||||
$scope.metric.hostList = $scope.metric.hostList.concat(hosts);
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update list of host applications
|
* Update list of host groups
|
||||||
*/
|
*/
|
||||||
$scope.updateAppList = function() {
|
$scope.updateGroupList = function () {
|
||||||
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
|
$scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
|
||||||
var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
|
$scope.metric.groupList = [{name: '*', visible_name: 'All'}];
|
||||||
if (groups && hosts) {
|
addTemplatedVariables($scope.metric.groupList);
|
||||||
$scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
|
$scope.metric.groupList = $scope.metric.groupList.concat(groups);
|
||||||
apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
|
});
|
||||||
return {name: appname};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.metric.applicationList = [{name: '*', visible_name: 'All'}];
|
}
|
||||||
addTemplatedVariables($scope.metric.applicationList);
|
};
|
||||||
$scope.metric.applicationList = $scope.metric.applicationList.concat(apps);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update list of items
|
* Update list of host applications
|
||||||
*/
|
*/
|
||||||
$scope.updateItemList = function() {
|
$scope.updateAppList = function () {
|
||||||
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
|
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 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) {
|
||||||
if (groups && hosts && apps) {
|
$scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
|
||||||
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
|
apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
|
||||||
// Show only unique item names
|
return {name: appname};
|
||||||
var uniq_items = _.map(_.uniq(items, function (item) {
|
});
|
||||||
return zabbixHelperSrv.expandItemName(item);
|
$scope.metric.applicationList = [{name: '*', visible_name: 'All'}];
|
||||||
}), function (item) {
|
addTemplatedVariables($scope.metric.applicationList);
|
||||||
return {name: zabbixHelperSrv.expandItemName(item)};
|
$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;
|
||||||
|
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)};
|
||||||
|
});
|
||||||
|
$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
|
// VALIDATION
|
||||||
*
|
//////////////////////////////
|
||||||
* @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
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////
|
function validateTarget(target) {
|
||||||
// VALIDATION
|
var errs = {};
|
||||||
//////////////////////////////
|
if (!target) {
|
||||||
|
errs = 'Not defined';
|
||||||
function validateTarget(target) {
|
}
|
||||||
var errs = {};
|
return errs;
|
||||||
if (!target) {
|
|
||||||
errs = 'Not defined';
|
|
||||||
}
|
}
|
||||||
return errs;
|
|
||||||
}
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -245,8 +245,8 @@ function (angular, _) {
|
|||||||
/**
|
/**
|
||||||
* Get the list of hosts
|
* Get the list of hosts
|
||||||
*
|
*
|
||||||
* @param {array} groupids
|
* @param {string|string[]} groupids
|
||||||
* @return {array} array of Zabbix host objects
|
* @return {Object} array of Zabbix host objects
|
||||||
*/
|
*/
|
||||||
p.performHostSuggestQuery = function(groupids) {
|
p.performHostSuggestQuery = function(groupids) {
|
||||||
var params = {
|
var params = {
|
||||||
@@ -269,7 +269,7 @@ function (angular, _) {
|
|||||||
*
|
*
|
||||||
* @param {array} hostids
|
* @param {array} hostids
|
||||||
* @param {array} groupids
|
* @param {array} groupids
|
||||||
* @return {array} array of Zabbix application objects
|
* @return {Object} array of Zabbix application objects
|
||||||
*/
|
*/
|
||||||
p.performAppSuggestQuery = function(hostids, /* optional */ groupids) {
|
p.performAppSuggestQuery = function(hostids, /* optional */ groupids) {
|
||||||
var params = {
|
var params = {
|
||||||
@@ -289,10 +289,10 @@ function (angular, _) {
|
|||||||
/**
|
/**
|
||||||
* Items request
|
* Items request
|
||||||
*
|
*
|
||||||
* @param {string or Array} hostids ///////////////////////////
|
* @param {string|string[]} hostids ///////////////////////////
|
||||||
* @param {string or Array} applicationids // Zabbix API parameters //
|
* @param {string|string[]} applicationids // Zabbix API parameters //
|
||||||
* @param {string or Array} groupids ///////////////////////////
|
* @param {string|string[]} groupids ///////////////////////////
|
||||||
* @return {string or Array} 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, /* optional */ groupids) {
|
||||||
var params = {
|
var params = {
|
||||||
@@ -508,6 +508,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;
|
return ZabbixAPI;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user