Skip to content

Instantly share code, notes, and snippets.

@mskian
Last active April 11, 2019 15:09
Show Gist options
  • Save mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9 to your computer and use it in GitHub Desktop.
Save mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9 to your computer and use it in GitHub Desktop.
Website HTTP Status Checker - Get Monitor Notification on Pushbullet
#!/bin/bash
# Purpose: Website HTTP Status Checker
# Source: https://gist.github.com/mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9
# Developer: Santhosh Veer
# Domain to check
DOMAIN="https://example.com"
# Pushbullet API Key - https://docs.pushbullet.com/
PUSHBULLET="<PUSHBULLET API KEY>"
# HTTP Status Code - https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
HTTP200="200"
HTTP503="503"
HTTP404="404"
HTTP500="500"
HTTP502="502"
HTTP400="400"
HTTP408="408"
# make the HTTP Status Check
GETSTATUS(){
curl -s -I $DOMAIN | grep HTTP/ | awk '{print $2}'
}
STATUSCHECK=$(GETSTATUS)
# check if HTTP Status Code are equal and send pushbullet notification
if [ "$STATUSCHECK" == "$HTTP200" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 200 - Health:Good","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP503" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 503 - Health:Service unavailable","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP404" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 404 - Health:Not Found","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP500" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 500 - Health:Internal Server Error","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP502" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 502 - Health:Bad Gateway","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP400" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 400 - Health:Bad Request","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP408" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 408 - Health:Request Timeout","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
fi
@mcnaveen
Copy link

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment