Skip to content

Instantly share code, notes, and snippets.

@teeebs
Last active June 30, 2017 20:34
Show Gist options
  • Save teeebs/3b487ee4b6bb05732a591b3513c12438 to your computer and use it in GitHub Desktop.
Save teeebs/3b487ee4b6bb05732a591b3513c12438 to your computer and use it in GitHub Desktop.
Script to mute a monitor when host shuts down, then unmute and resolve when back online
vagrant@kratos:~$ chmod +x manage_monitor.sh
vagrant@kratos:~$ sudo cp manage_monitor.sh /etc/init.d/manage_monitor
vagrant@kratos:~$ sudo update-rc.d manage_monitor defaults
#!/bin/sh
# Make sure to populate the variables below with ones for your account
api_key=xxx
app_key=xxx
monitor_id=12345
monitor_scope=host:kratos
case "$1" in
stop)
# Mute monitor
echo "Muting host monitor..."
curl -X POST "https://app.datadoghq.com/api/v1/monitor/${monitor_id}/mute?api_key=${api_key}&application_key=${app_key}"
;;
start)
echo "Resolving and unmuting host monitor..."
# Resolve monitor
curl -X POST -H "Content-type: application/json" -d "{ \"resolve\": [{\"${monitor_id}\": \"${monitor_scope}\"}] }" "https://app.datadoghq.com/monitor/bulk_resolve?api_key=${api_key}&application_key=${app_key}"
# Unmute monitor
curl -X POST "https://app.datadoghq.com/api/v1/monitor/${monitor_id}/unmute?api_key=${api_key}&application_key=${app_key}"
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment