summaryrefslogtreecommitdiff
path: root/check_postgres.pl
diff options
context:
space:
mode:
authorCédric Villemain2011-11-07 12:57:19 +0000
committerCédric Villemain2011-11-10 02:53:08 +0000
commit1118e0ab0028fee46a5bdaac9de169068e4fd03f (patch)
tree934231d85af60097fb28117ab4f7921ee1d0d7c8 /check_postgres.pl
parent2b6702af60fa033cddc844be63e646aff8db4078 (diff)
Reduce code duplicates around pg_controldata
Use the open_controldata where pg_controldata was used previously. Also split the code for make_sure_standby_mode to reduce code for the future option make_sure_prod.
Diffstat (limited to 'check_postgres.pl')
-rwxr-xr-xcheck_postgres.pl91
1 files changed, 18 insertions, 73 deletions
diff --git a/check_postgres.pl b/check_postgres.pl
index 101550dc0..3b5537e30 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -1521,59 +1521,37 @@ sub do_mrtg_stats {
do_mrtg({one => $one, two => $two, msg => $msg});
}
-sub make_sure_standby_mode {
+sub make_sure_mode_is {
- ## Checks if database in standby mode
## Requires $ENV{PGDATA} or --datadir
- ## Find the data directory, make sure it exists
- my $dir = $opt{datadir} || $ENV{PGDATA};
-
- if (!defined $dir or ! length $dir) {
- ndie msg('checkpoint-nodir');
- }
-
- if (! -d $dir) {
- ndie msg('checkpoint-baddir', $dir);
- }
-
$db->{host} = '<none>';
## Run pg_controldata, grab the mode
- my $pgc
- = $ENV{PGCONTROLDATA} ? $ENV{PGCONTROLDATA}
- : $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_controldata"
- : 'pg_controldata';
- $COM = qq{$pgc "$dir"};
- eval {
- $res = qx{$COM 2>&1};
- };
- if ($@) {
- ndie msg('checkpoint-nosys', $@);
- }
-
- ## If the path is echoed back, we most likely have an invalid data dir
- if ($res =~ /$dir/) {
- ndie msg('checkpoint-baddir2', $dir);
- }
-
- if ($res =~ /WARNING: Calculated CRC checksum/) {
- ndie msg('checkpoint-badver', $dir);
- }
- if ($res !~ /^pg_control.+\d+/) {
- ndie msg('checkpoint-badver2');
- }
+ $res = open_controldata();
my $regex = msg('checkmode-state');
if ($res !~ /$regex\s*(.+)/) { ## no critic (ProhibitUnusedCapture)
## Just in case, check the English one as well
$regex = msg_en('checkmode-state');
if ($res !~ /$regex\s*(.+)/) {
- ndie msg('checkpoint-noregex', $dir);
+ ndie msg('checkpoint-noregex');
}
}
my $last = $1;
- $regex = msg('checkmode-recovery');
+
+ return $last;
+
+}
+
+sub make_sure_standby_mode {
+
+ ## Checks if database in standby mode
+ ## Requires $ENV{PGDATA} or --datadir
+
+ my $last = make_sure_mode_is();
+
+ my $regex = msg('checkmode-recovery');
if ($last =~ /$regex/) {
$STANDBY = 1;
}
@@ -3708,50 +3686,17 @@ sub check_checkpoint {
forcemrtg => 1,
});
- ## Find the data directory, make sure it exists
- my $dir = $opt{datadir} || $ENV{PGDATA};
-
- if (!defined $dir or ! length $dir) {
- ndie msg('checkpoint-nodir');
- }
-
- if (! -d $dir) {
- ndie msg('checkpoint-baddir', $dir);
- }
-
$db->{host} = '<none>';
## Run pg_controldata, grab the time
- my $pgc
- = $ENV{PGCONTROLDATA} ? $ENV{PGCONTROLDATA}
- : $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_controldata"
- : 'pg_controldata';
- $COM = qq{$pgc "$dir"};
- eval {
- $res = qx{$COM 2>&1};
- };
- if ($@) {
- ndie msg('checkpoint-nosys', $@);
- }
-
- ## If the path is echoed back, we most likely have an invalid data dir
- if ($res =~ /$dir/) {
- ndie msg('checkpoint-baddir2', $dir);
- }
-
- if ($res =~ /WARNING: Calculated CRC checksum/) {
- ndie msg('checkpoint-badver', $pgc);
- }
- if ($res !~ /^pg_control.+\d+/) {
- ndie msg('checkpoint-badver2');
- }
+ $res = open_controldata();
my $regex = msg('checkpoint-po');
if ($res !~ /$regex\s*(.+)/) { ## no critic (ProhibitUnusedCapture)
## Just in case, check the English one as well
$regex = msg_en('checkpoint-po');
if ($res !~ /$regex\s*(.+)/) {
- ndie msg('checkpoint-noregex', $dir);
+ ndie msg('checkpoint-noregex');
}
}
my $last = $1;