Move alerting functions into zabbixAlertingSrv.
This commit is contained in:
85
dist/datasource-zabbix/datasource.js
vendored
85
dist/datasource-zabbix/datasource.js
vendored
@@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
System.register(['lodash', 'jquery', 'app/core/utils/datemath', './utils', './migrations', './metricFunctions', './dataProcessor', './responseHandler', './zabbix.js', './zabbixAPICore.service.js'], function (_export, _context) {
|
System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations', './metricFunctions', './dataProcessor', './responseHandler', './zabbix.js', './zabbixAlerting.service.js', './zabbixAPICore.service.js'], function (_export, _context) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _, $, dateMath, utils, migrations, metricFunctions, dataProcessor, responseHandler, ZabbixAPIError, _slicedToArray, _createClass, ZabbixAPIDatasource;
|
var _, dateMath, utils, migrations, metricFunctions, dataProcessor, responseHandler, ZabbixAPIError, _slicedToArray, _createClass, ZabbixAPIDatasource;
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) {
|
function _classCallCheck(instance, Constructor) {
|
||||||
if (!(instance instanceof Constructor)) {
|
if (!(instance instanceof Constructor)) {
|
||||||
@@ -119,8 +119,6 @@ System.register(['lodash', 'jquery', 'app/core/utils/datemath', './utils', './mi
|
|||||||
return {
|
return {
|
||||||
setters: [function (_lodash) {
|
setters: [function (_lodash) {
|
||||||
_ = _lodash.default;
|
_ = _lodash.default;
|
||||||
}, function (_jquery) {
|
|
||||||
$ = _jquery.default;
|
|
||||||
}, function (_appCoreUtilsDatemath) {
|
}, function (_appCoreUtilsDatemath) {
|
||||||
dateMath = _appCoreUtilsDatemath;
|
dateMath = _appCoreUtilsDatemath;
|
||||||
}, function (_utils) {
|
}, function (_utils) {
|
||||||
@@ -133,7 +131,7 @@ System.register(['lodash', 'jquery', 'app/core/utils/datemath', './utils', './mi
|
|||||||
dataProcessor = _dataProcessor.default;
|
dataProcessor = _dataProcessor.default;
|
||||||
}, function (_responseHandler) {
|
}, function (_responseHandler) {
|
||||||
responseHandler = _responseHandler.default;
|
responseHandler = _responseHandler.default;
|
||||||
}, function (_zabbixJs) {}, function (_zabbixAPICoreServiceJs) {
|
}, function (_zabbixJs) {}, function (_zabbixAlertingServiceJs) {}, function (_zabbixAPICoreServiceJs) {
|
||||||
ZabbixAPIError = _zabbixAPICoreServiceJs.ZabbixAPIError;
|
ZabbixAPIError = _zabbixAPICoreServiceJs.ZabbixAPIError;
|
||||||
}],
|
}],
|
||||||
execute: function () {
|
execute: function () {
|
||||||
@@ -196,12 +194,13 @@ System.register(['lodash', 'jquery', 'app/core/utils/datemath', './utils', './mi
|
|||||||
_export('ZabbixAPIDatasource', ZabbixAPIDatasource = function () {
|
_export('ZabbixAPIDatasource', ZabbixAPIDatasource = function () {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, Zabbix) {
|
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, zabbixAlertingSrv, Zabbix) {
|
||||||
_classCallCheck(this, ZabbixAPIDatasource);
|
_classCallCheck(this, ZabbixAPIDatasource);
|
||||||
|
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
this.alertSrv = alertSrv;
|
||||||
this.dashboardSrv = dashboardSrv;
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// General data source settings
|
// General data source settings
|
||||||
this.name = instanceSettings.name;
|
this.name = instanceSettings.name;
|
||||||
@@ -256,11 +255,12 @@ System.register(['lodash', 'jquery', 'app/core/utils/datemath', './utils', './mi
|
|||||||
// Get alerts for current panel
|
// Get alerts for current panel
|
||||||
if (this.alertingEnabled) {
|
if (this.alertingEnabled) {
|
||||||
this.alertQuery(options).then(function (alert) {
|
this.alertQuery(options).then(function (alert) {
|
||||||
_this.setPanelAlertState(options.panelId, alert.state);
|
_this.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
||||||
|
|
||||||
|
_this.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
||||||
if (_this.addThresholds) {
|
if (_this.addThresholds) {
|
||||||
_.forEach(alert.thresholds, function (threshold) {
|
_.forEach(alert.thresholds, function (threshold) {
|
||||||
_this.setPanelThreshold(options.panelId, threshold);
|
_this.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -631,75 +631,6 @@ System.register(['lodash', 'jquery', 'app/core/utils/datemath', './utils', './mi
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
key: 'setPanelAlertState',
|
|
||||||
value: function setPanelAlertState(panelId, alertState) {
|
|
||||||
var panelContainers = _.filter($('.panel-container'), function (elem) {
|
|
||||||
return elem.clientHeight && elem.clientWidth;
|
|
||||||
});
|
|
||||||
|
|
||||||
var panelModels = this.getPanelModels();
|
|
||||||
var panelIndex = _.findIndex(panelModels, function (panel) {
|
|
||||||
return panel.id === panelId;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (panelIndex >= 0) {
|
|
||||||
var alertClass = "panel-has-alert panel-alert-state--ok panel-alert-state--alerting";
|
|
||||||
$(panelContainers[panelIndex]).removeClass(alertClass);
|
|
||||||
|
|
||||||
if (alertState) {
|
|
||||||
if (alertState === 'alerting') {
|
|
||||||
alertClass = "panel-has-alert panel-alert-state--" + alertState;
|
|
||||||
$(panelContainers[panelIndex]).addClass(alertClass);
|
|
||||||
}
|
|
||||||
if (alertState === 'ok') {
|
|
||||||
alertClass = "panel-alert-state--" + alertState;
|
|
||||||
$(panelContainers[panelIndex]).addClass(alertClass);
|
|
||||||
$(panelContainers[panelIndex]).removeClass("panel-has-alert");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: 'getPanelModels',
|
|
||||||
value: function getPanelModels() {
|
|
||||||
return _.flatten(_.map(this.dashboardSrv.dash.rows, function (row) {
|
|
||||||
if (row.collapse) {
|
|
||||||
return [];
|
|
||||||
} else {
|
|
||||||
return row.panels;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: 'getPanelModel',
|
|
||||||
value: function getPanelModel(panelId) {
|
|
||||||
var panelModels = this.getPanelModels();
|
|
||||||
|
|
||||||
return _.find(panelModels, function (panel) {
|
|
||||||
return panel.id === panelId;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: 'setPanelThreshold',
|
|
||||||
value: function setPanelThreshold(panelId, threshold) {
|
|
||||||
var panel = this.getPanelModel(panelId);
|
|
||||||
var containsThreshold = _.find(panel.thresholds, { value: threshold });
|
|
||||||
|
|
||||||
if (panel && !containsThreshold) {
|
|
||||||
var thresholdOptions = {
|
|
||||||
colorMode: "custom",
|
|
||||||
fill: false,
|
|
||||||
line: true,
|
|
||||||
lineColor: "rgb(255, 0, 0)",
|
|
||||||
op: "gt",
|
|
||||||
value: threshold,
|
|
||||||
source: "zabbix"
|
|
||||||
};
|
|
||||||
|
|
||||||
panel.thresholds.push(thresholdOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
key: 'replaceTargetVariables',
|
key: 'replaceTargetVariables',
|
||||||
value: function replaceTargetVariables(target, options) {
|
value: function replaceTargetVariables(target, options) {
|
||||||
|
|||||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
139
dist/datasource-zabbix/zabbixAlerting.service.js
vendored
Normal file
139
dist/datasource-zabbix/zabbixAlerting.service.js
vendored
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
System.register(['lodash', 'jquery', 'angular'], function (_export, _context) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var _, $, angular, _createClass, ZabbixAlertingService;
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) {
|
||||||
|
if (!(instance instanceof Constructor)) {
|
||||||
|
throw new TypeError("Cannot call a class as a function");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
setters: [function (_lodash) {
|
||||||
|
_ = _lodash.default;
|
||||||
|
}, function (_jquery) {
|
||||||
|
$ = _jquery.default;
|
||||||
|
}, function (_angular) {
|
||||||
|
angular = _angular.default;
|
||||||
|
}],
|
||||||
|
execute: function () {
|
||||||
|
_createClass = function () {
|
||||||
|
function defineProperties(target, props) {
|
||||||
|
for (var i = 0; i < props.length; i++) {
|
||||||
|
var descriptor = props[i];
|
||||||
|
descriptor.enumerable = descriptor.enumerable || false;
|
||||||
|
descriptor.configurable = true;
|
||||||
|
if ("value" in descriptor) descriptor.writable = true;
|
||||||
|
Object.defineProperty(target, descriptor.key, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return function (Constructor, protoProps, staticProps) {
|
||||||
|
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||||
|
if (staticProps) defineProperties(Constructor, staticProps);
|
||||||
|
return Constructor;
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
|
||||||
|
ZabbixAlertingService = function () {
|
||||||
|
|
||||||
|
/** @ngInject */
|
||||||
|
function ZabbixAlertingService(dashboardSrv) {
|
||||||
|
_classCallCheck(this, ZabbixAlertingService);
|
||||||
|
|
||||||
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
}
|
||||||
|
|
||||||
|
_createClass(ZabbixAlertingService, [{
|
||||||
|
key: 'setPanelAlertState',
|
||||||
|
value: function setPanelAlertState(panelId, alertState) {
|
||||||
|
var panelContainers = _.filter($('.panel-container'), function (elem) {
|
||||||
|
return elem.clientHeight && elem.clientWidth;
|
||||||
|
});
|
||||||
|
|
||||||
|
var panelModels = this.getPanelModels();
|
||||||
|
var panelIndex = _.findIndex(panelModels, function (panel) {
|
||||||
|
return panel.id === panelId;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (panelIndex >= 0) {
|
||||||
|
var alertClass = "panel-has-alert panel-alert-state--ok panel-alert-state--alerting";
|
||||||
|
$(panelContainers[panelIndex]).removeClass(alertClass);
|
||||||
|
|
||||||
|
if (alertState) {
|
||||||
|
if (alertState === 'alerting') {
|
||||||
|
alertClass = "panel-has-alert panel-alert-state--" + alertState;
|
||||||
|
$(panelContainers[panelIndex]).addClass(alertClass);
|
||||||
|
}
|
||||||
|
if (alertState === 'ok') {
|
||||||
|
alertClass = "panel-alert-state--" + alertState;
|
||||||
|
$(panelContainers[panelIndex]).addClass(alertClass);
|
||||||
|
$(panelContainers[panelIndex]).removeClass("panel-has-alert");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'getPanelModels',
|
||||||
|
value: function getPanelModels() {
|
||||||
|
return _.flatten(_.map(this.dashboardSrv.dash.rows, function (row) {
|
||||||
|
if (row.collapse) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
return row.panels;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'getPanelModel',
|
||||||
|
value: function getPanelModel(panelId) {
|
||||||
|
var panelModels = this.getPanelModels();
|
||||||
|
|
||||||
|
return _.find(panelModels, function (panel) {
|
||||||
|
return panel.id === panelId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'setPanelThreshold',
|
||||||
|
value: function setPanelThreshold(panelId, threshold) {
|
||||||
|
var panel = this.getPanelModel(panelId);
|
||||||
|
var containsThreshold = _.find(panel.thresholds, { value: threshold });
|
||||||
|
|
||||||
|
if (panel && panel.type === "graph" && !containsThreshold) {
|
||||||
|
var thresholdOptions = {
|
||||||
|
colorMode: "custom",
|
||||||
|
fill: false,
|
||||||
|
line: true,
|
||||||
|
lineColor: "rgb(255, 0, 0)",
|
||||||
|
op: "gt",
|
||||||
|
value: threshold,
|
||||||
|
source: "zabbix"
|
||||||
|
};
|
||||||
|
|
||||||
|
panel.thresholds.push(thresholdOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'removeZabbixThreshold',
|
||||||
|
value: function removeZabbixThreshold(panelId) {
|
||||||
|
var panel = this.getPanelModel(panelId);
|
||||||
|
|
||||||
|
if (panel && panel.type === "graph") {
|
||||||
|
panel.thresholds = _.filter(panel.thresholds, function (threshold) {
|
||||||
|
return threshold.source !== "zabbix";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return ZabbixAlertingService;
|
||||||
|
}();
|
||||||
|
|
||||||
|
angular.module('grafana.services').service('zabbixAlertingSrv', ZabbixAlertingService);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=zabbixAlerting.service.js.map
|
||||||
1
dist/datasource-zabbix/zabbixAlerting.service.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbixAlerting.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
83
dist/test/datasource-zabbix/datasource.js
vendored
83
dist/test/datasource-zabbix/datasource.js
vendored
@@ -13,10 +13,6 @@ var _lodash = require('lodash');
|
|||||||
|
|
||||||
var _lodash2 = _interopRequireDefault(_lodash);
|
var _lodash2 = _interopRequireDefault(_lodash);
|
||||||
|
|
||||||
var _jquery = require('jquery');
|
|
||||||
|
|
||||||
var _jquery2 = _interopRequireDefault(_jquery);
|
|
||||||
|
|
||||||
var _datemath = require('app/core/utils/datemath');
|
var _datemath = require('app/core/utils/datemath');
|
||||||
|
|
||||||
var dateMath = _interopRequireWildcard(_datemath);
|
var dateMath = _interopRequireWildcard(_datemath);
|
||||||
@@ -43,6 +39,8 @@ var _responseHandler2 = _interopRequireDefault(_responseHandler);
|
|||||||
|
|
||||||
require('./zabbix.js');
|
require('./zabbix.js');
|
||||||
|
|
||||||
|
require('./zabbixAlerting.service.js');
|
||||||
|
|
||||||
var _zabbixAPICoreService = require('./zabbixAPICore.service.js');
|
var _zabbixAPICoreService = require('./zabbixAPICore.service.js');
|
||||||
|
|
||||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||||
@@ -54,12 +52,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|||||||
var ZabbixAPIDatasource = function () {
|
var ZabbixAPIDatasource = function () {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, Zabbix) {
|
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, zabbixAlertingSrv, Zabbix) {
|
||||||
_classCallCheck(this, ZabbixAPIDatasource);
|
_classCallCheck(this, ZabbixAPIDatasource);
|
||||||
|
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
this.alertSrv = alertSrv;
|
||||||
this.dashboardSrv = dashboardSrv;
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// General data source settings
|
// General data source settings
|
||||||
this.name = instanceSettings.name;
|
this.name = instanceSettings.name;
|
||||||
@@ -114,11 +113,12 @@ var ZabbixAPIDatasource = function () {
|
|||||||
// Get alerts for current panel
|
// Get alerts for current panel
|
||||||
if (this.alertingEnabled) {
|
if (this.alertingEnabled) {
|
||||||
this.alertQuery(options).then(function (alert) {
|
this.alertQuery(options).then(function (alert) {
|
||||||
_this.setPanelAlertState(options.panelId, alert.state);
|
_this.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
||||||
|
|
||||||
|
_this.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
||||||
if (_this.addThresholds) {
|
if (_this.addThresholds) {
|
||||||
_lodash2.default.forEach(alert.thresholds, function (threshold) {
|
_lodash2.default.forEach(alert.thresholds, function (threshold) {
|
||||||
_this.setPanelThreshold(options.panelId, threshold);
|
_this.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -520,75 +520,6 @@ var ZabbixAPIDatasource = function () {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
key: 'setPanelAlertState',
|
|
||||||
value: function setPanelAlertState(panelId, alertState) {
|
|
||||||
var panelContainers = _lodash2.default.filter((0, _jquery2.default)('.panel-container'), function (elem) {
|
|
||||||
return elem.clientHeight && elem.clientWidth;
|
|
||||||
});
|
|
||||||
|
|
||||||
var panelModels = this.getPanelModels();
|
|
||||||
var panelIndex = _lodash2.default.findIndex(panelModels, function (panel) {
|
|
||||||
return panel.id === panelId;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (panelIndex >= 0) {
|
|
||||||
var alertClass = "panel-has-alert panel-alert-state--ok panel-alert-state--alerting";
|
|
||||||
(0, _jquery2.default)(panelContainers[panelIndex]).removeClass(alertClass);
|
|
||||||
|
|
||||||
if (alertState) {
|
|
||||||
if (alertState === 'alerting') {
|
|
||||||
alertClass = "panel-has-alert panel-alert-state--" + alertState;
|
|
||||||
(0, _jquery2.default)(panelContainers[panelIndex]).addClass(alertClass);
|
|
||||||
}
|
|
||||||
if (alertState === 'ok') {
|
|
||||||
alertClass = "panel-alert-state--" + alertState;
|
|
||||||
(0, _jquery2.default)(panelContainers[panelIndex]).addClass(alertClass);
|
|
||||||
(0, _jquery2.default)(panelContainers[panelIndex]).removeClass("panel-has-alert");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: 'getPanelModels',
|
|
||||||
value: function getPanelModels() {
|
|
||||||
return _lodash2.default.flatten(_lodash2.default.map(this.dashboardSrv.dash.rows, function (row) {
|
|
||||||
if (row.collapse) {
|
|
||||||
return [];
|
|
||||||
} else {
|
|
||||||
return row.panels;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: 'getPanelModel',
|
|
||||||
value: function getPanelModel(panelId) {
|
|
||||||
var panelModels = this.getPanelModels();
|
|
||||||
|
|
||||||
return _lodash2.default.find(panelModels, function (panel) {
|
|
||||||
return panel.id === panelId;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: 'setPanelThreshold',
|
|
||||||
value: function setPanelThreshold(panelId, threshold) {
|
|
||||||
var panel = this.getPanelModel(panelId);
|
|
||||||
var containsThreshold = _lodash2.default.find(panel.thresholds, { value: threshold });
|
|
||||||
|
|
||||||
if (panel && !containsThreshold) {
|
|
||||||
var thresholdOptions = {
|
|
||||||
colorMode: "custom",
|
|
||||||
fill: false,
|
|
||||||
line: true,
|
|
||||||
lineColor: "rgb(255, 0, 0)",
|
|
||||||
op: "gt",
|
|
||||||
value: threshold,
|
|
||||||
source: "zabbix"
|
|
||||||
};
|
|
||||||
|
|
||||||
panel.thresholds.push(thresholdOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace template variables
|
// Replace template variables
|
||||||
|
|
||||||
|
|||||||
115
dist/test/datasource-zabbix/zabbixAlerting.service.js
vendored
Normal file
115
dist/test/datasource-zabbix/zabbixAlerting.service.js
vendored
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||||
|
|
||||||
|
var _lodash = require('lodash');
|
||||||
|
|
||||||
|
var _lodash2 = _interopRequireDefault(_lodash);
|
||||||
|
|
||||||
|
var _jquery = require('jquery');
|
||||||
|
|
||||||
|
var _jquery2 = _interopRequireDefault(_jquery);
|
||||||
|
|
||||||
|
var _angular = require('angular');
|
||||||
|
|
||||||
|
var _angular2 = _interopRequireDefault(_angular);
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
|
var ZabbixAlertingService = function () {
|
||||||
|
|
||||||
|
/** @ngInject */
|
||||||
|
function ZabbixAlertingService(dashboardSrv) {
|
||||||
|
_classCallCheck(this, ZabbixAlertingService);
|
||||||
|
|
||||||
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
}
|
||||||
|
|
||||||
|
_createClass(ZabbixAlertingService, [{
|
||||||
|
key: 'setPanelAlertState',
|
||||||
|
value: function setPanelAlertState(panelId, alertState) {
|
||||||
|
var panelContainers = _lodash2.default.filter((0, _jquery2.default)('.panel-container'), function (elem) {
|
||||||
|
return elem.clientHeight && elem.clientWidth;
|
||||||
|
});
|
||||||
|
|
||||||
|
var panelModels = this.getPanelModels();
|
||||||
|
var panelIndex = _lodash2.default.findIndex(panelModels, function (panel) {
|
||||||
|
return panel.id === panelId;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (panelIndex >= 0) {
|
||||||
|
var alertClass = "panel-has-alert panel-alert-state--ok panel-alert-state--alerting";
|
||||||
|
(0, _jquery2.default)(panelContainers[panelIndex]).removeClass(alertClass);
|
||||||
|
|
||||||
|
if (alertState) {
|
||||||
|
if (alertState === 'alerting') {
|
||||||
|
alertClass = "panel-has-alert panel-alert-state--" + alertState;
|
||||||
|
(0, _jquery2.default)(panelContainers[panelIndex]).addClass(alertClass);
|
||||||
|
}
|
||||||
|
if (alertState === 'ok') {
|
||||||
|
alertClass = "panel-alert-state--" + alertState;
|
||||||
|
(0, _jquery2.default)(panelContainers[panelIndex]).addClass(alertClass);
|
||||||
|
(0, _jquery2.default)(panelContainers[panelIndex]).removeClass("panel-has-alert");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'getPanelModels',
|
||||||
|
value: function getPanelModels() {
|
||||||
|
return _lodash2.default.flatten(_lodash2.default.map(this.dashboardSrv.dash.rows, function (row) {
|
||||||
|
if (row.collapse) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
return row.panels;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'getPanelModel',
|
||||||
|
value: function getPanelModel(panelId) {
|
||||||
|
var panelModels = this.getPanelModels();
|
||||||
|
|
||||||
|
return _lodash2.default.find(panelModels, function (panel) {
|
||||||
|
return panel.id === panelId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'setPanelThreshold',
|
||||||
|
value: function setPanelThreshold(panelId, threshold) {
|
||||||
|
var panel = this.getPanelModel(panelId);
|
||||||
|
var containsThreshold = _lodash2.default.find(panel.thresholds, { value: threshold });
|
||||||
|
|
||||||
|
if (panel && panel.type === "graph" && !containsThreshold) {
|
||||||
|
var thresholdOptions = {
|
||||||
|
colorMode: "custom",
|
||||||
|
fill: false,
|
||||||
|
line: true,
|
||||||
|
lineColor: "rgb(255, 0, 0)",
|
||||||
|
op: "gt",
|
||||||
|
value: threshold,
|
||||||
|
source: "zabbix"
|
||||||
|
};
|
||||||
|
|
||||||
|
panel.thresholds.push(thresholdOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: 'removeZabbixThreshold',
|
||||||
|
value: function removeZabbixThreshold(panelId) {
|
||||||
|
var panel = this.getPanelModel(panelId);
|
||||||
|
|
||||||
|
if (panel && panel.type === "graph") {
|
||||||
|
panel.thresholds = _lodash2.default.filter(panel.thresholds, function (threshold) {
|
||||||
|
return threshold.source !== "zabbix";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return ZabbixAlertingService;
|
||||||
|
}();
|
||||||
|
|
||||||
|
_angular2.default.module('grafana.services').service('zabbixAlertingSrv', ZabbixAlertingService);
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import $ from 'jquery';
|
|
||||||
import * as dateMath from 'app/core/utils/datemath';
|
import * as dateMath from 'app/core/utils/datemath';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
import * as migrations from './migrations';
|
import * as migrations from './migrations';
|
||||||
@@ -7,15 +6,17 @@ import * as metricFunctions from './metricFunctions';
|
|||||||
import dataProcessor from './dataProcessor';
|
import dataProcessor from './dataProcessor';
|
||||||
import responseHandler from './responseHandler';
|
import responseHandler from './responseHandler';
|
||||||
import './zabbix.js';
|
import './zabbix.js';
|
||||||
|
import './zabbixAlerting.service.js';
|
||||||
import {ZabbixAPIError} from './zabbixAPICore.service.js';
|
import {ZabbixAPIError} from './zabbixAPICore.service.js';
|
||||||
|
|
||||||
class ZabbixAPIDatasource {
|
class ZabbixAPIDatasource {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(instanceSettings, templateSrv, alertSrv, dashboardSrv, Zabbix) {
|
constructor(instanceSettings, templateSrv, alertSrv, dashboardSrv, zabbixAlertingSrv, Zabbix) {
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
this.alertSrv = alertSrv;
|
||||||
this.dashboardSrv = dashboardSrv;
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// General data source settings
|
// General data source settings
|
||||||
this.name = instanceSettings.name;
|
this.name = instanceSettings.name;
|
||||||
@@ -64,11 +65,12 @@ class ZabbixAPIDatasource {
|
|||||||
// Get alerts for current panel
|
// Get alerts for current panel
|
||||||
if (this.alertingEnabled) {
|
if (this.alertingEnabled) {
|
||||||
this.alertQuery(options).then(alert => {
|
this.alertQuery(options).then(alert => {
|
||||||
this.setPanelAlertState(options.panelId, alert.state);
|
this.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
||||||
|
|
||||||
|
this.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
||||||
if (this.addThresholds) {
|
if (this.addThresholds) {
|
||||||
_.forEach(alert.thresholds, threshold => {
|
_.forEach(alert.thresholds, threshold => {
|
||||||
this.setPanelThreshold(options.panelId, threshold);
|
this.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -454,71 +456,6 @@ class ZabbixAPIDatasource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setPanelAlertState(panelId, alertState) {
|
|
||||||
let panelContainers = _.filter($('.panel-container'), elem => {
|
|
||||||
return elem.clientHeight && elem.clientWidth;
|
|
||||||
});
|
|
||||||
|
|
||||||
let panelModels = this.getPanelModels();
|
|
||||||
let panelIndex = _.findIndex(panelModels, panel => {
|
|
||||||
return panel.id === panelId;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (panelIndex >= 0) {
|
|
||||||
let alertClass = "panel-has-alert panel-alert-state--ok panel-alert-state--alerting";
|
|
||||||
$(panelContainers[panelIndex]).removeClass(alertClass);
|
|
||||||
|
|
||||||
if (alertState) {
|
|
||||||
if (alertState === 'alerting') {
|
|
||||||
alertClass = "panel-has-alert panel-alert-state--" + alertState;
|
|
||||||
$(panelContainers[panelIndex]).addClass(alertClass);
|
|
||||||
}
|
|
||||||
if (alertState === 'ok') {
|
|
||||||
alertClass = "panel-alert-state--" + alertState;
|
|
||||||
$(panelContainers[panelIndex]).addClass(alertClass);
|
|
||||||
$(panelContainers[panelIndex]).removeClass("panel-has-alert");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getPanelModels() {
|
|
||||||
return _.flatten(_.map(this.dashboardSrv.dash.rows, row => {
|
|
||||||
if (row.collapse) {
|
|
||||||
return [];
|
|
||||||
} else {
|
|
||||||
return row.panels;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
getPanelModel(panelId) {
|
|
||||||
let panelModels = this.getPanelModels();
|
|
||||||
|
|
||||||
return _.find(panelModels, panel => {
|
|
||||||
return panel.id === panelId;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setPanelThreshold(panelId, threshold) {
|
|
||||||
let panel = this.getPanelModel(panelId);
|
|
||||||
let containsThreshold = _.find(panel.thresholds, {value: threshold});
|
|
||||||
|
|
||||||
if (panel && !containsThreshold) {
|
|
||||||
let thresholdOptions = {
|
|
||||||
colorMode : "custom",
|
|
||||||
fill : false,
|
|
||||||
line : true,
|
|
||||||
lineColor: "rgb(255, 0, 0)",
|
|
||||||
op: "gt",
|
|
||||||
value: threshold,
|
|
||||||
source: "zabbix"
|
|
||||||
};
|
|
||||||
|
|
||||||
panel.thresholds.push(thresholdOptions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace template variables
|
// Replace template variables
|
||||||
replaceTargetVariables(target, options) {
|
replaceTargetVariables(target, options) {
|
||||||
let parts = ['group', 'host', 'application', 'item'];
|
let parts = ['group', 'host', 'application', 'item'];
|
||||||
|
|||||||
91
src/datasource-zabbix/zabbixAlerting.service.js
Normal file
91
src/datasource-zabbix/zabbixAlerting.service.js
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import $ from 'jquery';
|
||||||
|
import angular from 'angular';
|
||||||
|
|
||||||
|
class ZabbixAlertingService {
|
||||||
|
|
||||||
|
/** @ngInject */
|
||||||
|
constructor(dashboardSrv) {
|
||||||
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPanelAlertState(panelId, alertState) {
|
||||||
|
let panelContainers = _.filter($('.panel-container'), elem => {
|
||||||
|
return elem.clientHeight && elem.clientWidth;
|
||||||
|
});
|
||||||
|
|
||||||
|
let panelModels = this.getPanelModels();
|
||||||
|
let panelIndex = _.findIndex(panelModels, panel => {
|
||||||
|
return panel.id === panelId;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (panelIndex >= 0) {
|
||||||
|
let alertClass = "panel-has-alert panel-alert-state--ok panel-alert-state--alerting";
|
||||||
|
$(panelContainers[panelIndex]).removeClass(alertClass);
|
||||||
|
|
||||||
|
if (alertState) {
|
||||||
|
if (alertState === 'alerting') {
|
||||||
|
alertClass = "panel-has-alert panel-alert-state--" + alertState;
|
||||||
|
$(panelContainers[panelIndex]).addClass(alertClass);
|
||||||
|
}
|
||||||
|
if (alertState === 'ok') {
|
||||||
|
alertClass = "panel-alert-state--" + alertState;
|
||||||
|
$(panelContainers[panelIndex]).addClass(alertClass);
|
||||||
|
$(panelContainers[panelIndex]).removeClass("panel-has-alert");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getPanelModels() {
|
||||||
|
return _.flatten(_.map(this.dashboardSrv.dash.rows, row => {
|
||||||
|
if (row.collapse) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
return row.panels;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
getPanelModel(panelId) {
|
||||||
|
let panelModels = this.getPanelModels();
|
||||||
|
|
||||||
|
return _.find(panelModels, panel => {
|
||||||
|
return panel.id === panelId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setPanelThreshold(panelId, threshold) {
|
||||||
|
let panel = this.getPanelModel(panelId);
|
||||||
|
let containsThreshold = _.find(panel.thresholds, {value: threshold});
|
||||||
|
|
||||||
|
if (panel && panel.type === "graph" && !containsThreshold) {
|
||||||
|
let thresholdOptions = {
|
||||||
|
colorMode : "custom",
|
||||||
|
fill : false,
|
||||||
|
line : true,
|
||||||
|
lineColor: "rgb(255, 0, 0)",
|
||||||
|
op: "gt",
|
||||||
|
value: threshold,
|
||||||
|
source: "zabbix"
|
||||||
|
};
|
||||||
|
|
||||||
|
panel.thresholds.push(thresholdOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeZabbixThreshold(panelId) {
|
||||||
|
let panel = this.getPanelModel(panelId);
|
||||||
|
|
||||||
|
if (panel && panel.type === "graph") {
|
||||||
|
panel.thresholds = _.filter(panel.thresholds, threshold => {
|
||||||
|
return threshold.source !== "zabbix";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
angular
|
||||||
|
.module('grafana.services')
|
||||||
|
.service('zabbixAlertingSrv', ZabbixAlertingService);
|
||||||
Reference in New Issue
Block a user