/[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.1 - (hide annotations)
Wed Jul 10 08:43:16 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
original from ftp://ftp.kernel.org/pub/software/admin/mon/contrib/monitors/postgres/postgresql.monitor

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     #$options{username} ||= "username";
50     #$options{password} ||= "password";
51    
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     if (($options{username} eq "") || ($options{password} eq "") || ($options{database} eq "")){
61     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    
74     my( $dbh ) = DBI->connect( "DBI:$mode:dbname=$options{database};$options{host};$options{port}", $options{username}, $options{password} );
75     if( ! $dbh ) {
76     push( @failures, "Could not connect to $mode server $host: " . $DBI::errstr );
77     }
78     if (@failures) {
79     print join (", ", @failures), "\n";
80     exit 1;
81     };
82     if ($dbh){
83     $dbh->disconnect();
84     }
85    
86     exit 0;

  ViewVC Help
Powered by ViewVC 1.1.26