[packages/monitoring-plugin-check_mysql-heartbeat: 4/10] - add warning/critical levels, check them

glen glen at pld-linux.org
Tue Mar 22 12:32:41 CET 2016


commit 2abe1e6de0b778cc401897e32890d0f8c5b840c3
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sun Sep 2 09:17:50 2012 +0000

    - add warning/critical levels, check them
    
    Changed files:
        check_mysql-heartbeat.sh -> 1.4

 check_mysql-heartbeat.sh | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/check_mysql-heartbeat.sh b/check_mysql-heartbeat.sh
index bdbcc42..c9eb042 100755
--- a/check_mysql-heartbeat.sh
+++ b/check_mysql-heartbeat.sh
@@ -16,11 +16,13 @@ port=
 username=
 password=
 database=
+warning=200
+critical=400
 
 die() {
 	eval local rc=\$STATE_$1
 	[ "$rc" ] || rc=$STATE_UNKNOWN
-	echo "$2"
+	echo "$1: $2"
 	exit $rc
 }
 
@@ -33,6 +35,8 @@ Usage: check_mysql-heartbeat
     --pt, --percona-toolkit
        Uses percona-toolkit: pt-hearbeat
 
+    -w SECONDS, --warning SECONDS
+    -c SECONDS,--critical SECONDS
     -H HOSTNAME, --host HOSTNAME
     -P PORT, --port PORT
     -u USERNAME, --username USERNAME
@@ -42,7 +46,7 @@ EOF
 }
 
 # Parse arguments
-args=$(getopt -o hVH:P:u:p:D: --long help,version,mk,maatkit,pt,percona-tookit,host:,port:,username:,password:,database: -u -n $PROGRAM -- "$@")
+args=$(getopt -o hVw:c:H:P:u:p:D: --long help,version,warning:,critical:,mk,maatkit,pt,percona-tookit,host:,port:,username:,password:,database: -u -n $PROGRAM -- "$@")
 if [ $? != 0 ]; then
 	usage
 	exit 1
@@ -66,6 +70,14 @@ while :; do
 	--pt|--percona-toolkit)
 		heartbeat=mk-heartbeat
 		;;
+	-c|--critical)
+		shift
+		critical=$1
+		;;
+	-w|--warning)
+		shift
+		warning=$1
+		;;
 	-H|--host)
 		shift
 		hostname=$1
@@ -101,9 +113,18 @@ if [ -z "$hostname" ]; then
 	die UNKNOWN "No hostname given"
 fi
 
-out=$($heartbeat ${database:+-D $database} --check -h $hostname ${username:+-u $username} ${password:+-p $password} 2>&1)
+# check out config errors
+if [ $warning -gt $critical ]; then
+	die UNKNOWN "Warning level bigger than critical level"
+fi
+
+secs=$($heartbeat ${database:+-D $database} --check -h $hostname ${username:+-u $username} ${password:+-p $password} 2>&1)
 rc=$?
 if [ "$rc" != 0 ]; then
-	die UNKNOWN "$out"
+	die UNKNOWN "$secs"
 fi
-die OK "OK $heartbeat on $hostname @$out"
+
+[ $secs -gt $critical ] && die CRITICAL "$heartbeat on $hostname $secs seconds over critical treshold $critical seconds"
+[ $secs -gt $warning ] && die WARNING "$heartbeat on $hostname $secs seconds over warning treshold $warning seconds"
+
+die OK "$heartbeat on $hostname @$secs seconds"
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/monitoring-plugin-check_mysql-heartbeat.git/commitdiff/c97836d2e3bccf7d77e278a624bc4dd433f544f9



More information about the pld-cvs-commit mailing list