saba-webhook-gateway 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,359 @@
1
+ # Saba Webhook Gateway base
2
+ # Copyright 2023 Kenshi Muto <kmuto@kmuto.jp>
3
+ require 'json'
4
+
5
+ # main namespace for Saba Webhook Gateway
6
+ module SabaWebhookGateway
7
+ class Base
8
+ # Initialize a new SabaWebhookGateway object.
9
+ #
10
+ # @return [SabaWebhookGateway::Base]
11
+ def initialize
12
+ @debug = ENV['DEBUG'] || nil
13
+ end
14
+
15
+ # Convert epoch to 'MM/DD hh:mm'.
16
+ #
17
+ # @param [Integer] :epoch Time epoch.
18
+ # @return [String]
19
+ def to_date(epoch)
20
+ Time.at(epoch.to_i).strftime('%m/%d %H:%M')
21
+ end
22
+
23
+ # Convert JSON to Ruby Hash.
24
+ #
25
+ # @param [String] :json JSON content.
26
+ # @return [Hash]
27
+ def parse(json)
28
+ begin
29
+ JSON.parse(json, symbolize_names: true)
30
+ rescue JSON::ParserError => e
31
+ if @debug
32
+ puts "[json error]\n#{e}"
33
+ end
34
+ nil
35
+ end
36
+ end
37
+
38
+ # Process sample notifications.
39
+ #
40
+ # @param [Hash] :h Event Hash object.
41
+ # @return [String]
42
+ def sample(h)
43
+ puts "[sample]\n#{h}"
44
+ '{ "event": "sample" }'
45
+ end
46
+
47
+ # Process alert notifications.
48
+ #
49
+ # @param [Hash] :h Event Hash object.
50
+ # @return [String]
51
+ def alert(h)
52
+ puts "[alert]\n#{h}"
53
+ '{ "event": "alert" }'
54
+ end
55
+
56
+ # Process alert group notifications.
57
+ #
58
+ # @param [Hash] :h Event Hash object.
59
+ # @return [String]
60
+ def alert_group(h)
61
+ puts "[alert_group]\n#{h}"
62
+ '{ "event": "alertGroup" }'
63
+ end
64
+
65
+ # Process host registration notifications.
66
+ #
67
+ # @param [Hash] :h Event Hash object.
68
+ # @return [String]
69
+ def host_register(h)
70
+ puts "[host_register]\n#{h}"
71
+ '{ "event": "hostRegister" }'
72
+ end
73
+
74
+ # Process host status change notifications.
75
+ #
76
+ # @param [Hash] :h Event Hash object.
77
+ # @return [String]
78
+ def host_status(h)
79
+ puts "[host_status]\n#{h}"
80
+ '{ "event": "hostStatus" }'
81
+ end
82
+
83
+ # Process host retirement notifications.
84
+ #
85
+ # @param [Hash] :h Event Hash object.
86
+ # @return [String]
87
+ def host_retire(h)
88
+ puts "[host_retire]\n#{h}"
89
+ '{ "event": "hostRetire" }'
90
+ end
91
+
92
+ # Process monitor creation notifications.
93
+ #
94
+ # @param [Hash] :h Event Hash object.
95
+ # @return [String]
96
+ def monitor_create(h)
97
+ case h[:monitor][:type]
98
+ when 'host'
99
+ monitor_create_host(h)
100
+ when 'external'
101
+ monitor_create_external(h)
102
+ when 'expression'
103
+ monitor_create_expression(h)
104
+ when 'anomalyDetection'
105
+ monitor_create_anomaly_detection(h)
106
+ when 'service'
107
+ monitor_create_service(h)
108
+ when 'connectivity'
109
+ monitor_create_connectivity(h)
110
+ end
111
+ end
112
+
113
+ # Process monitor creation (host) notifications.
114
+ #
115
+ # @param [Hash] :h Event Hash object.
116
+ # @return [String]
117
+ def monitor_create_host(h)
118
+ puts "[monitor_create_host]\n#{h}"
119
+ '{ "event": "monitorCreate/host" }'
120
+ end
121
+
122
+ # Process monitor creation (external) notifications.
123
+ #
124
+ # @param [Hash] :h Event Hash object.
125
+ # @return [String]
126
+ def monitor_create_external(h)
127
+ puts "[monitor_create_external]\n#{h}"
128
+ '{ "event": "monitorCreate/external" }'
129
+ end
130
+
131
+ # Process monitor creation (expression) notifications.
132
+ #
133
+ # @param [Hash] :h Event Hash object.
134
+ # @return [String]
135
+ def monitor_create_expression(h)
136
+ puts "[monitor_create_expression]\n#{h}"
137
+ '{ "event": "monitorCreate/expression" }'
138
+ end
139
+
140
+ # Process monitor creation (anomaly detection) notifications.
141
+ #
142
+ # @param [Hash] :h Event Hash object.
143
+ # @return [String]
144
+ def monitor_create_anomaly_detection(h)
145
+ puts "[monitor_create_anomaly_detection]\n#{h}"
146
+ '{ "event": "monitorCreate/anomalyDetection" }'
147
+ end
148
+
149
+ # Process monitor creation (service) notifications.
150
+ #
151
+ # @param [Hash] :h Event Hash object.
152
+ # @return [String]
153
+ def monitor_create_service(h)
154
+ puts "[monitor_create_service]\n#{h}"
155
+ '{ "event": "monitorCreate/service" }'
156
+ end
157
+
158
+ # Process monitor creation (connectivity) notifications.
159
+ #
160
+ # @param [Hash] :h Event Hash object.
161
+ # @return [String]
162
+ def monitor_create_connectivity(h)
163
+ puts "[monitor_create_connectivity]\n#{h}"
164
+ '{ "event": "monitorCreate/connectivity" }'
165
+ end
166
+
167
+ # Process monitor update notifications.
168
+ #
169
+ # @param [Hash] :h Event Hash object.
170
+ # @return [String]
171
+ def monitor_update(h)
172
+ case h[:monitor][:type]
173
+ when 'host'
174
+ monitor_update_host(h)
175
+ when 'external'
176
+ monitor_update_external(h)
177
+ when 'expression'
178
+ monitor_update_expression(h)
179
+ when 'anomalyDetection'
180
+ monitor_update_anomaly_detection(h)
181
+ when 'service'
182
+ monitor_update_service(h)
183
+ when 'connectivity'
184
+ monitor_update_connectivity(h)
185
+ end
186
+ end
187
+
188
+ # Process monitor update (host) notifications.
189
+ #
190
+ # @param [Hash] :h Event Hash object.
191
+ # @return [String]
192
+ def monitor_update_host(h)
193
+ puts "[monitor_update_host]\n#{h}"
194
+ '{ "event": "monitorUpdate/host" }'
195
+ end
196
+
197
+ # Process monitor update (external) notifications.
198
+ #
199
+ # @param [Hash] :h Event Hash object.
200
+ # @return [String]
201
+ def monitor_update_external(h)
202
+ puts "[monitor_update_external]\n#{h}"
203
+ '{ "event": "monitorUpdate/external" }'
204
+ end
205
+
206
+ # Process monitor update (expression) notifications.
207
+ #
208
+ # @param [Hash] :h Event Hash object.
209
+ # @return [String]
210
+ def monitor_update_expression(h)
211
+ puts "[monitor_update_expression]\n#{h}"
212
+ '{ "event": "monitorUpdate/expression" }'
213
+ end
214
+
215
+ # Process monitor update (anomaly detection) notifications.
216
+ #
217
+ # @param [Hash] :h Event Hash object.
218
+ # @return [String]
219
+ def monitor_update_anomaly_detection(h)
220
+ puts "[monitor_update_anomaly_detection]\n#{h}"
221
+ '{ "event": "monitorUpdate/anomalyDetection" }'
222
+ end
223
+
224
+ # Process monitor update (service) notifications.
225
+ #
226
+ # @param [Hash] :h Event Hash object.
227
+ # @return [String]
228
+ def monitor_update_service(h)
229
+ puts "[monitor_update_service]\n#{h}"
230
+ '{ "event": "monitorUpdate/service" }'
231
+ end
232
+
233
+ # Process monitor update (connectivity) notifications.
234
+ #
235
+ # @param [Hash] :h Event Hash object.
236
+ # @return [String]
237
+ def monitor_update_connectivity(h)
238
+ puts "[monitor_update_connectivity]\n#{h}"
239
+ '{ "event": "monitorUpdate/connectivity" }'
240
+ end
241
+
242
+ # Process monitor deletion notifications.
243
+ #
244
+ # @param [Hash] :h Event Hash object.
245
+ # @return [String]
246
+ def monitor_delete(h)
247
+ case h[:monitor][:type]
248
+ when 'host'
249
+ monitor_delete_host(h)
250
+ when 'external'
251
+ monitor_delete_external(h)
252
+ when 'expression'
253
+ monitor_delete_expression(h)
254
+ when 'anomalyDetection'
255
+ monitor_delete_anomaly_detection(h)
256
+ when 'service'
257
+ monitor_delete_service(h)
258
+ when 'connectivity'
259
+ monitor_delete_connectivity(h)
260
+ end
261
+ end
262
+
263
+ # Process monitor deletion (host) notifications.
264
+ #
265
+ # @param [Hash] :h Event Hash object.
266
+ # @return [String]
267
+ def monitor_delete_host(h)
268
+ puts "[monitor_delete_host]\n#{h}"
269
+ '{ "event": "monitorDelete/host" }'
270
+ end
271
+
272
+ # Process monitor deletion (external) notifications.
273
+ #
274
+ # @param [Hash] :h Event Hash object.
275
+ # @return [String]
276
+ def monitor_delete_external(h)
277
+ puts "[monitor_delete_external]\n#{h}"
278
+ '{ "event": "monitorDelete/external" }'
279
+ end
280
+
281
+ # Process monitor deletion (expression) notifications.
282
+ #
283
+ # @param [Hash] :h Event Hash object.
284
+ # @return [String]
285
+ def monitor_delete_expression(h)
286
+ puts "[monitor_delete_expression]\n#{h}"
287
+ '{ "event": "monitorDelete/expression" }'
288
+ end
289
+
290
+ # Process monitor deletion (anomaly detection) notifications.
291
+ #
292
+ # @param [Hash] :h Event Hash object.
293
+ # @return [String]
294
+ def monitor_delete_anomaly_detection(h)
295
+ puts "[monitor_delete_anomaly_detection]\n#{h}"
296
+ '{ "event": "monitorDelete/anomalyDetection" }'
297
+ end
298
+
299
+ # Process monitor deletion (service) notifications.
300
+ #
301
+ # @param [Hash] :h Event Hash object.
302
+ # @return [String]
303
+ def monitor_delete_service(h)
304
+ puts "[monitor_delete_service]\n#{h}"
305
+ '{ "event": "monitorDelete/service" }'
306
+ end
307
+
308
+ # Process monitor deletion (connectivity) notifications.
309
+ #
310
+ # @param [Hash] :h Event Hash object.
311
+ # @return [String]
312
+ def monitor_delete_connectivity(h)
313
+ puts "[monitor_delete_connectivity]\n#{h}"
314
+ '{ "event": "monitorDelete/connectivity" }'
315
+ end
316
+
317
+ # Call the respective notification method according to the event.
318
+ #
319
+ # @param [Hash] :h Event Hash object.
320
+ # @return [String]
321
+ def handle_by_event(h)
322
+ case h[:event]
323
+ when 'sample'
324
+ sample(h)
325
+ when 'alert'
326
+ alert(h)
327
+ when 'alertGroup'
328
+ alert_group(h)
329
+ when 'hostRegister'
330
+ host_register(h)
331
+ when 'hostStatus'
332
+ host_status(h)
333
+ when 'hostRetire'
334
+ host_retire(h)
335
+ when 'monitorCreate'
336
+ monitor_create(h)
337
+ when 'monitorUpdate'
338
+ monitor_update(h)
339
+ when 'monitorDelete'
340
+ monitor_delete(h)
341
+ end
342
+ end
343
+
344
+ # Post JSON to the target.
345
+ #
346
+ # @param [String] :json JSON content.
347
+ def post(json)
348
+ puts "[post]\n#{json}"
349
+ end
350
+
351
+ # Main routine. It receive and process event hash objects and make JSON post calls.
352
+ #
353
+ # @param [Hash] :h Event Hash object.
354
+ def run(h)
355
+ json = handle_by_event(h)
356
+ post(json) if json
357
+ end
358
+ end
359
+ end
@@ -0,0 +1,326 @@
1
+ # Saba Webhook Gateway for Google Chat
2
+ # Copyright 2023 Kenshi Muto <kmuto@kmuto.jp>
3
+ require_relative 'base'
4
+ require 'faraday'
5
+
6
+ module SabaWebhookGateway
7
+ class GoogleChat < Base
8
+ # Make Google Chat Card style JSON.
9
+ #
10
+ # @param [Hash] :header Header area Hash object.
11
+ # @param [Hash] :sections Section area Hash object.
12
+ # @return [String]
13
+ def googlechat_card(header, sections)
14
+ j = { cards: { header: header, sections: sections } }
15
+ JSON.generate(j)
16
+ end
17
+
18
+ def sample(h)
19
+ header = { title: 'notification test' }
20
+ widget1 = [{ textParagraph: { text: h[:message] } }]
21
+ sections = [{ widgets: widget1 }]
22
+ googlechat_card(header, sections)
23
+ end
24
+
25
+ def alert(h)
26
+ header = { title: %Q([#{h[:orgName]}] #{h[:alert][:status].upcase}: #{h[:alert][:monitorName]}) }
27
+ start_time = to_date(h[:alert][:openedAt])
28
+ end_time = h[:alert][:closedAt] ? to_date(h[:alert][:closedAt]) : nil
29
+ header[:subtitle] = if end_time
30
+ %Q(from #{start_time} to #{end_time})
31
+ else
32
+ %Q(from #{start_time})
33
+ end
34
+
35
+ sa = []
36
+ sa << %Q(<a href="#{h[:alert][:url]}">View Alert</a>)
37
+
38
+ if h[:host] && h[:host][:roles]
39
+ # Host
40
+ sa << %Q(Host: <a href="#{h[:host][:url]}">#{h[:host][:name]}</a>)
41
+ h[:host][:roles].each do |a|
42
+ sa << %Q(Role: [<a href="#{a[:serviceUrl]}">#{a[:serviceName]}</a>] <a href="#{a[:roleUrl]}">#{a[:roleName]}</a>)
43
+ end
44
+ end
45
+
46
+ if h[:service] && h[:service][:roles]
47
+ # Service
48
+ sa << %Q(Service: #{h[:service][:name]})
49
+ h[:service][:roles].each do |a|
50
+ sa << %Q(Role: [<a href="#{a[:serviceUrl]}">#{a[:serviceName]}</a>] <a href="#{a[:roleUrl]}">#{a[:roleName]}</a>)
51
+ end
52
+ end
53
+
54
+ if h[:alert][:metricLabel]
55
+ # Host, Service, Expression
56
+ if h[:alert][:status] == 'ok'
57
+ sa << %Q(Metric: #{h[:alert][:metricLabel]} #{h[:alert][:metricValue]})
58
+ else
59
+ threshold = if h[:alert][:status] == 'critical'
60
+ h[:alert][:criticalThreshold]
61
+ else
62
+ h[:alert][:warningThreshold]
63
+ end
64
+ sa << %Q(Metric: #{h[:alert][:metricLabel]} #{h[:alert][:metricValue]} #{h[:alert][:monitorOperator]} #{threshold})
65
+ end
66
+ end
67
+
68
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
69
+ sections = [{ widgets: widget1 }]
70
+
71
+ if h[:imageUrl]
72
+ widget2 = [{
73
+ image: {
74
+ imageUrl: h[:imageUrl],
75
+ onClick: {
76
+ openLink: {
77
+ url: h[:alert][:url]
78
+ }
79
+ }
80
+ }
81
+ }]
82
+ sections.push({ widgets: widget2 })
83
+ end
84
+
85
+ if h[:memo]
86
+ widget3 = [{ textParagraph: { text: h[:memo] } }]
87
+ sections.push({ widgets: widget3 })
88
+ end
89
+
90
+ googlechat_card(header, sections)
91
+ end
92
+
93
+ def alert_group(h)
94
+ header = { title: %Q([#{h[:orgName]}] #{h[:alertGroup][:status].upcase}: #{h[:alertGroupSetting][:name]}) }
95
+ start_time = to_date(h[:alertGroup][:createdAt]) # createdAt
96
+ end_time = h[:alertGroup][:closedAt] ? to_date(h[:alertGroup][:closedAt]) : nil
97
+ header[:subtitle] = if end_time
98
+ %Q(from #{start_time} to #{end_time})
99
+ else
100
+ %Q(from #{start_time})
101
+ end
102
+
103
+ sa = []
104
+ sa << %Q(<a href="#{h[:alertGroup][:url]}">View Alert</a>)
105
+
106
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
107
+ sections = [{ widgets: widget1 }]
108
+
109
+ if h[:alertGroupSetting][:memo]
110
+ widget2 = [{ textParagraph: { text: h[:alertGroupSetting][:memo] } }]
111
+ sections.push({ widgets: widget2 })
112
+ end
113
+
114
+ googlechat_card(header, sections)
115
+ end
116
+
117
+ def host_register(h)
118
+ header = { title: %Q([#{h[:orgName]}] Host #{h[:host][:name]} is registered) }
119
+
120
+ sa = []
121
+ if h[:user]
122
+ sa << %Q(Registered by: #{h[:user][:screenName]})
123
+ end
124
+
125
+ if h[:host][:roles]
126
+ sa << %Q(Host: <a href="#{h[:host][:url]}">#{h[:host][:name]}</a>)
127
+ h[:host][:roles].each do |a|
128
+ sa << %Q(Role: [<a href="#{a[:serviceUrl]}">#{a[:serviceName]}</a>] <a href="#{a[:roleUrl]}">#{a[:roleName]}</a>)
129
+ end
130
+ end
131
+
132
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
133
+ sections = [{ widgets: widget1 }]
134
+
135
+ googlechat_card(header, sections)
136
+ end
137
+
138
+ def host_status(h)
139
+ header = { title: %Q([#{h[:orgName]}] Host #{h[:host][:name]} is changed to #{h[:host][:status]}) }
140
+
141
+ sa = []
142
+ if h[:user]
143
+ sa << %Q(Chagned by: #{h[:user][:screenName]})
144
+ end
145
+
146
+ sa << %Q(Previous: #{h[:fromStatus]})
147
+ if h[:host][:roles]
148
+ sa << %Q(Host: <a href="#{h[:host][:url]}">#{h[:host][:name]}</a>)
149
+ h[:host][:roles].each do |a|
150
+ sa << %Q(Role: [<a href="#{a[:serviceUrl]}">#{a[:serviceName]}</a>] <a href="#{a[:roleUrl]}">#{a[:roleName]}</a>)
151
+ end
152
+ end
153
+
154
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
155
+ sections = [{ widgets: widget1 }]
156
+
157
+ googlechat_card(header, sections)
158
+ end
159
+
160
+ def host_retire(h)
161
+ header = { title: %Q([#{h[:orgName]}] Host #{h[:host][:name]} is retired) }
162
+
163
+ sa = []
164
+ if h[:user]
165
+ sa << %Q(Retired by: #{h[:user][:screenName]})
166
+ end
167
+
168
+ if h[:host][:roles]
169
+ sa << %Q(Host: <a href="#{h[:host][:url]}">#{h[:host][:name]}</a>)
170
+ h[:host][:roles].each do |a|
171
+ sa << %Q(Role: [<a href="#{a[:serviceUrl]}">#{a[:serviceName]}</a>] <a href="#{a[:roleUrl]}">#{a[:roleName]}</a>)
172
+ end
173
+ end
174
+
175
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
176
+ sections = [{ widgets: widget1 }]
177
+
178
+ googlechat_card(header, sections)
179
+ end
180
+
181
+ def monitor_create_common(h, target)
182
+ header = { title: %Q([#{h[:orgName]}] Monitor #{h[:monitor][:name]} is created) }
183
+
184
+ sa = []
185
+ if h[:user]
186
+ sa << %Q(Created by: #{h[:user][:screenName]})
187
+ end
188
+
189
+ sa << target
190
+
191
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
192
+ sections = [{ widgets: widget1 }]
193
+
194
+ if h[:monitor][:memo]
195
+ widget2 = [{ textParagraph: { text: h[:monitor][:memo] } }]
196
+ sections.push({ widgets: widget2 })
197
+ end
198
+
199
+ googlechat_card(header, sections)
200
+ end
201
+
202
+ def monitor_create_host(h)
203
+ monitor_create_common(h, %Q(Target: Host metric (#{h[:monitor][:metric]})))
204
+ end
205
+
206
+ def monitor_create_external(h)
207
+ monitor_create_common(h, %Q(Target: External (#{h[:monitor][:url]})))
208
+ end
209
+
210
+ def monitor_create_expression(h)
211
+ monitor_create_common(h, %Q(Target: Expression (#{h[:monitor][:expression]})))
212
+ end
213
+
214
+ def monitor_create_anomaly_detection(h)
215
+ monitor_create_common(h, %Q(Target: Anormaly detection (#{h[:monitor][:scopes].join(', ')})))
216
+ end
217
+
218
+ def monitor_create_service(h)
219
+ monitor_create_common(h, %Q(Target: Service metric (#{h[:monitor][:metric]})))
220
+ end
221
+
222
+ def monitor_create_connectivity(h)
223
+ monitor_create_common(h, %Q(Target: Connectivity (#{h[:monitor][:scopes].join(', ')})))
224
+ end
225
+
226
+ def monitor_update_common(h, target)
227
+ header = { title: %Q([#{h[:orgName]}] Monitor #{h[:monitor][:name]} is updated) }
228
+
229
+ sa = []
230
+ if h[:user]
231
+ sa << %Q(Updated by: #{h[:user][:screenName]})
232
+ end
233
+
234
+ sa << target
235
+
236
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
237
+ sections = [{ widgets: widget1 }]
238
+
239
+ if h[:monitor][:memo]
240
+ widget2 = [{ textParagraph: { text: h[:monitor][:memo] } }]
241
+ sections.push({ widgets: widget2 })
242
+ end
243
+
244
+ googlechat_card(header, sections)
245
+ end
246
+
247
+ def monitor_update_host(h)
248
+ monitor_update_common(h, %Q(Target: Host metric (#{h[:monitor][:metric]})))
249
+ end
250
+
251
+ def monitor_update_external(h)
252
+ monitor_update_common(h, %Q(Target: External (#{h[:monitor][:url]})))
253
+ end
254
+
255
+ def monitor_update_expression(h)
256
+ monitor_update_common(h, %Q(Target: Expression (#{h[:monitor][:expression]})))
257
+ end
258
+
259
+ def monitor_update_anomaly_detection(h)
260
+ monitor_update_common(h, %Q(Target: Anormaly detection (#{h[:monitor][:scopes].join(', ')})))
261
+ end
262
+
263
+ def monitor_update_service(h)
264
+ monitor_update_common(h, %Q(Target: Service metric (#{h[:monitor][:metric]})))
265
+ end
266
+
267
+ def monitor_update_connectivity(h)
268
+ monitor_update_common(h, %Q(Target: Connectivity (#{h[:monitor][:scopes].join(', ')})))
269
+ end
270
+
271
+ def monitor_delete_common(h, target)
272
+ header = { title: %Q([#{h[:orgName]}] Monitor #{h[:monitor][:name]} is deleted) }
273
+
274
+ sa = []
275
+ if h[:user]
276
+ sa << %Q(Deleted by: #{h[:user][:screenName]})
277
+ end
278
+
279
+ sa << target
280
+
281
+ widget1 = [{ textParagraph: { text: sa.join("\n") } }]
282
+ sections = [{ widgets: widget1 }]
283
+
284
+ if h[:monitor][:memo]
285
+ widget2 = [{ textParagraph: { text: h[:monitor][:memo] } }]
286
+ sections.push({ widgets: widget2 })
287
+ end
288
+
289
+ googlechat_card(header, sections)
290
+ end
291
+
292
+ def monitor_delete_host(h)
293
+ monitor_delete_common(h, %Q(Target: Host metric (#{h[:monitor][:metric]})))
294
+ end
295
+
296
+ def monitor_delete_external(h)
297
+ monitor_delete_common(h, %Q(Target: External (#{h[:monitor][:url]})))
298
+ end
299
+
300
+ def monitor_delete_expression(h)
301
+ monitor_delete_common(h, %Q(Target: Expression (#{h[:monitor][:expression]})))
302
+ end
303
+
304
+ def monitor_delete_anomaly_detection(h)
305
+ monitor_delete_common(h, %Q(Target: Anormaly detection (#{h[:monitor][:scopes].join(', ')})))
306
+ end
307
+
308
+ def monitor_delete_service(h)
309
+ monitor_delete_common(h, %Q(Target: Service metric (#{h[:monitor][:metric]})))
310
+ end
311
+
312
+ def monitor_delete_connectivity(h)
313
+ monitor_delete_common(h, %Q(Target: Connectivity (#{h[:monitor][:scopes].join(', ')})))
314
+ end
315
+
316
+ def post(json)
317
+ resp = Faraday.post(ENV['GOOGLECHAT_WEBHOOK']) do |req|
318
+ req.headers['Content-Type'] = 'application/json'
319
+ req.body = json
320
+ end
321
+ if @debug
322
+ p("[post]\n#{resp.body}")
323
+ end
324
+ end
325
+ end
326
+ end
@@ -0,0 +1,5 @@
1
+ # Saba Webhook Gateway
2
+ #
3
+ # Copyright 2023 Kenshi Muto <kmuto@kmuto.jp>
4
+ require_relative 'saba-webhook-gateway/base'
5
+ require_relative 'saba-webhook-gateway/googlechat'
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ bundle config set --local path 'vendor/bundle'
3
+ rm -rf vendor saba-webhook-gateway-googlechat.zip
4
+ bundle install --gemfile Gemfile-lambda
5
+ mv vendor/bundle/ruby/3.1.0 vendor/bundle/ruby/3.2.0
6
+ bundle config unset --local path
7
+ zip -r saba-webhook-gateway-googlechat.zip exe/lambda-handler-googlechat.rb customize.rb lib vendor