Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 3912f5b

Browse files
committed
Handle unresolved incidents before creating new ones
Add a function to check for existing unresolved incidents in the Instatus API before creating a new incident. This avoids duplication and ensures that ongoing issues are not reported multiple times.
1 parent 5101c27 commit 3912f5b

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

.github/scripts/check.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ update_component_status() {
4242

4343
# Function to create an incident
4444
create_incident() {
45-
local incident_name="Testing Instatus"
45+
local incident_name="Degraded Service"
4646
local message="The following modules are experiencing issues:\n"
4747
for i in "${!failures[@]}"; do
4848
message+="$(($i + 1)). ${failures[$i]}\n"
@@ -71,7 +71,25 @@ create_incident() {
7171
}")
7272

7373
incident_id=$(echo "$response" | jq -r '.id')
74-
echo "$incident_id"
74+
echo "Created incident with ID: $incident_id"
75+
}
76+
77+
# Function to check for existing unresolved incidents
78+
check_existing_incident() {
79+
# Fetch the latest incidents with status not equal to "RESOLVED"
80+
local response=$(curl -s -X GET "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
81+
-H "Authorization: Bearer $INSTATUS_API_KEY" \
82+
-H "Content-Type: application/json")
83+
84+
local unresolved_incidents=$(echo "$response" | jq -r '.incidents[] | select(.status != "RESOLVED") | .id')
85+
86+
if [[ -n "$unresolved_incidents" ]]; then
87+
echo "Unresolved incidents found: $unresolved_incidents"
88+
return 0 # Indicate that there are unresolved incidents
89+
else
90+
echo "No unresolved incidents found."
91+
return 1 # Indicate that no unresolved incidents exist
92+
fi
7593
}
7694

7795
# Check each module's accessibility
@@ -94,20 +112,19 @@ done
94112
# Determine overall status and update Instatus component
95113
if (( status == 0 )); then
96114
echo "All modules are operational."
97-
# set to
98115
update_component_status "OPERATIONAL"
99116
else
100117
echo "The following modules have issues: ${failures[*]}"
101-
# check if all modules are down
102118
if (( ${#failures[@]} == ${#modules[@]} )); then
103119
update_component_status "MAJOROUTAGE"
104120
else
105121
update_component_status "PARTIALOUTAGE"
106122
fi
107123

108-
# Create a new incident
109-
incident_id=$(create_incident)
110-
echo "Created incident with ID: $incident_id"
124+
# Check if there is an existing incident before creating a new one
125+
if ! check_existing_incident; then
126+
create_incident
127+
fi
111128
fi
112129

113130
exit "${status}"

0 commit comments

Comments
 (0)