Ensure command-line overrides check_postgresrc entries
authorGreg Sabino Mullane <[email protected]>
Wed, 12 Aug 2009 11:42:53 +0000 (07:42 -0400)
committerGreg Sabino Mullane <[email protected]>
Wed, 12 Aug 2009 11:42:53 +0000 (07:42 -0400)
check_postgres.pl

index 57c6b9cc3eeafa9c33edc14db7bf03bf24fa4f09..bc54bd5480ca87107b2ee467655e6de5c002e0fe 100755 (executable)
@@ -598,6 +598,8 @@ if (! $opt{'no-check_postgresrc'}) {
                $rcfile = '/etc/check_postgresrc';
        }
 }
+## We need a temporary hash so that multi-value options can be overriden on the command line
+my %tempopt;
 if (defined $rcfile) {
        open my $rc, '<', $rcfile or die qq{Could not open "$rcfile": $!\n};
        RCLINE:
@@ -633,10 +635,10 @@ if (defined $rcfile) {
 
                ## These options are multiples ('@s')
                for my $arr (qw/include exclude includeuser excludeuser host port dbuser dbname dbpass dbservice/) {
-                       if ($name eq $arr or $name eq "${arr}2") {
-                               push @{$opt{$name}} => $value;
-                               next RCLINE;
-                       }
+                       next if $name ne $arr and $name ne "${arr}2";
+                       push @{$tempopt{$name}} => $value;
+                       ## Don't set below as a normal value
+                       next RCLINE;
                }
                $opt{$name} = $value;
        }
@@ -699,6 +701,11 @@ die $USAGE unless
        and keys %opt
        and ! @ARGV;
 
+## Put multi-val options from check_postgresrc in place, only if no command-line args!
+for my $mv (keys %tempopt) {
+       $opt{$mv} ||= delete $tempopt{$mv};
+}
+
 our $VERBOSE = $opt{verbose} || 0;
 
 our $OUTPUT = lc $opt{output} || '';
@@ -7701,6 +7708,7 @@ Items not specifically attributed are by Greg Sabino Mullane.
 =item B<Version 2.11.0>
 
   Add the --no-check_postgresrc flag.
+  Ensure check_postgresrc options are completely overriden by command-line options.
 
 =item B<Version 2.10.1>