diff --git a/plugins/datasource-zabbix/datasource.js b/plugins/datasource-zabbix/datasource.js index 06a3b1a..1108c7b 100644 --- a/plugins/datasource-zabbix/datasource.js +++ b/plugins/datasource-zabbix/datasource.js @@ -10,52 +10,44 @@ define([ function (angular, _, dateMath) { '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; - /** - * Datasource initialization. Calls when you refresh page, add - * or modify datasource. - * - * @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 (instanceSettings.jsonData) { + this.username = instanceSettings.jsonData.username; + this.password = instanceSettings.jsonData.password; - if (datasource.jsonData) { - this.username = datasource.jsonData.username; - this.password = datasource.jsonData.password; + // Use trends instead history since specified time + this.trends = instanceSettings.jsonData.trends; + this.trendsFrom = instanceSettings.jsonData.trendsFrom || '7d'; - // Use trends instead history since specified time - this.trends = datasource.jsonData.trends; - this.trendsFrom = datasource.jsonData.trendsFrom || '7d'; - - // Limit metrics per panel for templated request - 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 - this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials); + // Limit metrics per panel for templated request + this.limitmetrics = instanceSettings.jsonData.limitMetrics || 100; + } else { + // DEPRECATED. Loads settings from plugin.json file. + // For backward compatibility only. + this.username = instanceSettings.meta.username; + this.password = instanceSettings.meta.password; + this.trends = instanceSettings.meta.trends; + this.trendsFrom = instanceSettings.meta.trendsFrom || '7d'; + this.limitmetrics = instanceSettings.meta.limitmetrics || 100; } + // Initialize Zabbix API + 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() { + this.testDatasource = function() { var self = this; return this.zabbixAPI.getZabbixAPIVersion().then(function (apiVersion) { return self.zabbixAPI.performZabbixAPILogin().then(function (auth) { @@ -91,7 +83,7 @@ function (angular, _, dateMath) { * @return {Object} Grafana metrics object with timeseries data * for each target. */ - ZabbixAPIDatasource.prototype.query = function(options) { + this.query = function(options) { // get from & to in seconds 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 * of metrics in "{metric1,metcic2,...,metricN}" format. */ - ZabbixAPIDatasource.prototype.metricFindQuery = function (query) { + this.metricFindQuery = function (query) { // Split query. Query structure: // group.host.app.item var parts = []; @@ -351,7 +343,7 @@ function (angular, _, dateMath) { // Annotations // ///////////////// - ZabbixAPIDatasource.prototype.annotationQuery = function(options) { + this.annotationQuery = function(options) { var from = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000); var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000); var annotation = annotation; @@ -427,6 +419,8 @@ function (angular, _, dateMath) { }); }; - return ZabbixAPIDatasource; - }); + } + + return ZabbixAPIDatasource; + }); diff --git a/plugins/datasource-zabbix/module.js b/plugins/datasource-zabbix/module.js new file mode 100644 index 0000000..ce52d1c --- /dev/null +++ b/plugins/datasource-zabbix/module.js @@ -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, + }; +}); diff --git a/plugins/datasource-zabbix/plugin.json b/plugins/datasource-zabbix/plugin.json index fac427d..0e75c1b 100644 --- a/plugins/datasource-zabbix/plugin.json +++ b/plugins/datasource-zabbix/plugin.json @@ -1,20 +1,11 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "Zabbix", + "id": "zabbix", - "type": "zabbix", - "serviceName": "ZabbixAPIDatasource", + "module": "plugins/zabbix/module", - "module": "plugins/zabbix/datasource", - - "partials": { - "config": "public/plugins/zabbix/partials/config.html" - }, - - "staticRoot": { - "url": "zabbix", - "path": "." - }, + "staticRoot": ".", "metrics": true, "annotations": true diff --git a/plugins/panel-triggers/module.js b/plugins/panel-triggers/module.js index e24448a..2b6b076 100644 --- a/plugins/panel-triggers/module.js +++ b/plugins/panel-triggers/module.js @@ -26,15 +26,8 @@ function (angular, app, _, $, config, PanelMeta) { var module = angular.module('grafana.panels.triggers', []); app.useModule(module); - module.directive('grafanaPanelTriggers', function() { - return { - controller: 'TriggersPanelCtrl', - templateUrl: 'public/plugins/triggers/module.html', - }; - }); - - module.controller('TriggersPanelCtrl', function($q, $scope, $element, datasourceSrv, panelSrv, - templateSrv, zabbixHelperSrv, popoverSrv) { + /** @ngInject */ + function TriggerPanelCtrl($q, $scope, $element, datasourceSrv, panelSrv, templateSrv, zabbixHelperSrv, popoverSrv) { $scope.panelMeta = new PanelMeta({ panelName: 'Zabbix triggers', @@ -299,5 +292,17 @@ function (angular, app, _, $, config, PanelMeta) { }; $scope.init(); - }); + } + + function triggerPanelDirective() { + return { + controller: TriggerPanelCtrl, + templateUrl: 'public/plugins/triggers/module.html', + }; + } + + return { + panel: triggerPanelDirective + }; + }); diff --git a/plugins/panel-triggers/plugin.json b/plugins/panel-triggers/plugin.json index db5b6b4..191cacd 100644 --- a/plugins/panel-triggers/plugin.json +++ b/plugins/panel-triggers/plugin.json @@ -1,13 +1,8 @@ { - "pluginType": "panel", - + "type": "panel", "name": "Zabbix triggers", - "type": "triggers", + "id": "triggers", "module": "plugins/triggers/module", - - "staticRoot": { - "url": "triggers", - "path": "." - } + "staticRoot": "." }