16
16
17
17
package check_postgres ;
18
18
19
- use 5.006001 ;
19
+ use 5.008 ;
20
20
use strict;
21
21
use warnings;
22
22
use utf8;
@@ -2815,15 +2815,15 @@ sub pretty_time {
2815
2815
2816
2816
# # Just seconds (< 2:00)
2817
2817
if ($sec < 120 or $tweak =~ / s/ ) {
2818
- return sprintf " $sec %s " , $sec ==1 ? msg(' time-second' ) : msg(' time-seconds' );
2818
+ return sprintf " $sec %s " , 1== $sec ? msg(' time-second' ) : msg(' time-seconds' );
2819
2819
}
2820
2820
2821
2821
# # Minutes and seconds (< 60:00)
2822
2822
if ($sec < 60*60 or $tweak =~ / m/ ) {
2823
2823
my $min = int $sec / 60;
2824
2824
$sec %= 60;
2825
- my $ret = sprintf " $min %s " , $min ==1 ? msg(' time-minute' ) : msg(' time-minutes' );
2826
- $sec and $tweak !~ / S/ and $ret .= sprintf " $sec %s " , $sec ==1 ? msg(' time-second' ) : msg(' time-seconds' );
2825
+ my $ret = sprintf " $min %s " , 1== $min ? msg(' time-minute' ) : msg(' time-minutes' );
2826
+ $sec and $tweak !~ / S/ and $ret .= sprintf " $sec %s " , 1== $sec ? msg(' time-second' ) : msg(' time-seconds' );
2827
2827
return $ret ;
2828
2828
}
2829
2829
@@ -2833,9 +2833,9 @@ sub pretty_time {
2833
2833
$sec -= ($hour *60*60);
2834
2834
my $min = int $sec / 60;
2835
2835
$sec -= ($min *60);
2836
- my $ret = sprintf " $hour %s " , $hour ==1 ? msg(' time-hour' ) : msg(' time-hours' );
2837
- $min and $tweak !~ / M/ and $ret .= sprintf " $min %s " , $min ==1 ? msg(' time-minute' ) : msg(' time-minutes' );
2838
- $sec and $tweak !~ / [SM]/ and $ret .= sprintf " $sec %s " , $sec ==1 ? msg(' time-second' ) : msg(' time-seconds' );
2836
+ my $ret = sprintf " $hour %s " , 1== $hour ? msg(' time-hour' ) : msg(' time-hours' );
2837
+ $min and $tweak !~ / M/ and $ret .= sprintf " $min %s " , 1== $min ? msg(' time-minute' ) : msg(' time-minutes' );
2838
+ $sec and $tweak !~ / [SM]/ and $ret .= sprintf " $sec %s " , 1== $sec ? msg(' time-second' ) : msg(' time-seconds' );
2839
2839
return $ret ;
2840
2840
}
2841
2841
@@ -2847,10 +2847,10 @@ sub pretty_time {
2847
2847
$sec -= ($our *60*60);
2848
2848
my $min = int $sec / 60;
2849
2849
$sec -= ($min *60);
2850
- my $ret = sprintf " $day %s " , $day ==1 ? msg(' time-day' ) : msg(' time-days' );
2851
- $our and $tweak !~ / H/ and $ret .= sprintf " $our %s " , $our ==1 ? msg(' time-hour' ) : msg(' time-hours' );
2852
- $min and $tweak !~ / [HM]/ and $ret .= sprintf " $min %s " , $min ==1 ? msg(' time-minute' ) : msg(' time-minutes' );
2853
- $sec and $tweak !~ / [HMS]/ and $ret .= sprintf " $sec %s " , $sec ==1 ? msg(' time-second' ) : msg(' time-seconds' );
2850
+ my $ret = sprintf " $day %s " , 1== $day ? msg(' time-day' ) : msg(' time-days' );
2851
+ $our and $tweak !~ / H/ and $ret .= sprintf " $our %s " , 1== $our ? msg(' time-hour' ) : msg(' time-hours' );
2852
+ $min and $tweak !~ / [HM]/ and $ret .= sprintf " $min %s " , 1== $min ? msg(' time-minute' ) : msg(' time-minutes' );
2853
+ $sec and $tweak !~ / [HMS]/ and $ret .= sprintf " $sec %s " , 1== $sec ? msg(' time-second' ) : msg(' time-seconds' );
2854
2854
return $ret ;
2855
2855
}
2856
2856
@@ -2863,11 +2863,11 @@ sub pretty_time {
2863
2863
$sec -= ($our *60*60);
2864
2864
my $min = int $sec / 60;
2865
2865
$sec -= ($min *60);
2866
- my $ret = sprintf " $week %s " , $week ==1 ? msg(' time-week' ) : msg(' time-weeks' );
2867
- $day and $tweak !~ / D/ and $ret .= sprintf " $day %s " , $day ==1 ? msg(' time-day' ) : msg(' time-days' );
2868
- $our and $tweak !~ / [DH]/ and $ret .= sprintf " $our %s " , $our ==1 ? msg(' time-hour' ) : msg(' time-hours' );
2869
- $min and $tweak !~ / [DHM]/ and $ret .= sprintf " $min %s " , $min ==1 ? msg(' time-minute' ) : msg(' time-minutes' );
2870
- $sec and $tweak !~ / [DHMS]/ and $ret .= sprintf " $sec %s " , $sec ==1 ? msg(' time-second' ) : msg(' time-seconds' );
2866
+ my $ret = sprintf " $week %s " , 1== $week ? msg(' time-week' ) : msg(' time-weeks' );
2867
+ $day and $tweak !~ / D/ and $ret .= sprintf " $day %s " , 1== $day ? msg(' time-day' ) : msg(' time-days' );
2868
+ $our and $tweak !~ / [DH]/ and $ret .= sprintf " $our %s " , 1== $our ? msg(' time-hour' ) : msg(' time-hours' );
2869
+ $min and $tweak !~ / [DHM]/ and $ret .= sprintf " $min %s " , 1== $min ? msg(' time-minute' ) : msg(' time-minutes' );
2870
+ $sec and $tweak !~ / [DHMS]/ and $ret .= sprintf " $sec %s " , 1== $sec ? msg(' time-second' ) : msg(' time-seconds' );
2871
2871
return $ret ;
2872
2872
2873
2873
} # # end of pretty_time
@@ -3117,7 +3117,7 @@ sub run_command {
3117
3117
$db -> {ok } = 1;
3118
3118
3119
3119
# # Unfortunately, psql outputs "(No rows)" even with -t and -x
3120
- $db -> {slurp } = ' ' if ! defined $db -> {slurp } or index ($db -> {slurp },' (' )==0 ;
3120
+ $db -> {slurp } = ' ' if ! defined $db -> {slurp } or 0 == index ($db -> {slurp },' (' );
3121
3121
3122
3122
# # Remove carriage returns (i.e. on Win32)
3123
3123
$db -> {slurp } =~ s /\r // g ;
@@ -3162,7 +3162,7 @@ sub run_command {
3162
3162
my $lastval ;
3163
3163
for my $line (split /\n/ => $db -> {slurp }) {
3164
3164
3165
- if (index ($line ,' -' )==0 ) {
3165
+ if (0 == index ($line ,' -' )) {
3166
3166
$lnum ++;
3167
3167
next ;
3168
3168
}
@@ -3573,7 +3573,7 @@ sub validate_range {
3573
3573
}
3574
3574
if (length $critical ) {
3575
3575
if ($critical !~ $timesecre ) {
3576
- ndie msg(' range-seconds' , ' critical' )
3576
+ ndie msg(' range-seconds' , ' critical' );
3577
3577
}
3578
3578
$critical = $1 ;
3579
3579
if (!$arg -> {any_warning } and length $warning and $warning > $critical ) {
@@ -4174,7 +4174,7 @@ sub check_backends {
4174
4174
$nwarn = $limit -$w2 ;
4175
4175
}
4176
4176
elsif ($w3 ) {
4177
- $nwarn = (int $w2 *$limit /100)
4177
+ $nwarn = (int $w2 *$limit /100);
4178
4178
}
4179
4179
4180
4180
if (! skip_item($r -> {datname })) {
@@ -4404,7 +4404,7 @@ sub check_bloat {
4404
4404
qw/ iname irows ipages iotta ibloat wastedipgaes wastedibytes wastedisize/ };
4405
4405
4406
4406
# # Made it past the exclusions
4407
- $max = -2 if $max == -1 ;
4407
+ $max = -2 if -1 == $max ;
4408
4408
4409
4409
# # Do the table first if we haven't seen it
4410
4410
if (! $seenit {" $dbname .$schema .$table " }++) {
@@ -4475,10 +4475,10 @@ sub check_bloat {
4475
4475
$db -> {perf } = ' ' ;
4476
4476
}
4477
4477
4478
- if ($max == -1 ) {
4478
+ if (-1 == $max ) {
4479
4479
add_unknown msg(' no-match-rel' );
4480
4480
}
4481
- elsif ($max != -1 ) {
4481
+ elsif (-1 != $max ) {
4482
4482
add_ok $maxmsg ;
4483
4483
}
4484
4484
@@ -4560,7 +4560,7 @@ sub check_checkpoint {
4560
4560
ndie msg(' checkpoint-noparse' , $last );
4561
4561
}
4562
4562
my $diff = time - $dt ;
4563
- my $msg = $diff ==1 ? msg(' checkpoint-ok' ) : msg(' checkpoint-ok2' , $diff );
4563
+ my $msg = 1== $diff ? msg(' checkpoint-ok' ) : msg(' checkpoint-ok2' , $diff );
4564
4564
$db -> {perf } = sprintf ' %s=%s;%s;%s' ,
4565
4565
perfname(msg(' age' )), $diff , $warning , $critical ;
4566
4566
@@ -5622,7 +5622,7 @@ sub check_hot_standby_delay {
5622
5622
# # Do the check on replay delay in case SR has disconnected because it way too far behind
5623
5623
my $msg = qq{ $rep_delta } ;
5624
5624
if ($version >= 9.1) {
5625
- $msg .= qq{ and $time_delta seconds}
5625
+ $msg .= qq{ and $time_delta seconds} ;
5626
5626
}
5627
5627
if ((length $critical or length $ctime ) and (!length $critical or length $critical and $rep_delta > $critical ) and (!length $ctime or length $ctime and $time_delta > $ctime )) {
5628
5628
add_critical $msg ;
@@ -5652,7 +5652,7 @@ sub check_replication_slots {
5652
5652
5653
5653
my ($warning , $critical ) = validate_range({type => ' size' });
5654
5654
5655
- $SQL = qq {
5655
+ $SQL = q {
5656
5656
WITH slots AS (SELECT slot_name,
5657
5657
slot_type,
5658
5658
coalesce(restart_lsn, '0/0'::pg_lsn) AS slot_lsn,
@@ -5679,7 +5679,7 @@ sub check_replication_slots {
5679
5679
5680
5680
for my $r (@{$db -> {slurp }}) {
5681
5681
if (skip_item($r -> {slot_name })) {
5682
- $max = -2 if ( $max == -1 ) ;
5682
+ $max = -2 if -1 == $max ;
5683
5683
next ;
5684
5684
}
5685
5685
if ($r -> {delta } >= $max ) {
@@ -5692,14 +5692,14 @@ sub check_replication_slots {
5692
5692
}
5693
5693
if ($max < 0) {
5694
5694
$stats {$db -> {dbname }} = 0;
5695
- add_ok msg(' no-match-slotok' ) if ( $max == -1) ;
5696
- add_unknown msg(' no-match-slot' ) if ( $max == -2) ;
5695
+ add_ok msg(' no-match-slotok' ) if -1 == $max ;
5696
+ add_unknown msg(' no-match-slot' ) if -2 == $max ;
5697
5697
next ;
5698
5698
}
5699
5699
5700
5700
my $msg = ' ' ;
5701
5701
for (sort {$s {$b }[0] <=> $s {$a }[0] or $a cmp $b } keys %s ) {
5702
- $msg .= " $_ : $s {$_ }[1] ($s {$_ }[2] $s {$_ }[3] " . ($s {$_ }[4] eq ' t' ? ' active' : ' inactive' ) ." ) " ;
5702
+ $msg .= " $_ : $s {$_ }[1] ($s {$_ }[2] $s {$_ }[3] " . ($s {$_ }[4] eq ' t' ? ' active' : ' inactive' ) .' ) ' ;
5703
5703
$db -> {perf } .= sprintf ' %s=%s;%s;%s' ,
5704
5704
perfname($_ ), $s {$_ }[0], $warning , $critical ;
5705
5705
}
@@ -5836,7 +5836,7 @@ sub check_last_vacuum_analyze {
5836
5836
do_mrtg({one => $mintime , msg => $maxrel });
5837
5837
return ;
5838
5838
}
5839
- if ($maxtime == -2 ) {
5839
+ if (-2 == $maxtime ) {
5840
5840
add_unknown (
5841
5841
$found ? $type eq ' vacuum' ? msg(' vac-nomatch-v' )
5842
5842
: msg(' vac-nomatch-a' )
@@ -6178,7 +6178,7 @@ sub check_logfile {
6178
6178
}
6179
6179
close $logfh or ndie msg(' file-noclose' , $logfile , $! );
6180
6180
6181
- if ($found == 1 ) {
6181
+ if (1 == $found ) {
6182
6182
$MRTG and do_mrtg({one => 1});
6183
6183
add_ok msg(' logfile-ok' , $logfile );
6184
6184
}
@@ -6607,7 +6607,7 @@ sub check_pgbouncer_backends {
6607
6607
$nwarn = $limit -$w2 ;
6608
6608
}
6609
6609
elsif ($w3 ) {
6610
- $nwarn = (int $w2 *$limit /100)
6610
+ $nwarn = (int $w2 *$limit /100);
6611
6611
}
6612
6612
6613
6613
if (! skip_item($r -> {database })) {
@@ -6890,15 +6890,17 @@ sub check_relation_size {
6890
6890
6891
6891
my ($warning , $critical ) = validate_range({type => ' size' });
6892
6892
6893
+ # # no critic
6893
6894
$SQL = sprintf q{
6894
6895
SELECT pg_%1$s_size(c.oid) AS rsize,
6895
6896
pg_size_pretty(pg_%1$s_size(c.oid)) AS psize,
6896
6897
relkind, relname, nspname
6897
6898
FROM pg_class c JOIN pg_namespace n ON (c.relnamespace = n.oid)
6898
6899
WHERE relkind IN (%2$s)
6899
6900
} ,
6900
- $sizefct ,
6901
- join (' ,' , map { " '$_ '" } split (// , $relkinds ));
6901
+ $sizefct , # # no critic
6902
+ join (' ,' , map { " '$_ '" } split (// , $relkinds )); # # no critic
6903
+ # # use critic
6902
6904
6903
6905
if ($opt {perflimit }) {
6904
6906
$SQL .= " ORDER BY 1 DESC LIMIT $opt {perflimit}" ;
@@ -6934,7 +6936,7 @@ sub check_relation_size {
6934
6936
my $nicename = $kind eq ' r' ? " $schema .$name " : $name ;
6935
6937
6936
6938
$db -> {perf } .= sprintf ' %s%s=%sB;%s;%s' ,
6937
- $VERBOSE ==1 ? " \n " : ' ' ,
6939
+ 1 == $VERBOSE ? " \n " : ' ' ,
6938
6940
perfname($nicename ), $size , $warning , $critical ;
6939
6941
($max =$size , $pmax =$psize , $kmax =$kind , $nmax =$name , $smax =$schema ) if $size > $max ;
6940
6942
}
@@ -8268,7 +8270,7 @@ sub check_sequence {
8268
8270
FROM pg_sequences) foo} ;
8269
8271
# # use critic
8270
8272
8271
- my $info = run_command($SQL , {regex => qr {\w } , emptyok => 1, version => [" >9.6 SELECT 1" ]} ); # actual SQL10 is executed below
8273
+ my $info = run_command($SQL , {regex => qr {\w } , emptyok => 1, version => [' >9.6 SELECT 1' ]} ); # actual SQL10 is executed below
8272
8274
8273
8275
my $MAXINT2 = 32767;
8274
8276
my $MAXINT4 = 2147483647;
@@ -8955,7 +8957,7 @@ sub check_wal_files {
8955
8957
my ($warning , $critical ) = validate_range($arg );
8956
8958
8957
8959
my $lsfunc = $opt {lsfunc } || ' pg_ls_dir' ;
8958
- my $lsargs = $opt {lsfunc } ? " " : " 'pg_xlog$subdir '" ;
8960
+ my $lsargs = $opt {lsfunc } ? q{ } : " 'pg_xlog$subdir '" ;
8959
8961
8960
8962
# # Figure out where the pg_xlog directory is
8961
8963
$SQL = qq{ SELECT count(*) AS count FROM $lsfunc ($lsargs ) WHERE $lsfunc ~ E'^[0-9A-F]{24}$extrabit \$ '} ; # # no critic (RequireInterpolationOfMetachars)
@@ -9135,17 +9137,17 @@ =head1 DATABASE CONNECTION OPTIONS
9135
9137
=item B<--dbservice=NAME >
9136
9138
9137
9139
The name of a service inside of the pg_service.conf file. Before version 9.0 of Postgres, this is
9138
- a global file, usually found in /etc/pg_service.conf. If you are using version 9.0 or higher of
9140
+ a global file, usually found in F< /etc/pg_service.conf> . If you are using version 9.0 or higher of
9139
9141
Postgres, you can use the file ".pg_service.conf" in the home directory of the user running
9140
9142
the script, e.g. nagios.
9141
9143
9142
9144
This file contains a simple list of connection options. You can also pass additional information
9143
9145
when using this option such as --dbservice="maindatabase sslmode=require"
9144
9146
9145
9147
The documentation for this file can be found at
9146
- https://www.postgresql.org/docs/current/static/libpq-pgservice.html
9148
+ L<https://www.postgresql.org/docs/current/static/libpq-pgservice.html>
9149
+
9147
9150
9148
- =back
9149
9151
9150
9152
The database connection options can be grouped: I<--host=a,b --host=c --port=1234 --port=3344 >
9151
9153
would connect to a-1234, b-1234, and c-3344. Note that once set, an option
@@ -9821,7 +9823,7 @@ =head2 B<disk_space>
9821
9823
9822
9824
check_postgres_disk_space --port=5432 --warning='90%' --critical='90%'
9823
9825
9824
- Example 2: Check that all file systems starting with /dev/sda are smaller than 10 GB and 11 GB (warning and critical)
9826
+ Example 2: Check that all file systems starting with F< /dev/sda> are smaller than 10 GB and 11 GB (warning and critical)
9825
9827
9826
9828
check_postgres_disk_space --port=5432 --warning='10 GB' --critical='11 GB' --include="~^/dev/sda"
9827
9829
@@ -10115,7 +10117,7 @@ =head2 B<new_version_bc>
10115
10117
program is available. The current version is obtained by running C<bucardo_ctl --version > .
10116
10118
If a major upgrade is available, a warning is returned. If a revision upgrade is
10117
10119
available, a critical is returned. (Bucardo is a master to slave, and master to master
10118
- replication system for Postgres: see https://bucardo.org/ for more information).
10120
+ replication system for Postgres: see L< https://bucardo.org/> for more information).
10119
10121
See also the information on the C<--get_method > option.
10120
10122
10121
10123
=head2 B<new_version_box >
@@ -10125,7 +10127,7 @@ =head2 B<new_version_box>
10125
10127
If a major upgrade is available, a warning is returned. If a revision upgrade is
10126
10128
available, a critical is returned. (boxinfo is a program for grabbing important
10127
10129
information from a server and putting it into a HTML format: see
10128
- https://bucardo.org/Boxinfo/ for more information). See also the information on
10130
+ L< https://bucardo.org/Boxinfo/> for more information). See also the information on
10129
10131
the C<--get_method > option.
10130
10132
10131
10133
=head2 B<new_version_cp >
@@ -10154,7 +10156,7 @@ =head2 B<new_version_tnm>
10154
10156
C<tail_n_mail --version > . If a major upgrade is available, a warning is returned. If a
10155
10157
revision upgrade is available, a critical is returned. (tail_n_mail is a log monitoring
10156
10158
tool that can send mail when interesting events appear in your Postgres logs.
10157
- See: https://bucardo.org/tail_n_mail/ for more information).
10159
+ See: L< https://bucardo.org/tail_n_mail/> for more information).
10158
10160
See also the information on the C<--get_method > option.
10159
10161
10160
10162
=head2 B<pgb_pool_cl_active >
@@ -10861,7 +10863,7 @@ =head1 FILES
10861
10863
10862
10864
In addition to command-line configurations, you can put any options inside of a file. The file
10863
10865
F<.check_postgresrc> in the current directory will be used if found. If not found, then the file
10864
- F<~/.check_postgresrc> will be used. Finally, the file /etc/check_postgresrc will be used if available.
10866
+ F<~/.check_postgresrc> will be used. Finally, the file F< /etc/check_postgresrc> will be used if available.
10865
10867
The format of the file is option = value, one per line. Any line starting with a '#' will be skipped.
10866
10868
Any values loaded from a check_postgresrc file will be overwritten by command-line options. All
10867
10869
check_postgresrc files can be ignored by supplying a C<--no-checkpostgresrc > argument.
@@ -10918,17 +10920,17 @@ =head1 MAILING LIST
10918
10920
Three mailing lists are available. For discussions about the program, bug reports,
10919
10921
feature requests, and commit notices, send email to check_postgres@bucardo.org
10920
10922
10921
- https://mail.endcrypt.com/mailman/listinfo/check_postgres
10923
+ L< https://mail.endcrypt.com/mailman/listinfo/check_postgres>
10922
10924
10923
10925
A low-volume list for announcement of new versions and important notices is the
10924
10926
'check_postgres-announce' list:
10925
10927
10926
- https://mail.endcrypt.com/mailman/listinfo/check_postgres-announce
10928
+ L< https://mail.endcrypt.com/mailman/listinfo/check_postgres-announce>
10927
10929
10928
10930
Source code changes (via git-commit) are sent to the
10929
10931
'check_postgres-commit' list:
10930
10932
10931
- https://mail.endcrypt.com/mailman/listinfo/check_postgres-commit
10933
+ L< https://mail.endcrypt.com/mailman/listinfo/check_postgres-commit>
10932
10934
10933
10935
=head1 HISTORY
10934
10936
0 commit comments