Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## machine info
- [root@VIRTCENT11 ~]# cat /etc/redhat-release
- CentOS release 5.6 (Final)
- [root@VIRTCENT11 ~]# uname -a
- Linux VIRTCENT11 2.6.18-194.el5xen #1 SMP Fri Apr 2 15:34:40 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
- ## nagios version
- [root@VIRTCENT11 ~]# /usr/local/nagios/bin/nagios --version
- Nagios Core 3.2.3
- Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
- Copyright (c) 1999-2009 Ethan Galstad
- Last Modified: 10-03-2010
- License: GPL
- ## check_mysqllag plugin error
- (Return code of 127 is out of bounds - plugin may be missing)
- ## here is the command definition
- # check_mysql
- define command{
- command_name check_mysqllag
- command_line $USER1$/check_mysqllag -H $HOSTADDRESS$ -p 3306 -v $ARG1$ $ARG2$
- }
- ## here is the service definition
- define service{
- use generic-service ; Name of service template to use
- hostgroup_name db-servers
- service_description MySQL Lag
- check_command check_mysqllag
- notifications_enabled 0
- }
- ## check_mysqllag script
- [root@virtcent10:/usr/local/nagios/libexec] #cat check_mysqllag
- #! /bin/sh
- STATE_OK=0
- STATE_WARNING=1
- STATE_CRITICAL=2
- STATE_UNKNOWN=3
- STATE_DEPENDENT=4
- mysqlpath='/usr/bin/mysql'
- warn=30
- crit=60
- null="NULL"
- usage1="Usage: $0 -uroot -psecret [-w <warn>] [-c <crit>]"
- usage2="<warn> is lag time, in seconds, to warn at. Default is 30."
- usage3="<crit> is lag time, in seconds, to be critical at. Default is 60."
- exitstatus=$STATE_WARNING #default
- while test -n "$1"; do
- case "$1" in
- -c)
- crit=$2
- shift
- ;;
- -w)
- warn=$2
- shift
- ;;
- -u)
- user=$2
- shift
- ;;
- -p)
- pass=$2
- shift
- ;;
- -h)
- echo $usage1;
- echo
- echo $usage2;
- echo $usage3;
- exit $STATE_UNKNOWN
- ;;
- -H)
- host=$2
- shift
- ;;
- *)
- echo "Unknown argument: $1"
- echo $usage1;
- echo
- echo $usage2;
- echo $usage3;
- exit $STATE_UNKNOWN
- ;;
- esac
- shift
- done
- seconds=`$mysqlpath/mysql -u $user -p$pass -e 'show slave status\G' | /bin/grep Seconds_Behind_Master | /bin/cut -f2 -d:`
- # on the number line, we need to test 6 cases:
- # 0-----w-----c----->
- # 0, 0<lag<w, w, w<lag<c, c, c<lag
- # which we simplify to
- # lag>=c, w<=lag<c, 0<=lag<warn
- # if null, critical
- if [ $seconds = $null ]; then
- echo CRITICAL - Slave is $seconds seconds behind
- exit $STATE_CRITICAL;
- fi
- #w<=lag<c
- if [ $seconds -lt $crit ]; then
- if [ $seconds -ge $warn ]; then
- echo WARNING - Slave is $seconds seconds behind
- exit $STATE_WARNING;
- fi
- fi
- if [ $seconds -ge $crit ]; then
- echo CRITICAL - Slave is $seconds seconds behind
- exit $STATE_CRITICAL;
- fi
- # 0<=lag<warn
- if [ $seconds -lt $warn ]; then
- echo OK - Slave is $seconds seconds behind
- exit $STATE_OK;
- fi
Add Comment
Please, Sign In to add comment