-
Notifications
You must be signed in to change notification settings - Fork 460
/
zabbixAlerting.service.js
93 lines (73 loc) · 2.23 KB
/
zabbixAlerting.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import _ from 'lodash';
import $ from 'jquery';
import angular from 'angular';
class ZabbixAlertingService {
/** @ngInject */
constructor(dashboardSrv) {
this.dashboardSrv = dashboardSrv;
}
isFullScreen() {
return this.getDashboardModel().meta.fullscreen;
}
setPanelAlertState(panelId, alertState) {
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);