summaryrefslogtreecommitdiffstats
path: root/contrib/check_mysql.pl
diff options
context:
space:
mode:
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 00000000..143d5a5a
--- /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}