/[mon-modules]/pgsql.monitor
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /pgsql.monitor

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Wed Jul 10 22:07:42 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.5: +1 -1 lines
renamed to pgsql.monitor to avoid confusion with postgresql.monitor

1 dpavlin 1.4 #!/usr/bin/perl -w
2 dpavlin 1.1 #
3 dpavlin 1.5 # Monitor multiple postgresql databases on different hosts
4     #
5     # Based on postgresql.monitor 1.3
6     # by Severin Luftensteiner <severin.luftensteiner@cubit.at>
7     #
8 dpavlin 1.6 #Usage: pgsql.monitor username[:password]\@host/database ...
9 dpavlin 1.1 #
10     # a monitor to determine if a PostgreSQL database server is operational
11     #
12     # Rather than use tcp.monitor to ensure that your SQL server is responding
13 dpavlin 1.5 # on the proper port, this attempts to connect to and count all tables
14     # in given database on given server.
15     #
16     # You can use this monitor along with fping+args which also knows how to
17     # ping hosts in that user@host/dabase format.
18 dpavlin 1.1 #
19     # This monitor requires the perl5 DBI, DBD::mSQL and DBD::mysql modules,
20     # available from CPAN (http://www.cpan.org)
21     #
22     # Copyright (C) 2001, CubIT IT Solutions
23     # Written by Severin Luftensteiner <severin.luftensteiner@cubit.at>
24 dpavlin 1.5 # Copyright (C) 2002, Dobrica Pavlinusic <dpavlin@rot13.org>
25 dpavlin 1.1 #
26     # This program is free software; you can redistribute it and/or modify
27     # it under the terms of the GNU General Public License as published by
28     # the Free Software Foundation; either version 2 of the License, or
29     # (at your option) any later version.
30     #
31     # This program is distributed in the hope that it will be useful,
32     # but WITHOUT ANY WARRANTY; without even the implied warranty of
33     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34     # GNU General Public License for more details.
35     #
36     # You should have received a copy of the GNU General Public License
37     # along with this program; if not, write to the Free Software
38     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39     #
40    
41     use DBI;
42 dpavlin 1.4 use strict;
43 dpavlin 1.1
44 dpavlin 1.4 if (! @ARGV) {
45 dpavlin 1.1 print <<EOP1;
46 dpavlin 1.4 Usage: postresql.monitor username[:password]\@host/database ...
47 dpavlin 1.1 EOP1
48 dpavlin 1.4 exit 1;
49 dpavlin 1.1 }
50    
51 dpavlin 1.3 my @test_db;
52 dpavlin 1.4 my @failures;
53 dpavlin 1.3
54     foreach (@ARGV) {
55 dpavlin 1.4 if (m/^([^:]+):?([^\@]*)\@([^\/]+)\/?(.*)$/) {
56     push @test_db, { user => $1, passwd => $2, host => $3, database => $4 };
57 dpavlin 1.3 } else {
58 dpavlin 1.4 push @failures, "Can't parse configuration: host '$_' not in username:password\@host/database format!";
59 dpavlin 1.3 }
60     }
61 dpavlin 1.1
62 dpavlin 1.4 foreach (@test_db) {
63     my $dbh = DBI->connect( "DBI:Pg:dbname=$_->{database};host=$_->{host};", $_->{user}, $_->{passwd} );
64     if( ! $dbh ) {
65     push @failures,"Could not connect server $_->{host}, database $_->{database}: " . $DBI::errstr;
66     } else {
67     my $sth = $dbh->prepare("select count(*) from pg_tables where tablename not like 'pg_%'");
68     if (! $sth->execute() ) {
69     push @failures, "Can't find out number of tables on $_->{host}, database $_->{database} " . $DBI::errstr;
70     } else {
71     my ($nr) = $sth->fetchrow_array;
72     if ($nr == 0) {
73     push @failures, "No tables on $_->{host}, database $_->{database} (turn off monitoring for this database?)";
74     }
75     }
76     $sth->finish();
77     }
78     if ($dbh) {
79     $dbh->disconnect();
80     }
81 dpavlin 1.1 }
82 dpavlin 1.3
83 dpavlin 1.1 if (@failures) {
84     print join (", ", @failures), "\n";
85     exit 1;
86     };
87     exit 0;

  ViewVC Help
Powered by ViewVC 1.1.26