Last active
December 30, 2015 17:58
-
-
Save utdrmac/ee3e4d55d8871b1ad77a to your computer and use it in GitHub Desktop.
Pushbullet Slave Watcher
This file contains 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 | |
# A title for the notification | |
title="Slave - ${HOSTNAME}" | |
# PushBullet API Token | |
# https://www.pushbullet.com/#settings/account | |
token="C17CdC7b0XXXXXXXX1idCdATgVjbfEY" | |
# Send a notification every X minutes | |
notify_every=30 | |
# Master ID | |
master_id=106 | |
### No Need To Edit Below Here Normally ### | |
notif_counter=$((6 * $notify_every)) | |
counter=1 | |
prev_err="" | |
while [ 1 ]; do | |
lag=$(/usr/bin/pt-heartbeat --check --database percona --utc --master-server-id ${master_id}) | |
mysql -e "SHOW SLAVE STATUS\G" | sed -e 's/^[[:space:]]*//' >/tmp/slave_status | |
sio_running=$(grep Slave_IO_Running: /tmp/slave_status) | |
sth_running=$(grep Slave_SQL_Running: /tmp/slave_status) | |
error=$(grep Last_Error /tmp/slave_status) | |
echo "`date` : $counter : ${sio_running} ${sth_running} Lag: ${lag} ${error}" | |
if [ "$error" != "Last_Error: " -a "$error" != "$prev_err" ] || [ $counter -gt $notif_counter ]; then | |
curl --header "Access-Token: ${token}" \ | |
--header 'Content-Type: application/json' \ | |
--data-binary "{\"body\":\"${sio_running}\n${sth_running}\nLag: ${lag}\n${error}\",\"title\":\"${title}\",\"type\":\"note\"}" \ | |
--request POST https://api.pushbullet.com/v2/pushes | |
let counter=1 | |
let prev_err=$error | |
fi | |
((counter++)) | |
sleep 10; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment