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 #
16 require 5.004;
18 sub usage;
20 my $TIMEOUT = 15;
21 my $MYSQLADMIN = "/usr/local/bin/mysqladmin";
23 my %ERRORS = ('UNKNOWN' , '-1',
24 'OK' , '0',
25 'WARNING', '1',
26 'CRITICAL', '2');
28 my $host = shift || &usage(%ERRORS);
29 my $user = shift || &usage(%ERRORS);
30 my $pass = shift || "";
31 my $warn = shift || 60;
32 my $crit = shift || 100;
34 my $state = "OK";
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 };
41 alarm($TIMEOUT);
43 open (OUTPUT,
44 "$MYSQLADMIN -h $host -u $user --password=\"$pass\" version 2>&1
45 |");
47 while (<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 }
55 $status = "Version $version -- $threads Threads <br>Uptime $uptime" if
56 $state ne "CRITICAL";
58 if ($threads >= $warn) { $state = "WARNING"; }
59 if ($threads >= $crit) { $state = "CRITICAL"; }
61 print $status;
62 exit $ERRORS{$state};
64 sub 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 }