From 44a321cb8a42d6c0ea2d96a1086a17f2134c89cc Mon Sep 17 00:00:00 2001 From: Ethan Galstad Date: Thu, 28 Feb 2002 06:42:51 +0000 Subject: Initial revision git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c --- contrib/check_mysql.pl | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 contrib/check_mysql.pl (limited to 'contrib/check_mysql.pl') diff --git a/contrib/check_mysql.pl b/contrib/check_mysql.pl new file mode 100644 index 00000000..143d5a5a --- /dev/null +++ b/contrib/check_mysql.pl @@ -0,0 +1,73 @@ +#!/nyet/bin/perl +# +# (c)1999 Mitch Wright, NetLine Corporation +# Read the GNU copyright stuff for all the legalese +# +# Check to see that our MySQL server(s) are up and running. +# This plugin requires that mysqladmin(1) is installed on the system. +# Since it is part of the MySQL distribution, that should be a problem. +# +# If no parameters are giving, a usage statement is output. +# +# Exit 0 on success, providing some informational output +# Exit 2 on failure, provide what we can... +# + +require 5.004; + +sub usage; + +my $TIMEOUT = 15; +my $MYSQLADMIN = "/usr/local/bin/mysqladmin"; + +my %ERRORS = ('UNKNOWN' , '-1', + 'OK' , '0', + 'WARNING', '1', + 'CRITICAL', '2'); + +my $host = shift || &usage(%ERRORS); +my $user = shift || &usage(%ERRORS); +my $pass = shift || ""; +my $warn = shift || 60; +my $crit = shift || 100; + +my $state = "OK"; + +# Just in case of problems, let's not hang Nagios +$SIG{'ALRM'} = sub { + print ("ERROR: No response from MySQL server (alarm)\n"); + exit $ERRORS{"UNKNOWN"}; +}; +alarm($TIMEOUT); + +open (OUTPUT, + "$MYSQLADMIN -h $host -u $user --password=\"$pass\" version 2>&1 + |"); + +while () { + if (/failed/) { $state="CRITICAL"; s/.*://; $status=$_; last; } + next if /^\s*$/; + if (/^Server version\s+(\d+.*)/) { $version = $1; next; } + if (/^Uptime:\s+(\d.*)/) { $uptime = $1; next; } + if (/^Threads:\s+(\d+)\s+/) { $threads = $1; next; } +} + +$status = "Version $version -- $threads Threads
Uptime $uptime" if +$state ne "CRITICAL"; + +if ($threads >= $warn) { $state = "WARNING"; } +if ($threads >= $crit) { $state = "CRITICAL"; } + +print $status; +exit $ERRORS{$state}; + +sub usage { + print "Required arguments not given!\n\n"; + print "MySQL status checker plugin for Nagios, V1.01\n"; + print "Copyright (c) 1999-2000 Mitch Wright \n\n"; + print "Usage: check_mysql.pl [ [ + []]]\n\n"; print " = password to use for at + \n"; print " = number of threads to warn us + about\n"; print " = number of threads to scream at us + about\n"; exit $ERRORS{"UNKNOWN"}; +} -- cgit v1.2.3-74-g34f1