-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanifest.jps
214 lines (183 loc) · 6.95 KB
/
manifest.jps
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
type: install
name: Load Alerts to Slack
description:
text: Automated alerts in Slack for a certain service isn’t working or resource limits are about to be exceeded
short: Slack integration with Jelastic alert system
logo: https://raw.githubusercontent.com/jelastic-jps/load-alerts-to-slack/main/images/slack-notification-logo.png
settings:
fields:
- type: list
name: envName
caption: Environment
required: true
values: []
- type: list
name: nodeGroup
caption: Attach To
required: true
dependsOn:
envName: {}
- type: radiolist
caption: Mode
name: mode
columns: 3
value: specificAlerts
values:
- caption: Specific Alerts
value: specificAlerts
- caption: All Alerts
value: allAlerts
showIf:
specificAlerts:
- type: list
name: alerts
caption: Load Alert(s)
required: true
multiSelect: true
dependsOn:
envName: {}
- type: string
caption: Slack Channel's ID
name: channel
required: true
placeholder: ID of the channel you want to send the message to
- type: string
caption: Slack OAuth Token
name: token
required: true
placeholder: xxxx-your-token-here
tooltip: Need a token? <a href="https://api.slack.com/apps" target="_blank">Create and install</a> a <a href="https://api.slack.com/start" target="_blank">Slack app</a> to begin.
onBeforeInit: |
var resp = api.env.control.GetEnvs();
if (resp.result !== 0) return resp;
var envInfos = resp.infos, envs = [], alertItems = {}, nodes = {};
for (var i = 0, envInfo, env; envInfo = envInfos[i]; i++) {
env = envInfo.env;
if (env.status == 1) {
for (var j = 0, node; node = envInfo.nodes[j]; j++) {
nodes[env.envName] = nodes[env.envName] || [];
nodes[env.envName].groups = nodes[env.envName].groups || {};
if (!nodes[env.envName].groups[node.nodeGroup])
nodes[env.envName].push({
value: node.nodeGroup,
caption: (node.displayName || node.name) + ' (' + node.nodeGroup + ')'
});
nodes[env.envName].groups[node.nodeGroup] = true;
}
resp = api.env.trigger.GetTriggers({ envName: env.envName });
if (resp.result != 0) return resp;
var alerts = resp.array;
for (var j = 0, alert; alert = alerts[j]; j++) {
alertItems[env.envName] = alertItems[env.envName] || [];
alertItems[env.envName].push({
value: alert.name + "#" + alert.nodeGroup,
caption: alert.name + ' (' + alert.nodeGroup + ')'
});
}
if (alertItems[env.envName] && alertItems[env.envName].length > 0) {
envs.push({
value: env.envName,
caption: (env.displayName || env.envName)
});
}
}
}
if (envs.length > 0) {
jps.settings.fields[0].values = envs;
jps.settings.fields[0].value = envs[0].value;
jps.settings.fields[1].dependsOn.envName = nodes;
jps.settings.fields[2].showIf.specificAlerts[0].dependsOn.envName = alertItems;
}
return { result: 0, settings: jps.settings };
onInstall:
- if ('${settings.mode}' == 'specificAlerts'):
set: { alerts: '${settings.alerts}' }
- script:
type: ejs
params:
alerts: ${this.alerts:}
body: |
type: update
targetNodes: any
name: Load Alerts to Slack
id: loadalerts-to-slack
description: Sends monitoring alerts to Slack messenger
settings:
fields:
- type: string
caption: Slack Channel's ID
name: channel
required: true
placeholder: ID of the channel you want to send the message to
- type: string
caption: Slack OAuth Token
name: token
required: true
placeholder: xxxx-your-token-here
tooltip: Need a token? <a href="https://api.slack.com/apps" target="_blank">Create and install</a> a <a href="https://api.slack.com/start" target="_blank">Slack app</a> to begin.
buttons:
- caption: Configure
settings: main
action: configure
- caption: Send Test Message
confirmText: Send test message?
loadingText: Sending test message...
action: sendTestMessage
<% alerts = alerts ? alerts.split(/\s*,\s*/) : [] %>
<% if (alerts.length == 0) { %>
onAlert:
sendSlackMessage:
name: '<%="$"%>{event.params.NAME}'
nodeGroup: '<%="$"%>{event.params.nodeGroup}'
<%}%>
<% for (var i = 0, n = alerts.length; i < n; i++) { var data = alerts[i].split('#'); %>
onAlert [name:<%=data[0]%>, nodeGroup:<%=data[1]%>]:
if ('<%="$"%>{event.params.nodeGroup}' == '<%=data[1]%>'):
sendSlackMessage:
name: '<%="$"%>{event.params.NAME}'
nodeGroup: '<%="$"%>{event.params.nodeGroup}'
<%}%>
actions:
configure:
log: successfuly configured!
sendTestMessage:
sendSlackMessage:
name: Test Alert
nodeGroup: Test Node Group
sendSlackMessage:
script: |
import com.hivext.api.core.utils.Transport;
var attachments = [{
fallback: "Monitoring Alert: ${env.name} ${this.name} ${this.nodeGroup}",
color: "#fe4141",
pretext: "https://" + window.location.host.replace(/^(cs.|appstore.)/, "app.") + "/",
author_name: "Monitoring Alert",
title: "${env.name}",
title_link: "${env.url}",
text: " ",
fields: [{
"title": "Alert Name",
"value": "${this.name}",
"short": false
}, {
"title": "Node Group",
"value": "${this.nodeGroup}",
"short": false
}],
ts: new Date().getTime()
}];
var resp = toNative(new Transport().post("https://slack.com/api/chat.postMessage", {
token: '<%="$"%>{settings.token}',
channel: '<%="$"%>{settings.channel}',
attachments: toJSON(attachments)
}, {}));
if (!resp.ok) return { type: "error", message: resp.error || "unknown error", data: resp };
return { result: 0 };
<% return { result: 0, body: ___ViewO.join('') }; %>
- install:
envName: ${settings.envName}
nodeGroup: ${settings.nodeGroup}
settings:
token: ${settings.token}
channel: ${settings.channel}
manifest: ${response.body}