Created
July 25, 2019 08:11
-
-
Save katzefudder/811e6dace4f1118d44fc666c1220a324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# create and delete maintenance | |
set -e | |
GENIEKEY=YourOpsGenieKey | |
INTEGRATION_ID=YourIntegrationId | |
MAINTENANCE_DESCRIPTION="RepositorySyncronization" | |
# OpsGenie expects a format like yyyy-MM-dd'T'HH:mm:ssZ) (e.g. 2017-01-15T08:00:00+02:00) | |
DURATION=30 | |
FROM_TIME=$(date --iso-8601=seconds) | |
TO_TIME=$(date --iso-8601=seconds -d "+$DURATION min") | |
echo "Setting maintenance from $FROM_TIME to $TO_TIME" | |
# create the maintenance, store the ID in a variable for later reference | |
MAINTENANCE_ID=$(curl -s -X POST 'https://api.opsgenie.com/v1/maintenance' --header "Authorization: GenieKey $GENIEKEY" --header 'Content-Type: application/json' --data '{ | |
"description": "'$MAINTENANCE_DESCRIPTION'", | |
"time": { | |
"type" : "schedule", | |
"startDate": "'$FROM_TIME'", | |
"endDate": "'$TO_TIME'" | |
}, | |
"rules": [ | |
{ | |
"entity": { | |
"id": "'$INTEGRATION_ID'", | |
"type": "integration" | |
} | |
} | |
] | |
}' | jq '.data.id') | |
echo "Maintenance created: $MAINTENANCE_ID" | |
# delete created maintenance | |
curl -X DELETE https://api.opsgenie.com/v1/maintenance/"$MAINTENANCE_ID" --header 'Authorization: GenieKey $GENIEKEY' | |
echo "Maintenance deleted: $MAINTENANCE_ID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment