Skip to content

Instantly share code, notes, and snippets.

@tomaszklim
Created September 4, 2019 09:31
Show Gist options
  • Save tomaszklim/08431793eaba39a1834070fbd8de6c8a to your computer and use it in GitHub Desktop.
Save tomaszklim/08431793eaba39a1834070fbd8de6c8a to your computer and use it in GitHub Desktop.
Edit existing Heartbeat-based check in Uptimerobot.com using API (update url and name)
#!/bin/bash
api_key="u123456-qa9oic80zsll1xi0fhbwso1"
if [ "$3" = "" ]; then
echo "usage: $0 <check-id> <search-for> <replace-with> [--execute]"
exit 0
fi
tmp=/tmp/uptimerobot-$1-$$.tmp
curl -s -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Cache-Control: no-cache" \
-d "api_key=$api_key&format=json&logs=0&alert_contacts=0&monitors=$1" \
"https://api.uptimerobot.com/v2/getMonitors" >$tmp
name=`cat $tmp |jq ".monitors[] .friendly_name" |sed s/\\"//g`
url=`cat $tmp |jq ".monitors[] .url" |sed s/\\"//g`
if [ "$url" = "" ]; then
echo "error: invalid check id"
exit 1
fi
rm $tmp
newname=`echo "$name" |sed s/$2/$3/g`
newurl=`echo "$url" |sed s/$2/$3/g`
echo "attempting to change: \"$name\" to \"$newname\""
if [ "$4" != "--execute" ]; then
exit 0
fi
echo "old url: $url"
echo "new url: $newurl"
curl -s -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Cache-Control: no-cache" \
-d "api_key=$api_key&format=json" \
-d "id=$1" \
-d "url=$newurl" \
-d "friendly_name=$newname" \
"https://api.uptimerobot.com/v2/editMonitor" |python -m json.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment