-
Notifications
You must be signed in to change notification settings - Fork 1
/
alert-create.sh
executable file
·192 lines (146 loc) · 8.34 KB
/
alert-create.sh
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
#!/bin/bash
sysdig_region=$1
if [ "$#" -ne 2 ]; then
echo "Required arguments missing!"
echo "Usage : ./alert-create.sh <sysdig_region> <sysdig_api_token>"
echo "<sysdig_region> value is one of us-south, eu-de,eu-gb,jp-tok,us-east,au-syd"
echo "<sysdig_api_token> is the API token to authenticate with the IBM Cloud Monitoring with Sysdig service"
exit 1
fi
sysdig_api_token=$2
sysdigEndpoint="https://$1.monitoring.cloud.ibm.com/api/alerts"
iamEndpoint="https://iam.cloud.ibm.com"
# Don't run if any of the prerequisites are not installed.
prerequisites=("curl")
for i in "${prerequisites[@]}"; do
isExist=$(command -v $i)
if [ -z "$isExist" ]; then
echo "$i not installed. Please install the required pre-requisites curl first"
exit 1
fi
done
#HighNumberOfRejectedRequests
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighNumberOfRejectedRequests > 1 per sec","description": "Gorouters received too many rejected requests.","enabled": false,"severity": 4,"timespan": 300000000, "condition": "avg(timeAvg(firehose_counter_event_gorouter_rejected_requests_total))> 1","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighNumberOfRejectedRequests > 5 per sec","description": "Gorouters received too many rejected requests.","enabled": false,"severity": 1,"timespan": 300000000, "condition": "avg(timeAvg(firehose_counter_event_gorouter_rejected_requests_total))> 5","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighNumberOfBadGateways
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighNumberOfBadGateways> 1 per sec","description": "Gorouters received too many bad gateway requests.","enabled": false,"severity": 4,"timespan": 300000000, "condition": "avg(timeAvg(firehose_counter_event_gorouter_bad_gateways_total))> 1","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighNumberOfBadGateways> 5 per sec","description": "Gorouters received too many bad gateway requests.","enabled": false,"severity": 1,"timespan": 300000000, "condition": "avg(timeAvg(firehose_counter_event_gorouter_bad_gateways_total))> 5","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:GorouterHighNumber4xx
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]GorouterHighNumber4xx","description": "High number of 4xx HTTP responses on Gorouter.","enabled": false,"severity": 4,"timespan": 300000000, "condition": "avg(timeAvg(firehose_counter_event_gorouter_responses_4_xx_delta))> 0.2","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:GorouterHighNumber5xx
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]GorouterHighNumber5xx","description": "High number of 5xx HTTP responses on Gorouter.","enabled": false,"severity": 4,"timespan": 300000000, "condition": "avg(timeAvg(firehose_counter_event_gorouter_responses_5_xx_delta))> 0.2","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:UnhealthyCell
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]UnhealthyCell","description": "Unhealthy cell found.","enabled": false,"severity": 4,"timespan": 60000000, "condition": "max(avg(firehose_value_metric_rep_unhealthy_cell))> 1","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:DiegoApiActivePassiveWrong
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]DiegoApiActivePassiveWrong","description": "One of diego-api pods is in wrong active passive status.","enabled": false,"severity": 1,"timespan": 60000000, "condition": "sum(sum(firehose_value_metric_bbs_lock_held)) != 1","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighMemoryUsageForCells > 80%
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighMemoryUsageForCells > 80%","description": "High memory usage for cells to allocate to containers.","enabled": false,"severity": 4,"timespan": 60000000, "condition": "sum(sum(firehose_value_metric_rep_capacity_remaining_memory))< 5","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighMemoryUsageForCells > 95%
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighMemoryUsageForCells > 95%","description": "High memory usage for cells to allocate to containers.","enabled": false,"severity": 1,"timespan": 300000000, "condition": "sum(sum(firehose_value_metric_rep_capacity_remaining_memory))< 2","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighDiskUsageForCells > 80%
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighDiskUsageForCells> 80%","description": "High disk usage for cells to allocate to containers.","enabled": false,"severity": 4,"timespan": 60000000, "condition": "sum(sum(firehose_value_metric_rep_capacity_remaining_disk))< 20","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighDiskUsageForCells > 95%
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighDiskUsageForCells> 95%","description": "High disk usage for cells to allocate to containers.","enabled": false,"severity": 1,"timespan": 300000000, "condition": "sum(sum(firehose_value_metric_rep_capacity_remaining_disk))< 10","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighContainersUsageForCells> 80%
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighContainersUsageForCells> 80%","description": "High containers usage for cells to allocate to containers.","enabled": false,"severity": 4,"timespan": 60000000, "condition": "sum(sum(firehose_value_metric_rep_capacity_remaining_containers))< 50","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
#CF:HighContainersUsageForCells> 95%
status=$(curl -X POST $sysdigEndpoint -H "Authorization: Bearer $sysdig_api_token" -H 'Content-Type: application/json' -d \
'{"alert": {"type": "MANUAL", "name": "[CFEE]HighContainersUsageForCells> 95%","description": "High containers usage for cells to allocate to containers.","enabled": false,"severity": 1,"timespan": 300000000, "condition": "sum(sum(firehose_value_metric_rep_capacity_remaining_containers))< 20","filter": ""}}')
echo $status
if [[ "$status" =~ "createdOn" ]]; then
echo "Alert created successfully!"
else
exit 1
fi
echo "All alerts created successfully!"