From dd38425c7677b0caad40f2a372289cbb295df981 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 18 Jun 2020 12:05:06 +0300 Subject: [PATCH] Remove old alerting feature --- src/datasource-zabbix/datasource.ts | 93 +----------------- src/datasource-zabbix/module.ts | 1 - .../zabbixAlerting.service.js | 98 ------------------- 3 files changed, 1 insertion(+), 191 deletions(-) delete mode 100644 src/datasource-zabbix/zabbixAlerting.service.js diff --git a/src/datasource-zabbix/datasource.ts b/src/datasource-zabbix/datasource.ts index 34e6241..f8c4893 100644 --- a/src/datasource-zabbix/datasource.ts +++ b/src/datasource-zabbix/datasource.ts @@ -24,9 +24,6 @@ export class ZabbixDatasource extends DataSourceApi any; /** @ngInject */ - constructor(instanceSettings: DataSourceInstanceSettings, private templateSrv, private zabbixAlertingSrv) { + constructor(instanceSettings: DataSourceInstanceSettings, private templateSrv) { super(instanceSettings); this.templateSrv = templateSrv; - this.zabbixAlertingSrv = zabbixAlertingSrv; - this.enableDebugLog = config.buildInfo.env === 'development'; // Use custom format for template variables @@ -67,11 +62,6 @@ export class ZabbixDatasource extends DataSourceApi { - this.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state); - - this.zabbixAlertingSrv.removeZabbixThreshold(options.panelId); - if (this.addThresholds) { - _.forEach(alert.thresholds, threshold => { - this.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold); - }); - } - }); - } - // Create request for each target const promises = _.map(options.targets, t => { // Don't request for hidden targets @@ -671,58 +644,6 @@ export class ZabbixDatasource extends DataSourceApi { - let target = _.cloneDeep(t); - target = migrations.migrate(target); - this.replaceTargetVariables(target, options); - return this.zabbix.getItemsFromTarget(target, {itemtype: 'num'}); - }); - - return Promise.all(getPanelItems) - .then(results => { - const items = _.flatten(results); - const itemids = _.map(items, 'itemid'); - - if (itemids.length === 0) { - return []; - } - return this.zabbix.getAlerts(itemids); - }) - .then(triggers => { - triggers = _.filter(triggers, trigger => { - return trigger.priority >= this.alertingMinSeverity; - }); - - if (!triggers || triggers.length === 0) { - return {}; - } - - let state = 'ok'; - - const firedTriggers = _.filter(triggers, {value: '1'}); - if (firedTriggers.length) { - state = 'alerting'; - } - - const thresholds = _.map(triggers, trigger => { - return getTriggerThreshold(trigger.expression); - }); - - return { - panelId: options.panelId, - state: state, - thresholds: thresholds - }; - }); - } - // Replace template variables replaceTargetVariables(target, options) { const parts = ['group', 'host', 'application', 'item']; @@ -845,15 +766,3 @@ function filterEnabledTargets(targets) { return !(target.hide || !target.group || !target.host || !target.item); }); } - -function getTriggerThreshold(expression) { - const thresholdPattern = /.*[<>=]{1,2}([\d\.]+)/; - const finded_thresholds = expression.match(thresholdPattern); - if (finded_thresholds && finded_thresholds.length >= 2) { - let threshold = finded_thresholds[1]; - threshold = Number(threshold); - return threshold; - } else { - return null; - } -} diff --git a/src/datasource-zabbix/module.ts b/src/datasource-zabbix/module.ts index f55eca2..03363e8 100644 --- a/src/datasource-zabbix/module.ts +++ b/src/datasource-zabbix/module.ts @@ -4,7 +4,6 @@ import { ZabbixDatasource } from './datasource'; import { ZabbixQueryController } from './query.controller'; import { ZabbixVariableQueryEditor } from './components/VariableQueryEditor'; import { ConfigEditor } from './components/ConfigEditor'; -import './zabbixAlerting.service.js'; import './add-metric-function.directive'; import './metric-function-editor.directive'; diff --git a/src/datasource-zabbix/zabbixAlerting.service.js b/src/datasource-zabbix/zabbixAlerting.service.js deleted file mode 100644 index 413d6d2..0000000 --- a/src/datasource-zabbix/zabbixAlerting.service.js +++ /dev/null @@ -1,98 +0,0 @@ -import _ from 'lodash'; -import $ from 'jquery'; -import angular from 'angular'; - -export class ZabbixAlertingService { - - /** - * @ngInject - */ - constructor(dashboardSrv) { - this.dashboardSrv = dashboardSrv; - } - - isFullScreen() { - return this.getDashboardModel().meta.fullscreen; - } - - setPanelAlertState(panelId, alertState) { - if (!alertState) { - return; - } - - let panelIndex; - let panelContainers = _.filter($('.panel-container'), elem => { - return elem.clientHeight && elem.clientWidth; - }); - - let panelModels = this.getPanelModels(); - - if (this.isFullScreen()) { - panelIndex = 0; - } else { - 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) { - alertClass = "panel-has-alert panel-alert-state--" + alertState; - $(panelContainers[panelIndex]).addClass(alertClass); - } - } - } - - getDashboardModel() { - return this.dashboardSrv.dash || this.dashboardSrv.dashboard; - } - - getPanelModels() { - return _.filter(this.getDashboardModel().panels, panel => panel.type !== 'row'); - } - - 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);