diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/check_linux_raid.pl | 80 | ||||
-rw-r--r-- | contrib/check_nagios_db.pl | 89 |
2 files changed, 169 insertions, 0 deletions
diff --git a/contrib/check_linux_raid.pl b/contrib/check_linux_raid.pl new file mode 100644 index 00000000..44f166b1 --- /dev/null +++ b/contrib/check_linux_raid.pl | |||
@@ -0,0 +1,80 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | |||
3 | # Copyright (c) 2002 ISOMEDIA, Inc. | ||
4 | # Written by Steve Milton | ||
5 | # Released under the GNU Public License | ||
6 | # | ||
7 | # This program is free software; you can redistribute it and/or modify | ||
8 | # it under the terms of the GNU General Public License as published by | ||
9 | # the Free Software Foundation; either version 2 of the License, or | ||
10 | # (at your option) any later version. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | # | ||
17 | # You should have received a copy of the GNU General Public License | ||
18 | # along with this program; if not, write to the Free Software | ||
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | # | ||
21 | # Usage: check_raid <raid-name> | ||
22 | # Example: check_raid md0 | ||
23 | # WARNING md0 status=[UUU_U], recovery=46.4%, finish=123.0min | ||
24 | |||
25 | use strict; | ||
26 | |||
27 | my %ERRORS=('DEPENDENT'=>4,'UNKNOWN'=>3,'OK'=>0,'WARNING'=>1,'CRITICAL'=>2); | ||
28 | |||
29 | open (MDSTAT, "</proc/mdstat") or die "Failed to open /proc/mdstat"; | ||
30 | my $found = 0; | ||
31 | my $status = ""; | ||
32 | my $recovery = ""; | ||
33 | my $finish = ""; | ||
34 | my $active = ""; | ||
35 | while(<MDSTAT>) { | ||
36 | if ($found) { | ||
37 | if (/(\[[_U]+\])/) { | ||
38 | $status = $1; | ||
39 | } elsif (/recovery = (.*?)\s/) { | ||
40 | $recovery = $1; | ||
41 | ($finish) = /finish=(.*?min)/; | ||
42 | } | ||
43 | } else { | ||
44 | if (/$ARGV[0]/) { | ||
45 | $found = 1; | ||
46 | if (/active/) { | ||
47 | $active = 1; | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | my $msg = "FAILURE"; | ||
54 | my $code = "UNKNOWN"; | ||
55 | if ($status =~ /_/) { | ||
56 | if ($recovery) { | ||
57 | $msg = sprintf "%s status=%s, recovery=%s, finish=%s\n", | ||
58 | $ARGV[0], $status, $recovery, $finish; | ||
59 | $code = "WARNING"; | ||
60 | } else { | ||
61 | $msg = sprintf "%s status=%s\n", $ARGV[0], $status; | ||
62 | $code = "CRITICAL"; | ||
63 | } | ||
64 | } elsif ($status =~ /U+/) { | ||
65 | $msg = sprintf "%s status=%s\n", $ARGV[0], $status; | ||
66 | $code = "OK"; | ||
67 | } else { | ||
68 | if ($active) { | ||
69 | $msg = sprintf "%s active with no status information.\n", | ||
70 | $ARGV[0]; | ||
71 | $code = "OK"; | ||
72 | } else { | ||
73 | $msg = sprintf "%s does not exist.\n", $ARGV[0]; | ||
74 | $code = "CRITICAL"; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | print $code, " ", $msg; | ||
79 | exit ($ERRORS{$code}); | ||
80 | |||
diff --git a/contrib/check_nagios_db.pl b/contrib/check_nagios_db.pl new file mode 100644 index 00000000..5811d7c6 --- /dev/null +++ b/contrib/check_nagios_db.pl | |||
@@ -0,0 +1,89 @@ | |||
1 | #!/usr/local/bin/perl -w | ||
2 | |||
3 | use strict; | ||
4 | $|++; | ||
5 | |||
6 | use vars qw/$opt_e $opt_c/; | ||
7 | |||
8 | $ENV{"PATH"} = "/usr/bin:/usr/sbin:/bin"; | ||
9 | |||
10 | use Getopt::Std; | ||
11 | use DBI; | ||
12 | |||
13 | my $driver = "mysql"; | ||
14 | |||
15 | my $CFG_DEF = "/opt/nagios/etc/cgi.cfg"; | ||
16 | my $QUERY = "select *, UNIX_TIMESTAMP(last_update) as ut from programstatus;"; | ||
17 | my $EXPIRE_DEF = 5; ## expressed in minutes | ||
18 | my $PROCCNT = 0; | ||
19 | |||
20 | use constant OK => 1; | ||
21 | use constant WARN => 2; | ||
22 | |||
23 | my $STAT = WARN; | ||
24 | |||
25 | sub usage { | ||
26 | print STDERR "\n"; | ||
27 | print STDERR "$0 -F -e <expire time in minutes> -C <process string>\n"; | ||
28 | print STDERR "\n"; | ||
29 | exit -1; | ||
30 | } | ||
31 | |||
32 | getopt("e:c:"); | ||
33 | |||
34 | my $EXPIRE = $opt_e || $EXPIRE_DEF; | ||
35 | my $CFG = $opt_c || $CFG_DEF; | ||
36 | |||
37 | ( -f $CFG ) or die "Can't open config file '$CFG': $!\n"; | ||
38 | |||
39 | my ($dbhost, $dbport, $dbuser, $dbpass, $dbname); | ||
40 | |||
41 | open(F, "< $CFG"); | ||
42 | while ( <F> ) { | ||
43 | if (/^xsddb_host=(.+)/) { $dbhost = $1; next; }; | ||
44 | if (/^xsddb_port=(.+)/) { $dbport = $1; next; }; | ||
45 | if (/^xsddb_database=(.+)/) { $dbname = $1; next; }; | ||
46 | if (/^xsddb_username=(.+)/) { $dbuser = $1; next; }; | ||
47 | if (/^xsddb_password=(.+)/) { $dbpass = $1; next; }; | ||
48 | } | ||
49 | close(F); | ||
50 | |||
51 | # print "($dbhost, $dbport, $dbuser, $dbpass, $dbname)\n"; | ||
52 | |||
53 | my $dsn = "DBI:$driver:database=$dbname;host=$dbhost;port=$dbport"; | ||
54 | my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'RaiseError' => 1}); | ||
55 | |||
56 | my $sth = $dbh->prepare($QUERY); | ||
57 | if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } | ||
58 | $sth->execute; | ||
59 | if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } | ||
60 | |||
61 | my %status = (); | ||
62 | |||
63 | my $names = $sth->{'NAME'}; | ||
64 | my $numFields = $sth->{'NUM_OF_FIELDS'}; | ||
65 | my $ref = $sth->fetchrow_arrayref; | ||
66 | for (my $i = 0; $i < $numFields; $i++) { | ||
67 | $status{"$$names[$i]"} = $$ref[$i]; | ||
68 | } | ||
69 | |||
70 | #foreach (keys(%status)) { | ||
71 | # print "$_: $status{$_}\n"; | ||
72 | #} | ||
73 | |||
74 | my $lastupdated = time() - $status{"ut"}; | ||
75 | if ( $lastupdated < ($EXPIRE*60) ) { ## convert $EXPIRE to seconds | ||
76 | $STAT = OK; | ||
77 | } | ||
78 | |||
79 | open(PS, "ps -eaf | grep $status{nagios_pid} | grep -v grep | "); | ||
80 | $PROCCNT = 0; | ||
81 | while(<PS>) { | ||
82 | $PROCCNT++; | ||
83 | } | ||
84 | close(PS); | ||
85 | |||
86 | if ( $STAT == OK ) { | ||
87 | print "Nagios OK: located $PROCCNT processes, program status updated $lastupdated seconds ago\n"; | ||
88 | } | ||
89 | |||