summaryrefslogtreecommitdiffstats
path: root/contrib/check_nagios_db_pg.pl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-09-02 13:16:24 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-09-02 13:16:24 +0200
commitb15adb7762b6caaecaa83637abfcf5fdb4802092 (patch)
tree64eddbe2aa1a7f98a140be0f7973f05d7a781ae0 /contrib/check_nagios_db_pg.pl
parentc4d5882b9e1d07c7b61091062b7d085fa5f00284 (diff)
downloadmonitoring-plugins-b15adb7762b6caaecaa83637abfcf5fdb4802092.tar.gz
Remove "contrib" plugins
These days, sites such as "Nagios Exchange" are a much better place for publishing plugins not maintained by the Plugins Development Team.
Diffstat (limited to 'contrib/check_nagios_db_pg.pl')
-rw-r--r--contrib/check_nagios_db_pg.pl91
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
3use strict;
4$|++;
5
6use vars qw/$opt_e $opt_c/;
7
8$ENV{"PATH"} = "/usr/bin:/usr/sbin:/bin";
9
10use Getopt::Std;
11use DBI;
12
13my $driver = "Pg";
14
15my $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
19my $QUERY = "select *, round(date_part('epoch',last_update)) as ut from programstatus;";
20my $EXPIRE_DEF = 5; ## expressed in minutes
21my $PROCCNT = 0;
22
23use constant OK => 1;
24use constant WARN => 2;
25
26my $STAT = WARN;
27
28sub usage {
29 print STDERR "\n";
30 print STDERR "$0 -F -e &lt;expire time in minutes&gt; -C &lt;process string&gt;\n";
31 print STDERR "\n";
32 exit -1;
33}
34
35getopt("e:c:");
36
37my $EXPIRE = $opt_e || $EXPIRE_DEF;
38my $CFG = $opt_c || $CFG_DEF;
39
40( -f $CFG ) or die "Can't open config file '$CFG': $!\n";
41
42my ($dbhost, $dbport, $dbuser, $dbpass, $dbname);
43
44open(F, "< $CFG");
45while ( <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}
52close(F);
53
54#print "($dbhost, $dbport, $dbuser, $dbpass, $dbname)\n";
55
56my $dsn = "DBI:$driver:dbname=$dbname;host=$dbhost;port=$dbport";
57my $dbh = DBI->connect($dsn, $dbuser, $dbpass, {'RaiseError' => 1});
58
59my $sth = $dbh->prepare($QUERY);
60if (!$sth) { die "Error:" . $dbh->errstr . "\n"; }
61$sth->execute;
62if (!$sth->execute) { die "Error:" . $sth->errstr . "\n"; }
63
64my %status = ();
65
66my $names = $sth->{'NAME'};
67my $numFields = $sth->{'NUM_OF_FIELDS'};
68my $ref = $sth->fetchrow_arrayref;
69for (my $i = 0; $i < $numFields; $i++) {
70 $status{"$$names[$i]"} = $$ref[$i];
71}
72
73#foreach (keys(%status)) {
74# print "$_: $status{$_}\n";
75#}
76
77my $lastupdated = time() - $status{"ut"};
78if ( $lastupdated < ($EXPIRE*60) ) { ## convert $EXPIRE to seconds
79 $STAT = OK;
80}
81
82open(PS, "ps -eaf | grep $status{nagios_pid} | grep -v grep | ");
83$PROCCNT = 0;
84while(<PS>) {
85 $PROCCNT++;
86}
87close(PS);
88
89if ( $STAT == OK ) {
90 print "Nagios OK: located $PROCCNT processes, program status updated $lastupdated seconds ago\n";
91}