Improve incident management in Instatus check script

- Change incident naming for better clarity.
- Ensure new incidents are not created if unresolved ones exist.
pull/346/head
Muhammad Atif Ali 8 months ago
parent 5101c27c83
commit 96d33bc0df

@ -42,7 +42,7 @@ update_component_status() {
# Function to create an incident # Function to create an incident
create_incident() { create_incident() {
local incident_name="Testing Instatus" local incident_name="Degraded Service"
local message="The following modules are experiencing issues:\n" local message="The following modules are experiencing issues:\n"
for i in "${!failures[@]}"; do for i in "${!failures[@]}"; do
message+="$(($i + 1)). ${failures[$i]}\n" message+="$(($i + 1)). ${failures[$i]}\n"
@ -53,7 +53,7 @@ create_incident() {
component_status="MAJOROUTAGE" component_status="MAJOROUTAGE"
fi fi
# see https://instatus.com/help/api/incidents # see https://instatus.com/help/api/incidents
response=$(curl -s -X POST "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \ incident_id=$(curl -s -X POST "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
-H "Authorization: Bearer $INSTATUS_API_KEY" \ -H "Authorization: Bearer $INSTATUS_API_KEY" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{ -d "{
@ -68,10 +68,25 @@ create_incident() {
\"status\": \"PARTIALOUTAGE\" \"status\": \"PARTIALOUTAGE\"
} }
] ]
}") }" | jq -r '.id')
incident_id=$(echo "$response" | jq -r '.id') echo "Created incident with ID: $incident_id"
echo "$incident_id" }
# Function to check for existing unresolved incidents
check_existing_incident() {
# Fetch the latest incidents with status not equal to "RESOLVED"
local unresolved_incidents=$(curl -s -X GET "https://api.instatus.com/v1/$INSTATUS_PAGE_ID/incidents" \
-H "Authorization: Bearer $INSTATUS_API_KEY" \
-H "Content-Type: application/json" | jq -r '.incidents[] | select(.status != "RESOLVED") | .id')
if [[ -n "$unresolved_incidents" ]]; then
echo "Unresolved incidents found: $unresolved_incidents"
return 0 # Indicate that there are unresolved incidents
else
echo "No unresolved incidents found."
return 1 # Indicate that no unresolved incidents exist
fi
} }
# Check each module's accessibility # Check each module's accessibility
@ -94,20 +109,19 @@ done
# Determine overall status and update Instatus component # Determine overall status and update Instatus component
if (( status == 0 )); then if (( status == 0 )); then
echo "All modules are operational." echo "All modules are operational."
# set to
update_component_status "OPERATIONAL" update_component_status "OPERATIONAL"
else else
echo "The following modules have issues: ${failures[*]}" echo "The following modules have issues: ${failures[*]}"
# check if all modules are down
if (( ${#failures[@]} == ${#modules[@]} )); then if (( ${#failures[@]} == ${#modules[@]} )); then
update_component_status "MAJOROUTAGE" update_component_status "MAJOROUTAGE"
else else
update_component_status "PARTIALOUTAGE" update_component_status "PARTIALOUTAGE"
fi fi
# Create a new incident # Check if there is an existing incident before creating a new one
incident_id=$(create_incident) if ! check_existing_incident; then
echo "Created incident with ID: $incident_id" create_incident
fi
fi fi
exit "${status}" exit "${status}"

Loading…
Cancel
Save