Skip to content

Instantly share code, notes, and snippets.

@bcicen
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcicen/9984161 to your computer and use it in GitHub Desktop.
Save bcicen/9984161 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Nagios plugin to check for inserts updates deletes drops alters creates on slave DBs due to http://bugs.mysql.com/bug.php?id=58669
function usage(){
echo "Usage: $0 [mysql socket]"
}
if [ $# -eq 0 ]; then
echo -n "Missing mysql socket. "
usage
exit $STATE_UNKNOWN
fi
mysql_socket=$1
binlog_dir=$(dirname $(grep -v '^#' /etc/mysql/my.cnf | grep 'log-bin' | cut -f2 -d\=))
binlog=$(mysql --skip-column-names -S $mysql_socket -B -e 'show binary logs;' | tail -1 | awk '{print $1}')
results=$(strings ${binlog_dir}/${binlog} | egrep -i '(insert|update|delete|drop|alter|create)' | wc -l)
case $results in
[0]*)
echo "OK - No direct slave changes found"
exit 0
;;
[1]*)
echo "WARNING - Direct slave modification found"
exit 1
;;
[2]*)
echo "CRITICAL - Multiple direct slave modifications found"
exit 2
;;
*)
echo "UNKNOWN - slave binlog check failed"
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment