diff options
Diffstat (limited to 'contrib/check_nagios_db_pg.pl')
-rw-r--r-- | contrib/check_nagios_db_pg.pl | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/contrib/check_nagios_db_pg.pl b/contrib/check_nagios_db_pg.pl deleted file mode 100644 index 99e5d4ed..00000000 --- a/contrib/check_nagios_db_pg.pl +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | #!/usr/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 = "Pg"; | ||
14 | |||
15 | my $CFG_DEF = "/etc/nagios/cgi.cfg"; | ||
16 | # this works only in mysql | ||
17 | # my $QUERY = "select *, UNIX_TIMESTAMP(last_update) as ut from programstatus;"; | ||
18 | # the following is the same for postgres | ||
19 | my $QUERY = "select *, round(date_part('epoch',last_update)) as ut from programstatus;"; | ||
20 | my $EXPIRE_DEF = 5; ## expressed in minutes | ||
21 | my $PROCCNT = 0; | ||
22 | |||
23 | use constant OK => 1; | ||
24 | use constant WARN => 2; | ||
25 | |||
26 | my $STAT = WARN; | ||
27 | |||
28 | sub usage { | ||
29 | print STDERR "\n"; | ||
30 | print STDERR "$0 -F -e <expire time in minutes> -C <process string>\n"; | ||
31 | print STDERR "\n"; | ||
32 | exit -1; | ||
33 | } | ||
34 | |||
35 | getopt("e:c:"); | ||
36 | |||
37 | my $EXPIRE = $opt_e || $EXPIRE_DEF; | ||
38 | my $CFG = $opt_c || $CFG_DEF; | ||
39 | |||
40 | ( -f $CFG ) or die "Can't open config file '$CFG': $!\n"; | ||
41 | |||
42 | my ($dbhost, $dbport, $dbuser, $dbpass, $dbname); | ||
43 | |||
44 | open(F, "< $CFG"); | ||
45 | while ( <F> ) { | ||
46 | if (/^xsddb_host=(.+)/) { $dbhost = $1; next; }; | ||
47 | if (/^xsddb_port=(.+)/) { $dbport = $1; next; }; | ||
48 | if (/^xsddb_database=(.+)/) { $dbname = $1; next; }; | ||
49 | if (/^xsddb_username=(.+)/) { $dbuser = $1; next; }; | ||
50 | if (/^xsddb_password=(.+)/) { $dbpass = $1; next; }; | ||
51 | } | ||
52 | close(F); | ||
53 | |||
54 | #print "($dbhost, $dbport, $dbuser, $dbpass, $dbname)\n"; | ||
55 | |||
56 | my $dsn = "DBI:$driver:dbname=$dbname;host=$dbhost;port=$dbport"; | ||
57 | my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'RaiseError' => 1}); | ||
58 | |||
59 | my $sth = $dbh->prepare($QUERY); | ||
60 | if (!$sth) { die "Error:" . $dbh->errstr . "\n"; } | ||
61 | $sth->execute; | ||
62 | if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; } | ||
63 | |||
64 | my %status = (); | ||
65 | |||
66 | my $names = $sth->{'NAME'}; | ||
67 | my $numFields = $sth->{'NUM_OF_FIELDS'}; | ||
68 | my $ref = $sth->fetchrow_arrayref; | ||
69 | for (my $i = 0; $i < $numFields; $i++) { | ||
70 | $status{"$$names[$i]"} = $$ref[$i]; | ||
71 | } | ||
72 | |||
73 | #foreach (keys(%status)) { | ||
74 | # print "$_: $status{$_}\n"; | ||
75 | #} | ||
76 | |||
77 | my $lastupdated = time() - $status{"ut"}; | ||
78 | if ( $lastupdated < ($EXPIRE*60) ) { ## convert $EXPIRE to seconds | ||
79 | $STAT = OK; | ||
80 | } | ||
81 | |||
82 | open(PS, "ps -eaf | grep $status{nagios_pid} | grep -v grep | "); | ||
83 | $PROCCNT = 0; | ||
84 | while(<PS>) { | ||
85 | $PROCCNT++; | ||
86 | } | ||
87 | close(PS); | ||
88 | |||
89 | if ( $STAT == OK ) { | ||
90 | print "Nagios OK: located $PROCCNT processes, program status updated $lastupdated seconds ago\n"; | ||
91 | } | ||