@@ -48,7 +48,7 @@ update_component_status() {
4848
4949# Function to create an incident
5050create_incident () {
51- local incident_name=" Testing Instatus "
51+ local incident_name=" Degraded Service "
5252 local message=" The following modules are experiencing issues:\n"
5353 for i in " ${! failures[@]} " ; do
5454 message+=" $(( i + 1 )) . ${failures[$i]} \n"
@@ -59,7 +59,7 @@ create_incident() {
5959 component_status=" MAJOROUTAGE"
6060 fi
6161 # 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" \
6363 -H " Authorization: Bearer $INSTATUS_API_KEY " \
6464 -H " Content-Type: application/json" \
6565 -d " {
@@ -74,10 +74,25 @@ create_incident() {
7474 \" status\" : \" PARTIALOUTAGE\"
7575 }
7676 ]
77- }" )
77+ }" | jq -r ' .id ' )
7878
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
8196}
8297
8398force_redeploy_registry () {
@@ -174,9 +189,10 @@ else
174189 update_component_status " PARTIALOUTAGE"
175190 fi
176191
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
180196
181197 # If a module is down, force a reployment to try getting things back online
182198 # ASAP
0 commit comments