@@ -48,7 +48,7 @@ update_component_status() {
48
48
49
49
# Function to create an incident
50
50
create_incident () {
51
- local incident_name=" Testing Instatus "
51
+ local incident_name=" Degraded Service "
52
52
local message=" The following modules are experiencing issues:\n"
53
53
for i in " ${! failures[@]} " ; do
54
54
message+=" $(( i + 1 )) . ${failures[$i]} \n"
@@ -59,7 +59,7 @@ create_incident() {
59
59
component_status=" MAJOROUTAGE"
60
60
fi
61
61
# see https://instatus.com/help/api/incidents
62
- response =$( curl -s -X POST " https://api.instatus.com/v1/$INSTATUS_PAGE_ID /incidents" \
62
+ incident_id =$( curl -s -X POST " https://api.instatus.com/v1/$INSTATUS_PAGE_ID /incidents" \
63
63
-H " Authorization: Bearer $INSTATUS_API_KEY " \
64
64
-H " Content-Type: application/json" \
65
65
-d " {
@@ -74,10 +74,25 @@ create_incident() {
74
74
\" status\" : \" PARTIALOUTAGE\"
75
75
}
76
76
]
77
- }" )
77
+ }" | jq -r ' .id ' )
78
78
79
- incident_id=$( echo " $response " | jq -r ' .id' )
80
- echo " $incident_id "
79
+ echo " Created incident with ID: $incident_id "
80
+ }
81
+
82
+ # Function to check for existing unresolved incidents
83
+ check_existing_incident () {
84
+ # Fetch the latest incidents with status not equal to "RESOLVED"
85
+ local unresolved_incidents=$( curl -s -X GET " https://api.instatus.com/v1/$INSTATUS_PAGE_ID /incidents" \
86
+ -H " Authorization: Bearer $INSTATUS_API_KEY " \
87
+ -H " Content-Type: application/json" | jq -r ' .incidents[] | select(.status != "RESOLVED") | .id' )
88
+
89
+ if [[ -n " $unresolved_incidents " ]]; then
90
+ echo " Unresolved incidents found: $unresolved_incidents "
91
+ return 0 # Indicate that there are unresolved incidents
92
+ else
93
+ echo " No unresolved incidents found."
94
+ return 1 # Indicate that no unresolved incidents exist
95
+ fi
81
96
}
82
97
83
98
force_redeploy_registry () {
@@ -174,9 +189,10 @@ else
174
189
update_component_status " PARTIALOUTAGE"
175
190
fi
176
191
177
- # Create a new incident
178
- incident_id=$( create_incident)
179
- echo " Created incident with ID: $incident_id "
192
+ # Check if there is an existing incident before creating a new one
193
+ if ! check_existing_incident; then
194
+ create_incident
195
+ fi
180
196
181
197
# If a module is down, force a reployment to try getting things back online
182
198
# ASAP
0 commit comments