/[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.3 - (hide annotations)
Wed Jul 10 09:26:32 2002 UTC (17 years, 4 months ago) by dpavlin
Branch: MAIN
Changes since 1.2: +18 -0 lines
supports format: username[:password]@hostname[/arguments]

1 dpavlin 1.1 #!/usr/bin/perl
2     #
3     # $Id: postgresql.monitor,v 1.3 2001/05/03 11:44:21 severin Exp $
4     # $Revision: 1.3 $
5     # $Author: severin $
6     #
7     #Usage: postresql.monitor [options]
8     #
9     # --database=<Databasename> indicates the database to which is connected
10     # --username=<Username> DB-User which is used to connect to the DB
11     # --password=<Password> DB-Password which is used to connect to the DB
12     # --host=<Databasehost> Host of the Database (optional,default=localhost)
13     # --port=<Portnumber> Port on which you want to connect (optional,default=5432)
14     #
15     # a monitor to determine if a PostgreSQL database server is operational
16     #
17     # Rather than use tcp.monitor to ensure that your SQL server is responding
18     # on the proper port, this attempts to connect to and list the databases
19     # on a given database server.
20     #
21     # This monitor requires the perl5 DBI, DBD::mSQL and DBD::mysql modules,
22     # available from CPAN (http://www.cpan.org)
23     #
24     # Copyright (C) 2001, CubIT IT Solutions
25     # Written by Severin Luftensteiner <severin.luftensteiner@cubit.at>
26     #
27     # This program is free software; you can redistribute it and/or modify
28     # it under the terms of the GNU General Public License as published by
29     # the Free Software Foundation; either version 2 of the License, or
30     # (at your option) any later version.
31     #
32     # This program is distributed in the hope that it will be useful,
33     # but WITHOUT ANY WARRANTY; without even the implied warranty of
34     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35     # GNU General Public License for more details.
36     #
37     # You should have received a copy of the GNU General Public License
38     # along with this program; if not, write to the Free Software
39     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40     #
41    
42     use DBI;
43     use Getopt::Long;
44    
45     GetOptions( \%options,"port=s", "username=s", "password=s", "database=s", "host=s" );
46    
47     # uncomment these two lines and provide suitable information if you don't
48     # want to pass sensitive information on the command line
49 dpavlin 1.2 $options{username} ||= "postgres";
50     $options{password} ||= "";
51 dpavlin 1.1
52     $mode="Pg";
53     if ($options{host} eq ""){
54     $options{"host"=>"localhost"};
55     }
56     if ($options{port} eq ""){
57     $options{"port"=>"5432"};
58     }
59    
60 dpavlin 1.2 if (($options{username} eq "") || (! defined $options{password}) || ($options{database} eq "")){
61 dpavlin 1.1 print <<EOP1;
62     Usage: postresql.monitor [options]
63    
64     --database=<Databasename> indicates the database to which is connected
65     --username=<Username> DB-User which is used to connect to the DB
66     --password=<Password> DB-Password which is used to connect to the DB
67     --host=<Databasehost> Host of the Database (optional,default=localhost)
68     --port=<Portnumber> Port on which you want to connect (optional,default=5432)
69     EOP1
70     die();
71     }
72    
73 dpavlin 1.3 my @test_db;
74    
75     foreach (@ARGV) {
76     if (m/^([^:]+):([^\@]+)\@(.+)/) {
77     push
78     %test[host] = $1;
79     %test[user] = $2;
80     %test
81     my ($host,$user,$database) = ($1,$2,$3);
82     } else {
83     push @failures, "Can't parse configuration: host '$_' not in host:user\@database format!";
84     }
85     }
86 dpavlin 1.1
87     my( $dbh ) = DBI->connect( "DBI:$mode:dbname=$options{database};$options{host};$options{port}", $options{username}, $options{password} );
88     if( ! $dbh ) {
89     push( @failures, "Could not connect to $mode server $host: " . $DBI::errstr );
90 dpavlin 1.3 } else {
91     my $sth = $dbh -> prepare("select count(*) from pg_tables");
92 dpavlin 1.1 }
93 dpavlin 1.3
94    
95    
96 dpavlin 1.1 if (@failures) {
97     print join (", ", @failures), "\n";
98     exit 1;
99     };
100     if ($dbh){
101     $dbh->disconnect();
102     }
103    
104     exit 0;

  ViewVC Help
Powered by ViewVC 1.1.26