-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp-request-divera.yaml
61 lines (61 loc) · 2.52 KB
/
http-request-divera.yaml
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
# do a HTTP POST request on the Divera alarm API
# parameters:
# log_text: String that will be logged
# divera_type: Alert title (max 30 chars)
- logger.log:
format: ${log_text}
level: INFO
# increase the http retry counter
- if:
condition:
lambda: 'return id(global_divera_http_request_failed);'
then:
- lambda: 'id(global_divera_http_request_count)++;'
- logger.log:
format: 'Increasing global_divera_http_request_count to %u'
args:
- 'id(global_divera_http_request_count)'
level: INFO
# if max retry number is not reached, send an http request
- if:
condition:
lambda: 'return (id(global_divera_http_request_count) < id(global_divera_http_request_max_retries));'
then:
- http_request.post:
url: !secret divera_alarm_api_url
verify_ssl: false
headers:
Content-Type: application/json
json:
type: ${divera_type}
on_response:
then:
- logger.log:
format: 'Response status: %d, Duration: %u ms'
args:
- status_code
- duration_ms
level: INFO
# if http status code is neither 200 nor 429 the request failed
- if:
condition:
lambda: "return (status_code != 200 && status_code != 429);"
then:
- lambda: 'id(global_divera_http_request_failed) = true;'
- logger.log:
format: 'Set global_divera_http_request_failed to true.'
level: INFO
else:
- lambda: 'id(global_divera_http_request_failed) = false;'
- lambda: 'id(global_divera_http_request_count) = 0;'
- logger.log:
format: 'Set global_divera_http_request_failed to false, global_divera_http_request_count to 0.'
level: INFO
else:
- logger.log:
format: 'Max retry count reached (%u), stop retrying.'
args:
- 'id(global_divera_http_request_count)'
level: INFO
- lambda: 'id(global_divera_http_request_failed) = false;'
- lambda: 'id(global_divera_http_request_count) = 0;'