Working on #142 - fixed plugin.json and
datasource constructor (module.js).
This commit is contained in:
@@ -10,52 +10,44 @@ define([
|
|||||||
function (angular, _, dateMath) {
|
function (angular, _, dateMath) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var module = angular.module('grafana.services');
|
/** @ngInject */
|
||||||
|
function ZabbixAPIDatasource(instanceSettings, $q, backendSrv, templateSrv, alertSrv,
|
||||||
|
ZabbixAPI, zabbixHelperSrv) {
|
||||||
|
|
||||||
module.factory('ZabbixAPIDatasource', function($q, backendSrv, templateSrv, alertSrv, ZabbixAPI, zabbixHelperSrv) {
|
this.name = instanceSettings.name;
|
||||||
|
this.url = instanceSettings.url;
|
||||||
|
this.basicAuth = instanceSettings.basicAuth;
|
||||||
|
this.withCredentials = instanceSettings.withCredentials;
|
||||||
|
|
||||||
/**
|
if (instanceSettings.jsonData) {
|
||||||
* Datasource initialization. Calls when you refresh page, add
|
this.username = instanceSettings.jsonData.username;
|
||||||
* or modify datasource.
|
this.password = instanceSettings.jsonData.password;
|
||||||
*
|
|
||||||
* @param {Object} datasource Grafana datasource object.
|
|
||||||
*/
|
|
||||||
function ZabbixAPIDatasource(datasource) {
|
|
||||||
this.name = datasource.name;
|
|
||||||
this.url = datasource.url;
|
|
||||||
this.basicAuth = datasource.basicAuth;
|
|
||||||
this.withCredentials = datasource.withCredentials;
|
|
||||||
|
|
||||||
if (datasource.jsonData) {
|
// Use trends instead history since specified time
|
||||||
this.username = datasource.jsonData.username;
|
this.trends = instanceSettings.jsonData.trends;
|
||||||
this.password = datasource.jsonData.password;
|
this.trendsFrom = instanceSettings.jsonData.trendsFrom || '7d';
|
||||||
|
|
||||||
// Use trends instead history since specified time
|
// Limit metrics per panel for templated request
|
||||||
this.trends = datasource.jsonData.trends;
|
this.limitmetrics = instanceSettings.jsonData.limitMetrics || 100;
|
||||||
this.trendsFrom = datasource.jsonData.trendsFrom || '7d';
|
} else {
|
||||||
|
// DEPRECATED. Loads settings from plugin.json file.
|
||||||
// Limit metrics per panel for templated request
|
// For backward compatibility only.
|
||||||
this.limitmetrics = datasource.jsonData.limitMetrics || 100;
|
this.username = instanceSettings.meta.username;
|
||||||
} else {
|
this.password = instanceSettings.meta.password;
|
||||||
// DEPRECATED. Loads settings from plugin.json file.
|
this.trends = instanceSettings.meta.trends;
|
||||||
// For backward compatibility only.
|
this.trendsFrom = instanceSettings.meta.trendsFrom || '7d';
|
||||||
this.username = datasource.meta.username;
|
this.limitmetrics = instanceSettings.meta.limitmetrics || 100;
|
||||||
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
|
|
||||||
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize Zabbix API
|
||||||
|
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test connection to Zabbix API
|
* Test connection to Zabbix API
|
||||||
*
|
*
|
||||||
* @return {object} Connection status and Zabbix API version
|
* @return {object} Connection status and Zabbix API version
|
||||||
*/
|
*/
|
||||||
ZabbixAPIDatasource.prototype.testDatasource = function() {
|
this.testDatasource = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.zabbixAPI.getZabbixAPIVersion().then(function (apiVersion) {
|
return this.zabbixAPI.getZabbixAPIVersion().then(function (apiVersion) {
|
||||||
return self.zabbixAPI.performZabbixAPILogin().then(function (auth) {
|
return self.zabbixAPI.performZabbixAPILogin().then(function (auth) {
|
||||||
@@ -91,7 +83,7 @@ function (angular, _, dateMath) {
|
|||||||
* @return {Object} Grafana metrics object with timeseries data
|
* @return {Object} Grafana metrics object with timeseries data
|
||||||
* for each target.
|
* for each target.
|
||||||
*/
|
*/
|
||||||
ZabbixAPIDatasource.prototype.query = function(options) {
|
this.query = function(options) {
|
||||||
|
|
||||||
// get from & to in seconds
|
// get from & to in seconds
|
||||||
var from = Math.ceil(dateMath.parse(options.range.from) / 1000);
|
var from = Math.ceil(dateMath.parse(options.range.from) / 1000);
|
||||||
@@ -277,7 +269,7 @@ function (angular, _, dateMath) {
|
|||||||
* @return {string} Metric name - group, host, app or item or list
|
* @return {string} Metric name - group, host, app or item or list
|
||||||
* of metrics in "{metric1,metcic2,...,metricN}" format.
|
* of metrics in "{metric1,metcic2,...,metricN}" format.
|
||||||
*/
|
*/
|
||||||
ZabbixAPIDatasource.prototype.metricFindQuery = function (query) {
|
this.metricFindQuery = function (query) {
|
||||||
// Split query. Query structure:
|
// Split query. Query structure:
|
||||||
// group.host.app.item
|
// group.host.app.item
|
||||||
var parts = [];
|
var parts = [];
|
||||||
@@ -351,7 +343,7 @@ function (angular, _, dateMath) {
|
|||||||
// Annotations //
|
// Annotations //
|
||||||
/////////////////
|
/////////////////
|
||||||
|
|
||||||
ZabbixAPIDatasource.prototype.annotationQuery = function(options) {
|
this.annotationQuery = function(options) {
|
||||||
var from = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
var from = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
||||||
var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||||
var annotation = annotation;
|
var annotation = annotation;
|
||||||
@@ -427,6 +419,8 @@ function (angular, _, dateMath) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return ZabbixAPIDatasource;
|
}
|
||||||
});
|
|
||||||
|
return ZabbixAPIDatasource;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
30
plugins/datasource-zabbix/module.js
Normal file
30
plugins/datasource-zabbix/module.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
define([
|
||||||
|
'./datasource',
|
||||||
|
],
|
||||||
|
function (ZabbixAPIDatasource) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
function metricsQueryEditor() {
|
||||||
|
return {controller: 'ZabbixAPIQueryCtrl', templateUrl: 'public/plugins/zabbix/partials/query.editor.html'};
|
||||||
|
}
|
||||||
|
|
||||||
|
function metricsQueryOptions() {
|
||||||
|
return {templateUrl: 'public/plugins/zabbix/partials/query.options.html'};
|
||||||
|
}
|
||||||
|
|
||||||
|
function annotationsQueryEditor() {
|
||||||
|
return {templateUrl: 'public/plugins/zabbix/partials/annotations.editor.html'};
|
||||||
|
}
|
||||||
|
|
||||||
|
function configView() {
|
||||||
|
return {templateUrl: 'public/plugins/zabbix/partials/config.html'};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
Datasource: ZabbixAPIDatasource,
|
||||||
|
configView: configView,
|
||||||
|
annotationsQueryEditor: annotationsQueryEditor,
|
||||||
|
metricsQueryEditor: metricsQueryEditor,
|
||||||
|
metricsQueryOptions: metricsQueryOptions,
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -1,20 +1,11 @@
|
|||||||
{
|
{
|
||||||
"pluginType": "datasource",
|
"type": "datasource",
|
||||||
"name": "Zabbix",
|
"name": "Zabbix",
|
||||||
|
"id": "zabbix",
|
||||||
|
|
||||||
"type": "zabbix",
|
"module": "plugins/zabbix/module",
|
||||||
"serviceName": "ZabbixAPIDatasource",
|
|
||||||
|
|
||||||
"module": "plugins/zabbix/datasource",
|
"staticRoot": ".",
|
||||||
|
|
||||||
"partials": {
|
|
||||||
"config": "public/plugins/zabbix/partials/config.html"
|
|
||||||
},
|
|
||||||
|
|
||||||
"staticRoot": {
|
|
||||||
"url": "zabbix",
|
|
||||||
"path": "."
|
|
||||||
},
|
|
||||||
|
|
||||||
"metrics": true,
|
"metrics": true,
|
||||||
"annotations": true
|
"annotations": true
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
{
|
{
|
||||||
"pluginType": "panel",
|
"type": "panel",
|
||||||
|
|
||||||
"name": "Zabbix triggers",
|
"name": "Zabbix triggers",
|
||||||
"type": "triggers",
|
"id": "triggers",
|
||||||
|
|
||||||
"module": "plugins/triggers/module",
|
"module": "plugins/triggers/module",
|
||||||
|
"staticRoot": "."
|
||||||
"staticRoot": {
|
|
||||||
"url": "triggers",
|
|
||||||
"path": "."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user