46 |
|
|
47 |
# uncomment these two lines and provide suitable information if you don't |
# uncomment these two lines and provide suitable information if you don't |
48 |
# want to pass sensitive information on the command line |
# want to pass sensitive information on the command line |
49 |
#$options{username} ||= "username"; |
$options{username} ||= "postgres"; |
50 |
#$options{password} ||= "password"; |
$options{password} ||= ""; |
51 |
|
|
52 |
$mode="Pg"; |
$mode="Pg"; |
53 |
if ($options{host} eq ""){ |
if ($options{host} eq ""){ |
57 |
$options{"port"=>"5432"}; |
$options{"port"=>"5432"}; |
58 |
} |
} |
59 |
|
|
60 |
if (($options{username} eq "") || ($options{password} eq "") || ($options{database} eq "")){ |
if (($options{username} eq "") || (! defined $options{password}) || ($options{database} eq "")){ |
61 |
print <<EOP1; |
print <<EOP1; |
62 |
Usage: postresql.monitor [options] |
Usage: postresql.monitor [options] |
63 |
|
|
70 |
die(); |
die(); |
71 |
} |
} |
72 |
|
|
73 |
|
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 |
|
|
87 |
my( $dbh ) = DBI->connect( "DBI:$mode:dbname=$options{database};$options{host};$options{port}", $options{username}, $options{password} ); |
my( $dbh ) = DBI->connect( "DBI:$mode:dbname=$options{database};$options{host};$options{port}", $options{username}, $options{password} ); |
88 |
if( ! $dbh ) { |
if( ! $dbh ) { |
89 |
push( @failures, "Could not connect to $mode server $host: " . $DBI::errstr ); |
push( @failures, "Could not connect to $mode server $host: " . $DBI::errstr ); |
90 |
|
} else { |
91 |
|
my $sth = $dbh -> prepare("select count(*) from pg_tables"); |
92 |
} |
} |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
if (@failures) { |
if (@failures) { |
97 |
print join (", ", @failures), "\n"; |
print join (", ", @failures), "\n"; |
98 |
exit 1; |
exit 1; |