Skip to content

Instantly share code, notes, and snippets.

@tomaszklim
Created January 8, 2019 11:53
Show Gist options
  • Save tomaszklim/a6ccacca234b36468e0b76f4e9d69660 to your computer and use it in GitHub Desktop.
Save tomaszklim/a6ccacca234b36468e0b76f4e9d69660 to your computer and use it in GitHub Desktop.
Add new Heartbeat-based check to Uptimerobot.com using API
#!/bin/bash
api_key="u123456-qa9oic80zsll1xi0fhbwso1"
alert_contacts="0123456_0_0-2761234_0_0"
baseurl="https://serverfarmer.home.pl/heartbeat/query.php"
db="id_myaccount.txt"
# 300 for free accounts, 60 for paid accounts
interval=300
host=$1
service=$2
safehost=`echo $1 |tr '.' '_'`
short=`echo $1 |cut -d'.' -f1`
friendly_name="$short - $service"
id="${service}_${safehost}"
url="$baseurl?id=$id"
if grep -qFx $id $db; then
echo "id $id already added"
exit 0
fi
echo "attempting to add: \"$friendly_name\""
if [ "$3" != "--execute" ]; then
exit 0
fi
echo "url: $url"
echo "ctx: $alert_contacts"
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 "type=2&keyword_type=2&keyword_value=ALIVE&interval=$interval" \
-d "url=$url" \
-d "friendly_name=$friendly_name" \
-d "alert_contacts=$alert_contacts" \
"https://api.uptimerobot.com/v2/newMonitor" |python -m json.tool
echo $id >>$db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment