Fix reloading query editor with no target's info. Some refactoring.
This commit is contained in:
@@ -14,16 +14,19 @@ function (angular, _, kbn) {
|
|||||||
function ZabbixAPIDatasource(datasource) {
|
function ZabbixAPIDatasource(datasource) {
|
||||||
this.name = datasource.name;
|
this.name = datasource.name;
|
||||||
this.type = 'ZabbixAPIDatasource';
|
this.type = 'ZabbixAPIDatasource';
|
||||||
this.supportMetrics = true;
|
|
||||||
this.url = datasource.url;
|
this.url = datasource.url;
|
||||||
this.username = datasource.username;
|
this.username = datasource.username;
|
||||||
this.password = datasource.password;
|
this.password = datasource.password;
|
||||||
|
|
||||||
// No datapoints limit by default
|
// No datapoints limit by default
|
||||||
this.limitmetrics = datasource.limitmetrics || 0;
|
this.limitmetrics = datasource.limitmetrics || 0;
|
||||||
|
|
||||||
this.partials = datasource.partials || 'plugins/datasource/zabbix/partials';
|
this.partials = datasource.partials || 'plugins/datasource/zabbix/partials';
|
||||||
this.editorSrc = this.partials + '/query.editor.html';
|
this.editorSrc = this.partials + '/query.editor.html';
|
||||||
this.annotationEditorSrc = this.partials + '/annotations.editor.html';
|
this.annotationEditorSrc = this.partials + '/annotations.editor.html';
|
||||||
|
|
||||||
|
this.supportMetrics = true;
|
||||||
this.supportAnnotations = true;
|
this.supportAnnotations = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +133,38 @@ function (angular, _, kbn) {
|
|||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// Request data from Zabbix API
|
||||||
|
ZabbixAPIDatasource.prototype.doZabbixAPIRequest = function(request_data) {
|
||||||
|
var options = {
|
||||||
|
method: 'POST',
|
||||||
|
url: this.url,
|
||||||
|
data: request_data
|
||||||
|
};
|
||||||
|
|
||||||
|
var performedQuery;
|
||||||
|
|
||||||
|
// Check authorization first
|
||||||
|
if (!this.auth) {
|
||||||
|
var self = this;
|
||||||
|
performedQuery = this.performZabbixAPILogin().then(function (response) {
|
||||||
|
self.auth = response;
|
||||||
|
options.data.auth = response;
|
||||||
|
return $http(options);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
performedQuery = $http(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle response
|
||||||
|
return performedQuery.then(function (response) {
|
||||||
|
if (!response.data) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return response.data.result;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform time series query to Zabbix API
|
* Perform time series query to Zabbix API
|
||||||
*
|
*
|
||||||
@@ -186,6 +221,7 @@ function (angular, _, kbn) {
|
|||||||
id: 1
|
id: 1
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return $http(options).then(function (result) {
|
return $http(options).then(function (result) {
|
||||||
if (!result.data) {
|
if (!result.data) {
|
||||||
return null;
|
return null;
|
||||||
@@ -197,10 +233,7 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
// Get the list of host groups
|
// Get the list of host groups
|
||||||
ZabbixAPIDatasource.prototype.performHostGroupSuggestQuery = function() {
|
ZabbixAPIDatasource.prototype.performHostGroupSuggestQuery = function() {
|
||||||
var options = {
|
var data = {
|
||||||
url : this.url,
|
|
||||||
method : 'POST',
|
|
||||||
data: {
|
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'hostgroup.get',
|
method: 'hostgroup.get',
|
||||||
params: {
|
params: {
|
||||||
@@ -209,23 +242,15 @@ function (angular, _, kbn) {
|
|||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: this.auth,
|
||||||
id: 1
|
id: 1
|
||||||
},
|
|
||||||
};
|
};
|
||||||
return $http(options).then(function (result) {
|
|
||||||
if (!result.data) {
|
return this.doZabbixAPIRequest(data);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return result.data.result;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of hosts
|
// Get the list of hosts
|
||||||
ZabbixAPIDatasource.prototype.performHostSuggestQuery = function(groupid) {
|
ZabbixAPIDatasource.prototype.performHostSuggestQuery = function(groupid) {
|
||||||
var options = {
|
var data = {
|
||||||
url : this.url,
|
|
||||||
method : 'POST',
|
|
||||||
data: {
|
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'host.get',
|
method: 'host.get',
|
||||||
params: {
|
params: {
|
||||||
@@ -234,26 +259,18 @@ function (angular, _, kbn) {
|
|||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: this.auth,
|
||||||
id: 1
|
id: 1
|
||||||
},
|
|
||||||
};
|
};
|
||||||
if (groupid) {
|
if (groupid) {
|
||||||
options.data.params.groupids = groupid;
|
data.params.groupids = groupid;
|
||||||
}
|
}
|
||||||
return $http(options).then(function (result) {
|
|
||||||
if (!result.data) {
|
return this.doZabbixAPIRequest(data);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return result.data.result;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of applications
|
// Get the list of applications
|
||||||
ZabbixAPIDatasource.prototype.performAppSuggestQuery = function(hostid) {
|
ZabbixAPIDatasource.prototype.performAppSuggestQuery = function(hostid) {
|
||||||
var options = {
|
var data = {
|
||||||
url : this.url,
|
|
||||||
method : 'POST',
|
|
||||||
data: {
|
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'application.get',
|
method: 'application.get',
|
||||||
params: {
|
params: {
|
||||||
@@ -263,23 +280,15 @@ function (angular, _, kbn) {
|
|||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: this.auth,
|
||||||
id: 1
|
id: 1
|
||||||
},
|
|
||||||
};
|
};
|
||||||
return $http(options).then(function (result) {
|
|
||||||
if (!result.data) {
|
return this.doZabbixAPIRequest(data);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return result.data.result;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of host items
|
// Get the list of host items
|
||||||
ZabbixAPIDatasource.prototype.performItemSuggestQuery = function(hostid, applicationid) {
|
ZabbixAPIDatasource.prototype.performItemSuggestQuery = function(hostid, applicationid) {
|
||||||
var options = {
|
var data = {
|
||||||
url : this.url,
|
|
||||||
method : 'POST',
|
|
||||||
data: {
|
|
||||||
jsonrpc: '2.0',
|
jsonrpc: '2.0',
|
||||||
method: 'item.get',
|
method: 'item.get',
|
||||||
params: {
|
params: {
|
||||||
@@ -289,18 +298,13 @@ function (angular, _, kbn) {
|
|||||||
},
|
},
|
||||||
auth: this.auth,
|
auth: this.auth,
|
||||||
id: 1
|
id: 1
|
||||||
},
|
|
||||||
};
|
};
|
||||||
// If application selected return only relative items
|
// If application selected return only relative items
|
||||||
if (applicationid) {
|
if (applicationid) {
|
||||||
options.data.params.applicationids = applicationid;
|
data.params.applicationids = applicationid;
|
||||||
}
|
}
|
||||||
return $http(options).then(function (result) {
|
|
||||||
if (!result.data) {
|
return this.doZabbixAPIRequest(data);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return result.data.result;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ function (angular, _) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Update host group, host, application and item lists
|
// Update host group, host, application and item lists
|
||||||
//$scope.updateHostGroupList();
|
$scope.updateHostGroupList();
|
||||||
$scope.updateHostList();
|
$scope.updateHostList();
|
||||||
if ($scope.target.host) {
|
if ($scope.target.host) {
|
||||||
$scope.updateAppList($scope.target.host.hostid);
|
$scope.updateAppList($scope.target.host.hostid);
|
||||||
|
|||||||
Reference in New Issue
Block a user