summaryrefslogtreecommitdiffstats
path: root/contrib/check_mysql.pl
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/check_mysql.pl
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_mysql.pl')
-rw-r--r--contrib/check_mysql.pl73
1 files changed, 73 insertions, 0 deletions
diff --git a/contrib/check_mysql.pl b/contrib/check_mysql.pl
new file mode 100644
index 0000000..143d5a5
--- /dev/null
+++ b/contrib/check_mysql.pl
@@ -0,0 +1,73 @@
1#!/nyet/bin/perl
2#
3# (c)1999 Mitch Wright, NetLine Corporation
4# Read the GNU copyright stuff for all the legalese
5#
6# Check to see that our MySQL server(s) are up and running.
7# This plugin requires that mysqladmin(1) is installed on the system.
8# Since it is part of the MySQL distribution, that should be a problem.
9#
10# If no parameters are giving, a usage statement is output.
11#
12# Exit 0 on success, providing some informational output
13# Exit 2 on failure, provide what we can...
14#
15
16require 5.004;
17
18sub usage;
19
20my $TIMEOUT = 15;
21my $MYSQLADMIN = "/usr/local/bin/mysqladmin";
22
23my %ERRORS = ('UNKNOWN' , '-1',
24 'OK' , '0',
25 'WARNING', '1',
26 'CRITICAL', '2');
27
28my $host = shift || &usage(%ERRORS);
29my $user = shift || &usage(%ERRORS);
30my $pass = shift || "";
31my $warn = shift || 60;
32my $crit = shift || 100;
33
34my $state = "OK";
35
36# Just in case of problems, let's not hang Nagios
37$SIG{'ALRM'} = sub {
38 print ("ERROR: No response from MySQL server (alarm)\n");
39 exit $ERRORS{"UNKNOWN"};
40};
41alarm($TIMEOUT);
42
43open (OUTPUT,
44 "$MYSQLADMIN -h $host -u $user --password=\"$pass\" version 2>&1
45 |");
46
47while (<OUTPUT>) {
48 if (/failed/) { $state="CRITICAL"; s/.*://; $status=$_; last; }
49 next if /^\s*$/;
50 if (/^Server version\s+(\d+.*)/) { $version = $1; next; }
51 if (/^Uptime:\s+(\d.*)/) { $uptime = $1; next; }
52 if (/^Threads:\s+(\d+)\s+/) { $threads = $1; next; }
53}
54
55$status = "Version $version -- $threads Threads <br>Uptime $uptime" if
56$state ne "CRITICAL";
57
58if ($threads >= $warn) { $state = "WARNING"; }
59if ($threads >= $crit) { $state = "CRITICAL"; }
60
61print $status;
62exit $ERRORS{$state};
63
64sub usage {
65 print "Required arguments not given!\n\n";
66 print "MySQL status checker plugin for Nagios, V1.01\n";
67 print "Copyright (c) 1999-2000 Mitch Wright \n\n";
68 print "Usage: check_mysql.pl <host> <user> [<pass> [<warn>
69 [<crit>]]]\n\n"; print " <pass> = password to use for <user> at
70 <host>\n"; print " <warn> = number of threads to warn us
71 about\n"; print " <crit> = number of threads to scream at us
72 about\n"; exit $ERRORS{"UNKNOWN"};
73}