Merge branch 'release-1.0' into develop-1.9
This commit is contained in:
10
README.md
10
README.md
@@ -1,6 +1,16 @@
|
|||||||
# grafana-zabbix
|
# grafana-zabbix
|
||||||
Zabbix API datasource for Grafana dashboard
|
Zabbix API datasource for Grafana dashboard
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
Query editor allows to add metric by step-by-step selection from host group, host, application dropdown menus.
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Grafana 1.9.x
|
### Grafana 1.9.x
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ function (angular, _, kbn) {
|
|||||||
// get from & to in seconds
|
// get from & to in seconds
|
||||||
var from = kbn.parseDate(options.range.from).getTime();
|
var from = kbn.parseDate(options.range.from).getTime();
|
||||||
var to = kbn.parseDate(options.range.to).getTime();
|
var to = kbn.parseDate(options.range.to).getTime();
|
||||||
|
|
||||||
// Need for find target alias
|
// Need for find target alias
|
||||||
var targets = options.targets;
|
var targets = options.targets;
|
||||||
|
|
||||||
|
// TODO: remove undefined targets from request
|
||||||
// Check that all targets defined
|
// Check that all targets defined
|
||||||
var targetsDefined = options.targets.every(function (target, index, array) {
|
var targetsDefined = options.targets.every(function (target, index, array) {
|
||||||
return target.item;
|
return target.item;
|
||||||
@@ -46,7 +48,6 @@ function (angular, _, kbn) {
|
|||||||
// Extract zabbix api item objects from targets
|
// Extract zabbix api item objects from targets
|
||||||
var target_items = _.map(options.targets, 'item');
|
var target_items = _.map(options.targets, 'item');
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// No valid targets, return the empty dataset
|
// No valid targets, return the empty dataset
|
||||||
var d = $q.defer();
|
var d = $q.defer();
|
||||||
d.resolve({ data: [] });
|
d.resolve({ data: [] });
|
||||||
@@ -56,20 +57,7 @@ function (angular, _, kbn) {
|
|||||||
from = Math.ceil(from/1000);
|
from = Math.ceil(from/1000);
|
||||||
to = Math.ceil(to/1000);
|
to = Math.ceil(to/1000);
|
||||||
|
|
||||||
var performedQuery;
|
return this.performTimeSeriesQuery(target_items, from, to).then(function (response) {
|
||||||
|
|
||||||
// Check authorization first
|
|
||||||
if (!this.auth) {
|
|
||||||
var self = this;
|
|
||||||
performedQuery = this.performZabbixAPILogin().then(function (response) {
|
|
||||||
self.auth = response;
|
|
||||||
return self.performTimeSeriesQuery(target_items, from, to);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
performedQuery = this.performTimeSeriesQuery(target_items, from, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
return performedQuery.then(function (response) {
|
|
||||||
/**
|
/**
|
||||||
* Response should be in the format:
|
* Response should be in the format:
|
||||||
* data: [
|
* data: [
|
||||||
@@ -85,9 +73,7 @@ function (angular, _, kbn) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Index returned datapoints by item/metric id
|
// Index returned datapoints by item/metric id
|
||||||
var indexed_result = _.groupBy(response.data.result, function (history_item) {
|
var indexed_result = _.groupBy(response, 'itemid');
|
||||||
return history_item.itemid;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reduce timeseries to the same size for stacking and tooltip work properly
|
// Reduce timeseries to the same size for stacking and tooltip work properly
|
||||||
var min_length = _.min(_.map(indexed_result, function (history) {
|
var min_length = _.min(_.map(indexed_result, function (history) {
|
||||||
@@ -137,6 +123,9 @@ function (angular, _, kbn) {
|
|||||||
ZabbixAPIDatasource.prototype.doZabbixAPIRequest = function(request_data) {
|
ZabbixAPIDatasource.prototype.doZabbixAPIRequest = function(request_data) {
|
||||||
var options = {
|
var options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
url: this.url,
|
url: this.url,
|
||||||
data: request_data
|
data: request_data
|
||||||
};
|
};
|
||||||
@@ -171,37 +160,68 @@ function (angular, _, kbn) {
|
|||||||
* @param items: array of zabbix api item objects
|
* @param items: array of zabbix api item objects
|
||||||
*/
|
*/
|
||||||
ZabbixAPIDatasource.prototype.performTimeSeriesQuery = function(items, start, end) {
|
ZabbixAPIDatasource.prototype.performTimeSeriesQuery = function(items, start, end) {
|
||||||
var item_ids = items.map(function (item, index, array) {
|
|
||||||
return item.itemid;
|
// Group items by value type for separate requests
|
||||||
});
|
var items_by_value_type = _.groupBy(items, 'value_type');
|
||||||
// TODO: if different value types passed?
|
|
||||||
// Perform multiple api request.
|
var self = this;
|
||||||
var hystory_type = items[0].value_type;
|
var apiRequests = [];
|
||||||
var options = {
|
|
||||||
method: 'POST',
|
// Prepare requests for each value type
|
||||||
url: this.url,
|
_.each(items_by_value_type, function (value, key, list) {
|
||||||
data: {
|
var item_ids = _.map(value, 'itemid');
|
||||||
|
var history_type = key;
|
||||||
|
var data = {
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'history.get',
|
method: 'history.get',
|
||||||
params: {
|
params: {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
history: hystory_type,
|
history: history_type,
|
||||||
itemids: item_ids,
|
itemids: item_ids,
|
||||||
sortfield: 'clock',
|
sortfield: 'clock',
|
||||||
sortorder: 'ASC',
|
sortorder: 'ASC',
|
||||||
limit: this.limitmetrics,
|
limit: self.limitmetrics,
|
||||||
time_from: start,
|
time_from: start,
|
||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: self.auth,
|
||||||
id: 1
|
id: 1
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Relative queries (e.g. last hour) don't include an end time
|
// Relative queries (e.g. last hour) don't include an end time
|
||||||
if (end) {
|
if (end) {
|
||||||
options.data.params.time_till = end;
|
data.params.time_till = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $http(options);
|
apiRequests.push(self.doZabbixAPIRequest(data));
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.handleMultipleRequest(apiRequests);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Handle multiple request
|
||||||
|
ZabbixAPIDatasource.prototype.handleMultipleRequest = function(apiRequests) {
|
||||||
|
var history = [];
|
||||||
|
var performedQuery = null;
|
||||||
|
|
||||||
|
// Build chain of api requests and put all history data into single array
|
||||||
|
_.each(apiRequests, function (apiRequest) {
|
||||||
|
if(!performedQuery) {
|
||||||
|
performedQuery = apiRequest.then(function (response) {
|
||||||
|
history = history.concat(response);
|
||||||
|
return history;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
performedQuery = performedQuery.then(function () {
|
||||||
|
return apiRequest.then(function (response) {
|
||||||
|
history = history.concat(response);
|
||||||
|
return history;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return performedQuery;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -238,6 +258,7 @@ function (angular, _, kbn) {
|
|||||||
method: 'hostgroup.get',
|
method: 'hostgroup.get',
|
||||||
params: {
|
params: {
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
|
real_hosts: true, //Return only host groups that contain hosts
|
||||||
sortfield: 'name'
|
sortfield: 'name'
|
||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: this.auth,
|
||||||
@@ -294,7 +315,11 @@ function (angular, _, kbn) {
|
|||||||
params: {
|
params: {
|
||||||
output: ['name', 'key_', 'value_type', 'delay'],
|
output: ['name', 'key_', 'value_type', 'delay'],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
hostids: hostid
|
hostids: hostid,
|
||||||
|
webitems: true, //Include web items in the result
|
||||||
|
filter: {
|
||||||
|
value_type: [0,3]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: this.auth,
|
||||||
id: 1
|
id: 1
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ function (angular, _) {
|
|||||||
$scope.metric.hostGroupList = series;
|
$scope.metric.hostGroupList = series;
|
||||||
if ($scope.target.hostGroup) {
|
if ($scope.target.hostGroup) {
|
||||||
$scope.target.hostGroup = $scope.metric.hostGroupList.filter(function (item, index, array) {
|
$scope.target.hostGroup = $scope.metric.hostGroupList.filter(function (item, index, array) {
|
||||||
|
|
||||||
// Find selected host in metric.hostList
|
// Find selected host in metric.hostList
|
||||||
return (item.groupid == $scope.target.hostGroup.groupid);
|
return (item.groupid == $scope.target.hostGroup.groupid);
|
||||||
}).pop();
|
}).pop();
|
||||||
@@ -150,11 +149,13 @@ function (angular, _) {
|
|||||||
$scope.updateHostList = function(groupid) {
|
$scope.updateHostList = function(groupid) {
|
||||||
$scope.datasource.performHostSuggestQuery(groupid).then(function (series) {
|
$scope.datasource.performHostSuggestQuery(groupid).then(function (series) {
|
||||||
$scope.metric.hostList = series;
|
$scope.metric.hostList = series;
|
||||||
$scope.target.host = $scope.metric.hostList.filter(function (item, index, array) {
|
|
||||||
|
|
||||||
|
if ($scope.target.host) {
|
||||||
|
$scope.target.host = $scope.metric.hostList.filter(function (item, index, array) {
|
||||||
// Find selected host in metric.hostList
|
// Find selected host in metric.hostList
|
||||||
return (item.hostid == $scope.target.host.hostid);
|
return (item.hostid == $scope.target.host.hostid);
|
||||||
}).pop();
|
}).pop();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -167,7 +168,6 @@ function (angular, _) {
|
|||||||
$scope.metric.applicationList = series;
|
$scope.metric.applicationList = series;
|
||||||
if ($scope.target.application) {
|
if ($scope.target.application) {
|
||||||
$scope.target.application = $scope.metric.applicationList.filter(function (item, index, array) {
|
$scope.target.application = $scope.metric.applicationList.filter(function (item, index, array) {
|
||||||
|
|
||||||
// Find selected application in metric.hostList
|
// Find selected application in metric.hostList
|
||||||
return (item.applicationid == $scope.target.application.applicationid);
|
return (item.applicationid == $scope.target.application.applicationid);
|
||||||
}).pop();
|
}).pop();
|
||||||
@@ -192,11 +192,12 @@ function (angular, _) {
|
|||||||
item.expandedName = expandItemName(item);
|
item.expandedName = expandItemName(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if ($scope.target.item) {
|
||||||
$scope.target.item = $scope.metric.itemList.filter(function (item, index, array) {
|
$scope.target.item = $scope.metric.itemList.filter(function (item, index, array) {
|
||||||
|
|
||||||
// Find selected item in metric.hostList
|
// Find selected item in metric.hostList
|
||||||
return (item.itemid == $scope.target.item.itemid);
|
return (item.itemid == $scope.target.item.itemid);
|
||||||
}).pop();
|
}).pop();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$scope.metric.itemList = [];
|
$scope.metric.itemList = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user