Merge branch 'release-2.0.1'
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
'use strict';
|
|
||||||
define([
|
define([
|
||||||
'angular',
|
'angular',
|
||||||
'lodash',
|
'lodash',
|
||||||
@@ -8,7 +7,7 @@ define([
|
|||||||
'./queryCtrl'
|
'./queryCtrl'
|
||||||
],
|
],
|
||||||
function (angular, _, kbn) {
|
function (angular, _, kbn) {
|
||||||
//'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.services');
|
var module = angular.module('grafana.services');
|
||||||
|
|
||||||
@@ -26,21 +25,56 @@ function (angular, _, kbn) {
|
|||||||
this.basicAuth = datasource.basicAuth;
|
this.basicAuth = datasource.basicAuth;
|
||||||
this.withCredentials = datasource.withCredentials;
|
this.withCredentials = datasource.withCredentials;
|
||||||
|
|
||||||
// TODO: fix passing username and password from config.html
|
if (datasource.jsonData) {
|
||||||
this.username = datasource.meta.username;
|
this.username = datasource.jsonData.username;
|
||||||
this.password = datasource.meta.password;
|
this.password = datasource.jsonData.password;
|
||||||
|
|
||||||
// Use trends instead history since specified time
|
// Use trends instead history since specified time
|
||||||
this.trends = datasource.meta.trends;
|
this.trends = datasource.jsonData.trends;
|
||||||
this.trendsFrom = datasource.meta.trendsFrom || '7d';
|
this.trendsFrom = datasource.jsonData.trendsFrom || '7d';
|
||||||
|
|
||||||
// Limit metrics per panel for templated request
|
// Limit metrics per panel for templated request
|
||||||
this.limitmetrics = datasource.meta.limitmetrics || 100;
|
this.limitmetrics = datasource.jsonData.limitMetrics || 100;
|
||||||
|
} else {
|
||||||
|
// DEPRECATED. Loads settings from plugin.json file.
|
||||||
|
// For backward compatibility only.
|
||||||
|
this.username = datasource.meta.username;
|
||||||
|
this.password = datasource.meta.password;
|
||||||
|
this.trends = datasource.meta.trends;
|
||||||
|
this.trendsFrom = datasource.meta.trendsFrom || '7d';
|
||||||
|
this.limitmetrics = datasource.meta.limitmetrics || 100;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize Zabbix API
|
// Initialize Zabbix API
|
||||||
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test connection to Zabbix API
|
||||||
|
*
|
||||||
|
* @return {object} Connection status and Zabbix API version
|
||||||
|
*/
|
||||||
|
ZabbixAPIDatasource.prototype.testDatasource = function() {
|
||||||
|
var self = this;
|
||||||
|
return this.zabbixAPI.getZabbixAPIVersion().then(function (apiVersion) {
|
||||||
|
return self.zabbixAPI.performZabbixAPILogin().then(function (auth) {
|
||||||
|
if (auth) {
|
||||||
|
return {
|
||||||
|
status: "success",
|
||||||
|
title: "Success",
|
||||||
|
message: "Zabbix API version: " + apiVersion
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
status: "error",
|
||||||
|
title: "Invalid user name or password",
|
||||||
|
message: "Zabbix API version: " + apiVersion
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls for each panel in dashboard.
|
* Calls for each panel in dashboard.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -10,16 +10,44 @@
|
|||||||
User
|
User
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="text" class="tight-form-input input-large" ng-model='current.jsonData.zabbixUser' placeholder=""></input>
|
<input type="text" class="tight-form-input input-large" ng-model='current.jsonData.username' placeholder=""></input>
|
||||||
</li>
|
</li>
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
Password
|
Password
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="password" class="tight-form-input input-large" ng-model='current.jsonData.zabbixPassword' placeholder=""></input>
|
<input type="password" class="tight-form-input input-large" ng-model='current.jsonData.password' placeholder=""></input>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="tight-form">
|
||||||
|
<ul class="tight-form-list">
|
||||||
|
<li class="tight-form-item" style="width: 80px">
|
||||||
|
Trends
|
||||||
|
</li>
|
||||||
|
<li class="tight-form-item">
|
||||||
|
Enable
|
||||||
|
<input class="cr1" id="current.jsonData.trends" type="checkbox" ng-model="current.jsonData.trends" ng-checked="current.jsonData.trends">
|
||||||
|
<label for="current.jsonData.trends" class="cr1"></label>
|
||||||
|
</li>
|
||||||
|
<li class="tight-form-item" ng-if="current.jsonData.trends">
|
||||||
|
Use trends from
|
||||||
|
</li>
|
||||||
|
<li ng-if="current.jsonData.trends">
|
||||||
|
<input type="text" class="tight-form-input input-small" ng-model='current.basicAuthUser' placeholder="7d"></input>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
<div class="tight-form last">
|
||||||
|
<ul class="tight-form-list">
|
||||||
|
<li class="tight-form-item" style="width: 80px">
|
||||||
|
Metrics limit
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<input type="text" class="tight-form-input input-small" ng-model='current.jsonData.limitMetrics' placeholder="100"></input>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ function (angular, _) {
|
|||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
$scope.targetLetters = targetLetters;
|
$scope.targetLetters = targetLetters;
|
||||||
$scope.metric = {
|
$scope.metric = {
|
||||||
hostGroupList: ["Loading..."],
|
hostGroupList: [],
|
||||||
hostList: ["Loading..."],
|
hostList: [{name: '*', visible_name: 'All'}],
|
||||||
applicationList: ["Loading..."],
|
applicationList: [{name: '*', visible_name: 'All'}],
|
||||||
itemList: ["Loading..."]
|
itemList: [{name: 'All'}]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update host group, host, application and item lists
|
// Update host group, host, application and item lists
|
||||||
@@ -120,10 +120,9 @@ function (angular, _) {
|
|||||||
* Update list of host groups
|
* Update list of host groups
|
||||||
*/
|
*/
|
||||||
$scope.updateGroupList = function() {
|
$scope.updateGroupList = function() {
|
||||||
$scope.metric.groupList = [{name: '*', visible_name: 'All'}];
|
|
||||||
addTemplatedVariables($scope.metric.groupList);
|
|
||||||
|
|
||||||
$scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
|
$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);
|
$scope.metric.groupList = $scope.metric.groupList.concat(groups);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -132,51 +131,54 @@ function (angular, _) {
|
|||||||
* Update list of hosts
|
* Update list of hosts
|
||||||
*/
|
*/
|
||||||
$scope.updateHostList = function() {
|
$scope.updateHostList = function() {
|
||||||
$scope.metric.hostList = [{name: '*', visible_name: 'All'}];
|
|
||||||
addTemplatedVariables($scope.metric.hostList);
|
|
||||||
|
|
||||||
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;
|
||||||
$scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) {
|
if (groups) {
|
||||||
$scope.metric.hostList = $scope.metric.hostList.concat(hosts);
|
$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);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update list of host applications
|
* Update list of host applications
|
||||||
*/
|
*/
|
||||||
$scope.updateAppList = function() {
|
$scope.updateAppList = function() {
|
||||||
$scope.metric.applicationList = [{name: '*', visible_name: 'All'}];
|
|
||||||
addTemplatedVariables($scope.metric.applicationList);
|
|
||||||
|
|
||||||
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;
|
||||||
$scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
|
if (groups && hosts) {
|
||||||
apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
|
$scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
|
||||||
return {name: appname};
|
apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
|
||||||
|
return {name: appname};
|
||||||
|
});
|
||||||
|
$scope.metric.applicationList = [{name: '*', visible_name: 'All'}];
|
||||||
|
addTemplatedVariables($scope.metric.applicationList);
|
||||||
|
$scope.metric.applicationList = $scope.metric.applicationList.concat(apps);
|
||||||
});
|
});
|
||||||
$scope.metric.applicationList = $scope.metric.applicationList.concat(apps);
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update list of items
|
* Update list of items
|
||||||
*/
|
*/
|
||||||
$scope.updateItemList = function() {
|
$scope.updateItemList = function() {
|
||||||
$scope.metric.itemList = [{name: 'All'}];
|
|
||||||
addTemplatedVariables($scope.metric.itemList);
|
|
||||||
|
|
||||||
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;
|
var apps = $scope.target.application ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
|
||||||
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
|
if (groups && hosts && apps) {
|
||||||
// Show only unique item names
|
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
|
||||||
var uniq_items = _.map(_.uniq(items, function (item) {
|
// Show only unique item names
|
||||||
return zabbixHelperSrv.expandItemName(item);
|
var uniq_items = _.map(_.uniq(items, function (item) {
|
||||||
}), function (item) {
|
return zabbixHelperSrv.expandItemName(item);
|
||||||
return {name: 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);
|
||||||
});
|
});
|
||||||
$scope.metric.itemList = $scope.metric.itemList.concat(uniq_items);
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -117,6 +117,42 @@ function (angular, _) {
|
|||||||
// API method wrappers //
|
// API method wrappers //
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request version of the Zabbix API.
|
||||||
|
*
|
||||||
|
* @return {string} Zabbix API version
|
||||||
|
*/
|
||||||
|
p.getZabbixAPIVersion = function() {
|
||||||
|
var options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
url: this.url,
|
||||||
|
data: {
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
method: 'apiinfo.version',
|
||||||
|
params: [],
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.basicAuth || this.withCredentials) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
}
|
||||||
|
if (this.basicAuth) {
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
options.headers.Authorization = this.basicAuth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return backendSrv.datasourceRequest(options).then(function (result) {
|
||||||
|
if (!result.data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return result.data.result;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform history query from Zabbix API
|
* Perform history query from Zabbix API
|
||||||
*
|
*
|
||||||
@@ -303,7 +339,7 @@ function (angular, _) {
|
|||||||
var params = {
|
var params = {
|
||||||
output: ['name']
|
output: ['name']
|
||||||
};
|
};
|
||||||
if (group[0] !== '*') {
|
if (group && group[0] !== '*') {
|
||||||
params.filter = {
|
params.filter = {
|
||||||
name: group
|
name: group
|
||||||
};
|
};
|
||||||
@@ -338,7 +374,7 @@ function (angular, _) {
|
|||||||
var params = {
|
var params = {
|
||||||
output: ['host', 'name']
|
output: ['host', 'name']
|
||||||
};
|
};
|
||||||
if (hostnames[0] !== '*') {
|
if (hostnames && hostnames[0] !== '*') {
|
||||||
params.filter = {
|
params.filter = {
|
||||||
name: hostnames
|
name: hostnames
|
||||||
};
|
};
|
||||||
@@ -356,7 +392,7 @@ function (angular, _) {
|
|||||||
var params = {
|
var params = {
|
||||||
output: ['name']
|
output: ['name']
|
||||||
};
|
};
|
||||||
if (application[0] !== '*') {
|
if (application && application[0] !== '*') {
|
||||||
params.filter = {
|
params.filter = {
|
||||||
name: application
|
name: application
|
||||||
};
|
};
|
||||||
@@ -385,7 +421,7 @@ function (angular, _) {
|
|||||||
promises.push(this.getGroupByName(groups));
|
promises.push(this.getGroupByName(groups));
|
||||||
}
|
}
|
||||||
// Get applicationids from names
|
// Get applicationids from names
|
||||||
if (apps) {
|
if (apps && apps[0] !== '*') {
|
||||||
promises.push(this.getAppByName(apps));
|
promises.push(this.getAppByName(apps));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +441,7 @@ function (angular, _) {
|
|||||||
return object.hostid;
|
return object.hostid;
|
||||||
}), 'hostid');
|
}), 'hostid');
|
||||||
}
|
}
|
||||||
if (apps) {
|
if (apps && apps[0] !== '*') {
|
||||||
applicationids = _.map(_.filter(results, function (object) {
|
applicationids = _.map(_.filter(results, function (object) {
|
||||||
return object.applicationid;
|
return object.applicationid;
|
||||||
}), 'applicationid');
|
}), 'applicationid');
|
||||||
|
|||||||
Reference in New Issue
Block a user