This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
check_postgres.pl
executable file
·8267 lines (6746 loc) · 271 KB
/
check_postgres.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -- -*-cperl-*-
## Perform many different checks against Postgres databases.
## Designed primarily as a Nagios script.
## Run with --help for a summary.
##
## Greg Sabino Mullane <greg@endpoint.com>
## End Point Corporation http://www.endpoint.com/
## BSD licensed, see complete license at bottom of this script
## The latest version can be found at:
## http://www.bucardo.org/check_postgres/
##
## See the HISTORY section for other contributors
package check_postgres;
use 5.006001;
use strict;
use warnings;
use utf8;
use Getopt::Long qw/GetOptions/;
Getopt::Long::Configure(qw/no_ignore_case/);
use File::Basename qw/basename/;
use File::Temp qw/tempfile tempdir/;
File::Temp->safe_level( File::Temp::MEDIUM );
use Cwd;
use Data::Dumper qw/Dumper/;
$Data::Dumper::Varname = 'POSTGRES';
$Data::Dumper::Indent = 2;
$Data::Dumper::Useqq = 1;
our $VERSION = '2.11.1';
use vars qw/ %opt $PSQL $res $COM $SQL $db /;
## Which user to connect as if --dbuser is not given
$opt{defaultuser} = 'postgres';
## Which port to connect to if --dbport is not given
$opt{defaultport} = 5432;
## What type of output to use by default
our $DEFAULT_OUTPUT = 'nagios';
## If psql is not in your path, it is recommended that hardcode it here,
## as an alternative to the --PSQL option
$PSQL = '';
## If this is true, $opt{PSQL} is disabled for security reasons
our $NO_PSQL_OPTION = 1;
## If true, we show how long each query took by default. Requires Time::HiRes to be installed.
$opt{showtime} = 1;
## If true, we show "after the pipe" statistics
$opt{showperf} = 1;
## Default time display format, used for last_vacuum and last_analyze
our $SHOWTIME = 'HH24:MI FMMonth DD, YYYY';
## Always prepend 'postgres_' to the name of the service in the output string
our $FANCYNAME = 1;
## Change the service name to uppercase
our $YELLNAME = 1;
## Preferred order of ways to fetch pages for new_version checks
our $get_method_timeout = 30;
our @get_methods = (
"GET -t $get_method_timeout",
"wget --quiet --timeout=$get_method_timeout -O -",
"fetch -q -T $get_method_timeout -o -",
"curl --silent --max-time=$get_method_timeout",
"lynx --connect-timeout=$get_method_timeout --dump",
'links -dump',
);
## Nothing below this line should need to be changed for normal usage.
## If you do find yourself needing to change something,
## please email the author as it probably indicates something
## that could be made into a command-line option or moved above.
## Messages. Translations always welcome
## Items without a leading tab still need translating
## no critic (RequireInterpolationOfMetachars)
our %msg = (
'en' => {
'backends-fatal' => q{Could not connect: too many connections},
'backends-mrtg' => q{DB=$1 Max connections=$2},
'backends-msg' => q{$1 of $2 connections ($3%)},
'backends-nomax' => q{Could not determine max_connections},
'backends-oknone' => q{No connections},
'backends-po' => q{sorry, too many clients already},
'backends-users' => q{$1 for number of users must be a number or percentage},
'bloat-index' => q{(db $1) index $2 rows:$3 pages:$4 shouldbe:$5 ($6X) wasted bytes:$7 ($8)},
'bloat-nomin' => q{no relations meet the minimum bloat criteria},
'bloat-table' => q{(db $1) table $2.$3 rows:$4 pages:$5 shouldbe:$6 ($7X) wasted size:$8 ($9)},
'checkpoint-baddir' => q{Invalid data_directory: "$1"},
'checkpoint-baddir2' => q{pg_controldata could not read the given data directory: "$1"},
'checkpoint-badver' => q{Failed to run pg_controldata - probably the wrong version},
'checkpoint-badver2' => q{Failed to run pg_controldata - is it the correct version?},
'checkpoint-nodir' => q{Must supply a --datadir argument or set the PGDATA environment variable},
'checkpoint-nodp' => q{Must install the Perl module Date::Parse to use the checkpoint action},
'checkpoint-noparse' => q{Unable to parse pg_controldata output: "$1"},
'checkpoint-noregex' => q{Call to pg_controldata $1 failed},
'checkpoint-nosys' => q{Could not call pg_controldata: $1},
'checkpoint-ok' => q{Last checkpoint was 1 second ago},
'checkpoint-ok2' => q{Last checkpoint was $1 seconds ago},
'checkpoint-po' => q{Time of latest checkpoint:},
'checksum-badline' => q{Invalid pg_setting line: $1},
'checksum-msg' => q{checksum: $1},
'checksum-nomd' => q{Must install the Perl module Digest::MD5 to use the checksum action},
'checksum-nomrtg' => q{Must provide a checksum via the --mrtg option},
'custom-invalid' => q{Invalid format returned by custom query},
'custom-norows' => q{No rows returned},
'custom-nostring' => q{Must provide a query string},
'dbsize-version' => q{Target database must be version 8.1 or higher to run the database_size action},
'die-action-version' => q{Cannot run "$1": server version must be >= $2, but is $3},
'die-badtime' => q{Value for '$1' must be a valid time. Examples: -$2 1s -$2 "10 minutes"},
'die-badversion' => q{Invalid version string: $1},
'die-noset' => q{Cannot run "$1" $2 is not set to on},
'die-nosetting' => q{Could not fetch setting '$1'},
'diskspace-fail' => q{Invalid result from command "$1": $2},
'diskspace-msg' => q{FS $1 mounted on $2 is using $3 of $4 ($5%)},
'diskspace-nodata' => q{Could not determine data_directory: are you connecting as a superuser?},
'diskspace-nodf' => q{Could not find required executable /bin/df},
'diskspace-nodir' => q{Could not find data directory "$1"},
'file-noclose' => q{Could not close $1: $2},
'fsm-page-highver' => q{Cannot check on fsm_pages on servers version 8.4 or greater},
'fsm-page-msg' => q{fsm page slots used: $1 of $2 ($3%)},
'fsm-rel-highver' => q{Cannot check on fsm_relations on servers version 8.4 or greater},
'fsm-rel-msg' => q{fsm relations used: $1 of $2 ($3%)},
'invalid-option' => q{Invalid option},
'invalid-query' => q{Invalid query returned: $1},
'listener-count' => q{ listening=$1}, ## needs leading space
'listener-msg' => q{listeners found: $1},
'locks-msg' => q{total "$1" locks: $2},
'locks-msg2' => q{total locks: $1},
'logfile-bad' => q{Invalid logfile "$1"},
'logfile-debug' => q{Dest is $1, dir is $2, file is $3, facility is $4},
'logfile-debug2' => q{Final logfile: $1},
'logfile-dne' => q{logfile $1 does not exist!},
'logfile-fail' => q{fails logging to: $1},
'logfile-ok' => q{logs to: $1},
'logfile-openfail' => q{logfile "$1" failed to open: $2},
'logfile-opt-bad' => q{Invalid logfile option},
'logfile-seekfail' => q{Seek on $1 failed: $2},
'logfile-stderr' => q{Logfile output has been redirected to stderr: please provide a filename},
'logfile-syslog' => q{Database is using syslog, please specify path with --logfile option (fac=$1)},
'maxtime' => q{ maxtime=$1}, ## needs leading space
'mrtg-fail' => q{Action $1 failed: $2},
'new-cp-fail' => q{Unable to determine the current version of check_postgres.pl},
'new-cp-ok' => q{Version $1 is the latest for check_postgres.pl},
'new-cp-warn' => q{Version $1 of check_postgres.pl exists (this is version $2)},
'new-pg-badver' => q{Could not determine the Postgres revision (version was $1)},
'new-pg-badver2' => q{Could not find revision information for Postgres version $1},
'new-pg-big' => q{Please upgrade to version $1 of Postgres. You are running $2},
'new-pg-match' => q{Postgres is at the latest revision ($1)},
'new-pg-small' => q{The latest version of Postgres is $1, but you are running $2?},
'no-match-db' => q{No matching databases found due to exclusion/inclusion options},
'no-match-fs' => q{No matching file systems found due to exclusion/inclusion options},
'no-match-rel' => q{No matching relations found due to exclusion/inclusion options},
'no-match-set' => q{No matching settings found due to exclusion/inclusion options},
'no-match-table' => q{No matching tables found due to exclusion/inclusion options},
'no-match-user' => q{No matching entries found due to user exclusion/inclusion options},
'no-time-hires' => q{Cannot find Time::HiRes, needed if 'showtime' is true},
'opt-output-invalid' => q{Invalid output: must be 'nagios' or 'mrtg' or 'simple' or 'cacti'},
'opt-psql-badpath' => q{Invalid psql argument: must be full path to a file named psql},
'opt-psql-noexec' => q{The file "$1" does not appear to be executable},
'opt-psql-noexist' => q{Cannot find given psql executable: $1},
'opt-psql-nofind' => q{Could not find a suitable psql executable},
'opt-psql-nover' => q{Could not determine psql version},
'opt-psql-restrict' => q{Cannot use the --PSQL option when NO_PSQL_OPTION is on},
'preptxn-none' => q{No prepared transactions found},
'qtime-fail' => q{Cannot run the txn_idle action unless stats_command_string is set to 'on'!},
'qtime-msg' => q{longest query: $1s},
'range-badcs' => q{Invalid '$1' option: must be a checksum},
'range-badlock' => q{Invalid '$1' option: must be number of locks, or "type1=#;type2=#"},
'range-badpercent' => q{Invalid '$1' option: must be a percentage},
'range-badpercsize' => q{Invalid '$1' option: must be a size or a percentage},
'range-badsize' => q{Invalid size for '$1' option},
'range-badtype' => q{validate_range called with unknown type '$1'},
'range-badversion' => q{Invalid string for '$1' option: $2},
'range-cactionly' => q{This action is for cacti use only and takes no warning or critical arguments},
'range-int' => q{Invalid argument for '$1' option: must be an integer},
'range-int-pos' => q{Invalid argument for '$1' option: must be a positive integer},
'range-neg-percent' => q{Cannot specify a negative percent!},
'range-none' => q{No warning or critical options are needed},
'range-noopt-both' => q{Must provide both 'warning' and 'critical' options},
'range-noopt-one' => q{Must provide a 'warning' or 'critical' option},
'range-noopt-only' => q{Can only provide 'warning' OR 'critical' option},
'range-noopt-orboth' => q{Must provide a 'warning' option, a 'critical' option, or both},
'range-noopt-size' => q{Must provide a warning and/or critical size},
'range-nosize' => q{Must provide a warning and/or critical size},
'range-notime' => q{Must provide a warning and/or critical time},
'range-seconds' => q{Invalid argument to '$1' option: must be number of seconds},
'range-version' => q{must be in the format X.Y or X.Y.Z, where X is the major version number, },
'range-warnbig' => q{The 'warning' option cannot be greater than the 'critical' option},
'range-warnbigsize' => q{The 'warning' option ($1 bytes) cannot be larger than the 'critical' option ($2 bytes)},
'range-warnbigtime' => q{The 'warning' option ($1 s) cannot be larger than the 'critical' option ($2 s)},
'range-warnsmall' => q{The 'warning' option cannot be less than the 'critical' option},
'relsize-msg-ind' => q{largest index is "$1": $2},
'relsize-msg-reli' => q{largest relation is index "$1": $2},
'relsize-msg-relt' => q{largest relation is table "$1": $2},
'relsize-msg-tab' => q{largest table is "$1": $2},
'rep-badarg' => q{Invalid repinfo argument: expected 6 comma-separated values},
'rep-duh' => q{Makes no sense to test replication with same values},
'rep-fail' => q{Row not replicated to slave $1},
'rep-noarg' => q{Need a repinfo argument},
'rep-norow' => q{Replication source row not found: $1},
'rep-noslaves' => q{No slaves found},
'rep-notsame' => q{Cannot test replication: values are not the same},
'rep-ok' => q{Row was replicated},
'rep-sourcefail' => q{Source update failed},
'rep-timeout' => q{Row was not replicated. Timeout: $1},
'rep-unknown' => q{Replication check failed},
'rep-wrongvals' => q{Cannot test replication: values are not the right ones ($1 not $2 nor $3)},
'runcommand-err' => q{Unknown error inside of the "run_command" function},
'runcommand-nodb' => q{No target databases could be found},
'runcommand-nodupe' => q{Could not dupe STDERR},
'runcommand-noerr' => q{Could not open STDERR?!},
'runcommand-nosys' => q{System call failed with a $1},
'runcommand-pgpass' => q{Created temporary pgpass file $1},
'runcommand-timeout' => q{Command timed out! Consider boosting --timeout higher than $1},
'runtime-badmrtg' => q{invalid queryname?},
'runtime-badname' => q{Invalid queryname option: must be a simple view name},
'runtime-msg' => q{query runtime: $1 seconds},
'same-failed' => q{Databases were different. Items not matched: $1},
'same-matched' => q{Both databases have identical items},
'seq-die' => q{Could not determine information about sequence $1},
'seq-msg' => q{$1=$2% (calls left=$3)},
'seq-none' => q{No sequences found},
'symlink-create' => q{Created "$1"},
'symlink-done' => q{Not creating "$1": $2 already linked to "$3"},
'symlink-exists' => q{Not creating "$1": $2 file already exists},
'symlink-fail1' => q{Failed to unlink "$1": $2},
'symlink-fail2' => q{Could not symlink $1 to $2: $3},
'symlink-name' => q{This command will not work unless the program has the word "postgres" in it},
'symlink-unlink' => q{Unlinking "$1":$2 },
'testmode-end' => q{END OF TEST MODE},
'testmode-fail' => q{Connection failed: $1 $2},
'testmode-norun' => q{Cannot run "$1" on $2: version must be >= $3, but is $4},
'testmode-noset' => q{Cannot run "$1" on $2: $3 is not set to on},
'testmode-nover' => q{Could not find version for $1},
'testmode-ok' => q{Connection ok: $1},
'testmode-start' => q{BEGIN TEST MODE},
'time-day' => q{day},
'time-days' => q{days},
'time-hour' => q{hour},
'time-hours' => q{hours},
'time-minute' => q{minute},
'time-minutes' => q{minutes},
'time-month' => q{month},
'time-months' => q{months},
'time-second' => q{second},
'time-seconds' => q{seconds},
'time-week' => q{week},
'time-weeks' => q{weeks},
'time-year' => q{year},
'time-years' => q{years},
'timesync-diff' => q{ diff=$1}, ## needs leading space
'timesync-msg' => q{timediff=$1 DB=$2 Local=$3},
'trigger-msg' => q{Disabled triggers: $1},
'txnidle-msg' => q{longest idle in txn: $1s},
'txnidle-none' => q{no idle in transaction},
'txntime-fail' => q{Query failed},
'txntime-msg' => q{longest txn: $1s},
'txntime-none' => q{No transactions},
'txnwrap-cbig' => q{The 'critical' value must be less than 2 billion},
'txnwrap-wbig' => q{The 'warning' value must be less than 2 billion},
'unknown-error' => q{Unknown error},
'usage' => qq{\nUsage: \$1 <options>\n Try "\$1 --help" for a complete list of options\n\n},
'vac-msg' => q{DB: $1 TABLE: $2},
'vac-nomatch-a' => q{No matching tables have ever been analyzed},
'vac-nomatch-v' => q{No matching tables have ever been vacuumed},
'version' => q{version $1},
'version-badmrtg' => q{Invalid mrtg version argument},
'version-fail' => q{version $1, but expected $2},
'version-ok' => q{version $1},
},
'fr' => {
'backends-fatal' => q{N'a pas pu se connecter : trop de connexions},
'backends-mrtg' => q{DB=$1 Connexions maximum=$2},
'backends-msg' => q{$1 connexions sur $2 ($3%)},
'backends-nomax' => q{N'a pas pu déterminer max_connections},
'backends-oknone' => q{Aucune connexion},
'backends-po' => q{désolé, trop de clients sont déjà connectés},
'backends-users' => q{$1 pour le nombre d'utilisateurs doit être un nombre ou un pourcentage},
'bloat-index' => q{(db $1) index $2 lignes:$3 pages:$4 devrait être:$5 ($6X) octets perdus:$7 ($8)},
'bloat-nomin' => q{aucune relation n'atteint le critère minimum de fragmentation},
'bloat-table' => q{(db $1) table $2.$3 lignes:$4 pages:$5 devrait être:$6 ($7X) place perdue:$8 ($9)},
'checkpoint-baddir' => q{data_directory invalide : "$1"},
'checkpoint-baddir2' => q{pg_controldata n'a pas pu lire le répertoire des données indiqué : « $1 »},
'checkpoint-badver' => q{Échec lors de l'exécution de pg_controldata - probablement la mauvaise version},
'checkpoint-badver2' => q{Échec lors de l'exécution de pg_controldata - est-ce la bonne version ?},
'checkpoint-nodir' => q{Vous devez fournir un argument --datadir ou configurer la variable d'environnement PGDATA},
'checkpoint-nodp' => q{Vous devez installer le module Perl Date::Parse pour utiliser l'action checkpoint},
'checkpoint-noparse' => q{Incapable d'analyser le résultat de la commande pg_controldata : "$1"},
'checkpoint-noregex' => q{Échec de l'appel à pg_controldata $1},
'checkpoint-nosys' => q{N'a pas pu appeler pg_controldata : $1},
'checkpoint-ok' => q{Le dernier CHECKPOINT est survenu il y a une seconde},
'checkpoint-ok2' => q{Le dernier CHECKPOINT est survenu il y a $1 secondes},
'checkpoint-po' => q{Heure du dernier point de contr�le :},
'checksum-badline' => q{Ligne pg_setting invalide : $1},
'checksum-msg' => q{somme de contrôle : $1},
'checksum-nomd' => q{Vous devez installer le module Perl Digest::MD5 pour utiliser l'action checksum},
'checksum-nomrtg' => q{Vous devez fournir une somme de contrôle avec l'option --mrtg},
'custom-invalid' => q{Format invalide renvoyé par la requête personnalisée},
'custom-norows' => q{Aucune ligne renvoyée},
'custom-nostring' => q{Vous devez fournir une requête},
'dbsize-version' => q{La base de données cible doit être une version 8.1 ou ultérieure pour exécuter l'action database_size},
'die-action-version' => q{Ne peut pas exécuter « $1 » : la version du serveur doit être supérieure ou égale à $2, alors qu'elle est $3},
'die-badtime' => q{La valeur de « $1 » doit être une heure valide. Par exemple, -$2 1s -$2 « 10 minutes »},
'die-badversion' => q{Version invalide : $1},
'die-noset' => q{Ne peut pas exécuter « $1 » $2 n'est pas activé},
'die-nosetting' => q{N'a pas pu récupérer le paramètre « $1 »},
'diskspace-fail' => q{Résultat invalide pour la commande « $1 » : $2},
'diskspace-msg' => q{Le système de fichiers $1 monté sur $2 utilise $3 sur $4 ($5%)},
'diskspace-nodata' => q{N'a pas pu déterminer data_directory : êtes-vous connecté en tant que super-utilisateur ?},
'diskspace-nodf' => q{N'a pas pu trouver l'exécutable /bin/df},
'diskspace-nodir' => q{N'a pas pu trouver le répertoire des données « $1 »},
'file-noclose' => q{N'a pas pu fermer $1 : $2},
'fsm-page-highver' => q{Ne peut pas vérifier fsm_pages sur des serveurs en version 8.4 ou ultérieure},
'fsm-page-msg' => q{emplacements de pages utilisés par la FSM : $1 sur $2 ($3%)},
'fsm-rel-highver' => q{Ne peut pas vérifier fsm_relations sur des serveurs en version 8.4 ou ultérieure},
'fsm-rel-msg' => q{relations tracées par la FSM : $1 sur $2 ($3%)},
'invalid-option' => q{Option invalide},
'invalid-query' => q{Une requête invalide a renvoyé : $1},
'listener-count' => q{ en écoute=$1}, ## needs leading space
'listener-msg' => q{processus LISTEN trouvés : $1},
'locks-msg' => q{total des verrous « $1 » : $2},
'locks-msg2' => q{total des verrous : $1},
'logfile-bad' => q{Option logfile invalide « $1 »},
'logfile-debug' => q{la destination est $1, le répertoire est $2, le fichier est $3, l'option facility est $4},
'logfile-debug2' => q{Journal applicatif final : $1},
'logfile-dne' => q{le journal applicatif $1 n'existe pas !},
'logfile-fail' => q{échec pour tracer dans : $1},
'logfile-ok' => q{trace dans : $1},
'logfile-openfail' => q{échec pour l'ouverture du journal applicatif « $1 » : $2},
'logfile-opt-bad' => q{Option logfile invalide},
'logfile-seekfail' => q{Échec de la recherche dans $1 : $2},
'logfile-stderr' => q{La sortie des traces a été redirigés stderr : merci de fournir un nom de fichier},
'logfile-syslog' => q{La base de données utiliser syslog, merci de spécifier le chemin avec l'option --logfile (fac=$1)},
'maxtime' => q{ maxtime=$1}, ## needs leading space
'mrtg-fail' => q{Échec de l'action $1 : $2},
'new-cp-fail' => q{Incapable de déterminer la version actuelle de check_postgres.pl},
'new-cp-ok' => q{La version $1 est la dernière pour check_postgres.pl},
'new-cp-warn' => q{La version $1 de check_postgres.pl existe (ceci est la version $2)},
'new-pg-badver' => q{N'a pas pu déterminer la révision de Postgres (la version était $1)},
'new-pg-badver2' => q{N'a pas pu trouver l'information de révision de Posrgres version $1},
'new-pg-big' => q{Veuillez mettre à jour Postgres vers la version $1. Vous utilisez actuellement la version $2},
'new-pg-match' => q{Postgres est à la dernière révision ($1)},
'new-pg-small' => q{La dernière version de Postgres est la $1, mais vous utilisez actuellement la version $2?},
'no-match-db' => q{Aucune base de données trouvée à cause des options d'exclusion/inclusion},
'no-match-fs' => q{Aucun système de fichier trouvé à cause des options d'exclusion/inclusion},
'no-match-rel' => q{Aucune relation trouvée à cause des options d'exclusion/inclusion},
'no-match-set' => q{Aucun paramètre trouvé à cause des options d'exclusion/inclusion},
'no-match-table' => q{Aucune table trouvée à cause des options d'exclusion/inclusion},
'no-match-user' => q{Aucune entrée trouvée à cause options d'exclusion/inclusion},
'no-time-hires' => q{N'a pas trouvé le module Time::HiRes, nécessaire quand « showtime » est activé},
'opt-output-invalid' => q{Sortie invalide : doit être 'nagios' ou 'mrtg' ou 'simple' ou 'cacti'},
'opt-psql-badpath' => q{Argument invalide pour psql : doit être le chemin complet vers un fichier nommé psql},
'opt-psql-noexec' => q{ Le fichier « $1 » ne paraît pas exécutable},
'opt-psql-noexist' => q{Ne peut pas trouver l'exécutable psql indiqué : $1},
'opt-psql-nofind' => q{N'a pas pu trouver un psql exécutable},
'opt-psql-nover' => q{N'a pas pu déterminer la version de psql},
'opt-psql-restrict' => q{Ne peut pas utiliser l'option --PSQL si NO_PSQL_OPTION est activé},
'preptxn-none' => q{Aucune transaction préparée trouvée},
'qtime-fail' => q{Ne peut pas exécuter l'action txn_idle si stats_command_string est désactivé !},
'qtime-msg' => q{requête la plus longue : $1s},
'range-badcs' => q{Option « $1 » invalide : doit être une somme de contrôle},
'range-badlock' => q{Option « $1 » invalide : doit être un nombre de verrou ou « type1=#;type2=# »},
'range-badpercent' => q{Option « $1 » invalide : doit être un pourcentage},
'range-badpercsize' => q{Option « $1 » invalide : doit être une taille ou un pourcentage},
'range-badsize' => q{Taille invalide pour l'option « $1 »},
'range-badtype' => q{validate_range appelé avec un type inconnu « $1 »},
'range-badversion' => q{Chaîne invalide pour l'option « $1 » : $2},
'range-cactionly' => q{Cette action est pour cacti seulement et ne prend pas les arguments warning et critical},
'range-int' => q{Argument invalide pour l'option « $1 » : doit être un entier},
'range-int-pos' => q{Argument invalide pour l'option « $1 » : doit être un entier positif},
'range-neg-percent' => q{Ne peut pas indiquer un pourcentage négatif !},
'range-none' => q{Les options warning et critical ne sont pas nécessaires},
'range-noopt-both' => q{Doit fournir les options warning et critical},
'range-noopt-one' => q{Doit fournir une option warning ou critical},
'range-noopt-only' => q{Peut seulement fournir une option warning ou critical},
'range-noopt-orboth' => q{Doit fournir une option warning, une option critical ou les deux},
'range-noopt-size' => q{Doit fournir une taille warning et/ou critical},
'range-nosize' => q{Doit fournir une taille warning et/ou critical},
'range-notime' => q{Doit fournir une heure warning et/ou critical},
'range-seconds' => q{Argument invalide pour l'option « $1 » : doit être un nombre de secondes},
'range-version' => q{doit être dans le format X.Y ou X.Y.Z, où X est le numéro de version majeure, },
'range-warnbig' => q{L'option warning ne peut pas être plus grand que l'option critical},
'range-warnbigsize' => q{L'option warning ($1 octets) ne peut pas être plus grand que l'option critical ($2 octets)},
'range-warnbigtime' => q{L'option warning ($1 s) ne peut pas être plus grand que l'option critical ($2 s)},
'range-warnsmall' => q{L'option warningne peut pas être plus petit que l'option critical},
'relsize-msg-ind' => q{le plus gros index est « $1 » : $2},
'relsize-msg-reli' => q{la plus grosse relation est l'index « $1 » : $2},
'relsize-msg-relt' => q{la plus grosse relation est la table « $1 » : $2},
'relsize-msg-tab' => q{la plus grosse table est « $1 » : $2},
'rep-badarg' => q{Argument repinfo invalide : 6 valeurs séparées par des virgules attendues},
'rep-duh' => q{Aucun sens à tester la réplication avec les mêmes valeurs},
'rep-fail' => q{Ligne non répliquée sur l'esclave $1},
'rep-noarg' => q{A besoin d'un argument repinfo},
'rep-norow' => q{Ligne source de la réplication introuvable : $1},
'rep-noslaves' => q{Aucun esclave trouvé},
'rep-notsame' => q{Ne peut pas tester la réplication : les valeurs ne sont pas identiques},
'rep-ok' => q{La ligne a été répliquée},
'rep-sourcefail' => q{Échec de la mise à jour de la source},
'rep-timeout' => q{La ligne n'a pas été répliquée. Délai dépassé : $1},
'rep-unknown' => q{Échec du test de la réplication},
'rep-wrongvals' => q{Ne peut pas tester la réplication : les valeurs ne sont pas les bonnes (ni $1 ni $2 ni $3)},
'runcommand-err' => q{Erreur inconnue de la fonction « run_command »},
'runcommand-nodb' => q{Aucune base de données cible trouvée},
'runcommand-nodupe' => q{N'a pas pu dupliqué STDERR},
'runcommand-noerr' => q{N'a pas pu ouvrir STDERR},
'runcommand-nosys' => q{Échec de l'appel système avec un $1},
'runcommand-pgpass' => q{Création du fichier pgpass temporaire $1},
'runcommand-timeout' => q{Délai épuisée pour la commande ! Essayez d'augmenter --timeout à une valeur plus importante que $1},
'runtime-badmrtg' => q{queryname invalide ?},
'runtime-badname' => q{Option invalide pour queryname option : doit être le nom d'une vue},
'runtime-msg' => q{durée d'exécution de la requête : $1 secondes},
'same-failed' => q{Les bases de données sont différentes. Éléments différents : $1},
'same-matched' => q{Les bases de données ont les mêmes éléments},
'seq-die' => q{N'a pas pu récupérer d'informations sur la séquence $1},
'seq-msg' => q{$1=$2% (appels restant=$3)},
'seq-none' => q{Aucune sequences trouvée},
'symlink-create' => q{Création de « $1 »},
'symlink-done' => q{Création impossible de « $1 »: $2 est déjà lié à "$3"},
'symlink-exists' => q{Création impossible de « $1 »: le fichier $2 existe déjà},
'symlink-fail1' => q{Échec de la suppression de « $1 » : $2},
'symlink-fail2' => q{N'a pas pu supprimer le lien symbolique $1 vers $2 : $3},
'symlink-name' => q{Cette commande ne fonctionnera pas sauf si le programme contient le mot « postgres »},
'symlink-unlink' => q{Supression de « $1 » :$2 },
'testmode-end' => q{FIN DU MODE DE TEST},
'testmode-fail' => q{Échec de la connexion : $1 $2},
'testmode-norun' => q{N'a pas pu exécuter « $1 » sur $2 : la version doit être supérieure ou égale à $3, mais est $4},
'testmode-noset' => q{N'a pas pu exécuter « $1 » sur $2 : $3 n'est pas activé},
'testmode-nover' => q{N'a pas pu trouver la version de $1},
'testmode-ok' => q{Connexion OK : $1},
'testmode-start' => q{DÉBUT DU MODE DE TEST},
'time-day' => q{jour},
'time-days' => q{jours},
'time-hour' => q{heure},
'time-hours' => q{heures},
'time-minute' => q{minute},
'time-minutes' => q{minutes},
'time-month' => q{mois},
'time-months' => q{mois},
'time-second' => q{seconde},
'time-seconds' => q{secondes},
'time-week' => q{semaine},
'time-weeks' => q{semaines},
'time-year' => q{année},
'time-years' => q{années},
'timesync-diff' => q{ diff=$1}, ## needs leading space
'timesync-msg' => q{timediff=$1 Base de données=$2 Local=$3},
'trigger-msg' => q{Triggers désactivés : $1},
'txnidle-msg' => q{transaction en attente la plus longue : $1s},
'txnidle-none' => q{Aucun processus en attente dans une transaction},
'txntime-fail' => q{Échec de la requête},
'txntime-msg' => q{Transaction la plus longue : $1s},
'txntime-none' => q{Aucune transaction},
'txnwrap-cbig' => q{La valeur critique doit être inférieure à 2 milliards},
'txnwrap-wbig' => q{La valeur d'avertissement doit être inférieure à 2 milliards},
'unknown-error' => q{erreur inconnue},
'usage' => qq{\nUsage: \$1 <options>\n Essayez « \$1 --help » pour liste complète des options\n\n},
'vac-msg' => q{Base de données : $1 Table : $2},
'vac-nomatch-a' => q{Aucune des tables correspondantes n'a eu d'opération ANALYZE},
'vac-nomatch-v' => q{Aucune des tables correspondantes n'a eu d'opération VACUUM},
'version' => q{version $1},
'version-badmrtg' => q{Argument invalide pour la version de mrtg},
'version-fail' => q{version $1, alors que la version attendue est $2},
'version-ok' => q{version $1},
},
'af' => {
},
'cs' => {
'checkpoint-po' => q{�as posledn�ho kontroln�ho bodu:},
},
'de' => {
'backends-po' => q{tut mir leid, schon zu viele Verbindungen},
'checkpoint-po' => q{Zeit des letzten Checkpoints:},
},
'es' => {
'backends-po' => q{lo siento, ya tenemos demasiados clientes},
'checkpoint-po' => q{Instante de �ltimo checkpoint:},
},
'fa' => {
'checkpoint-po' => q{زمان آخرین وارسی:},
},
'hr' => {
'backends-po' => q{nažalost, već je otvoreno previše klijentskih veza},
},
'hu' => {
'checkpoint-po' => q{A legut�bbi ellen�rz�pont ideje:},
},
'it' => {
'checkpoint-po' => q{Orario ultimo checkpoint:},
},
'ja' => {
'backends-po' => q{現在クライアント数が多すぎます},
'checkpoint-po' => q{最終チェックポイント時刻:},
},
'ko' => {
'backends-po' => q{최대 동시 접속자 수를 초과했습니다.},
'checkpoint-po' => q{������ üũ����Ʈ �ð�:},
},
'nb' => {
'backends-po' => q{beklager, for mange klienter},
'checkpoint-po' => q{Tidspunkt for nyeste kontrollpunkt:},
},
'nl' => {
},
'pl' => {
'checkpoint-po' => q{Czas najnowszego punktu kontrolnego:},
},
'pt_BR' => {
'backends-po' => q{desculpe, muitos clientes conectados},
'checkpoint-po' => q{Hora do último ponto de controle:},
},
'ro' => {
'checkpoint-po' => q{Timpul ultimului punct de control:},
},
'ru' => {
'backends-po' => q{��������, ��� ������� ����� ��������},
'checkpoint-po' => q{����� ��������� checkpoint:},
},
'sk' => {
'backends-po' => q{je mi ��to, je u� pr�li� ve�a klientov},
'checkpoint-po' => q{Čas posledného kontrolného bodu:},
},
'sl' => {
'backends-po' => q{povezanih je �e preve� odjemalcev},
'checkpoint-po' => q{�as zadnje kontrolne to�ke ............},
},
'sv' => {
'backends-po' => q{ledsen, f�r m�nga klienter},
'checkpoint-po' => q{Tidpunkt f�r senaste kontrollpunkt:},
},
'ta' => {
'checkpoint-po' => q{நவீன சோதனை மையத்தின் நேரம்:},
},
'tr' => {
'backends-po' => q{üzgünüm, istemci sayısı çok fazla},
'checkpoint-po' => q{En son checkpoint'in zamanı:},
},
'zh_CN' => {
'backends-po' => q{�Բ���, �Ѿ���̫���Ŀͻ�},
'checkpoint-po' => q{���¼�������ʱ��:},
},
'zh_TW' => {
'backends-po' => q{對不起,用戶端過多},
'checkpoint-po' => q{最新的檢查點時間:},
},
);
## use critic
our $lang = $ENV{LC_ALL} || $ENV{LC_MESSAGES} || $ENV{LANG} || 'en';
$lang = substr($lang,0,2);
## Messages are stored in these until the final output via finishup()
our (%ok, %warning, %critical, %unknown);
our $ME = basename($0);
our $ME2 = 'check_postgres.pl';
our $USAGE = msg('usage', $ME);
## This gets turned on for meta-commands which don't hit a Postgres database
our $nohost = 0;
## Global error string, mostly used for MRTG error handling
our $ERROR = '';
$opt{test} = 0;
$opt{timeout} = 30;
## Look for any rc files to control additional parameters
## Command line options always overwrite these
## Format of these files is simply name=val
## This option must come before the GetOptions call
for my $arg (@ARGV) {
if ($arg eq '--no-check_postgresrc') {
$opt{'no-check_postgresrc'} = 1;
last;
}
}
my $rcfile;
if (! $opt{'no-check_postgresrc'}) {
if (-e '.check_postgresrc') {
$rcfile = '.check_postgresrc';
}
elsif (-e "$ENV{HOME}/.check_postgresrc") {
$rcfile = "$ENV{HOME}/.check_postgresrc";
}
elsif (-e '/etc/check_postgresrc') {
$rcfile = '/etc/check_postgresrc';
}
}
## We need a temporary hash so that multi-value options can be overridden on the command line
my %tempopt;
if (defined $rcfile) {
open my $rc, '<', $rcfile or die qq{Could not open "$rcfile": $!\n};
RCLINE:
while (<$rc>) {
next if /^\s*#/;
next unless /^\s*(\w+)\s*=\s*(.+?)\s*$/o;
my ($name,$value) = ($1,$2); ## no critic (ProhibitCaptureWithoutTest)
## Map alternate option spellings to preferred names
if ($name eq 'dbport' or $name eq 'p') {
$name = 'port';
}
elsif ($name eq 'dbhost' or $name eq 'H') {
$name = 'host';
}
elsif ($name eq 'db') {
$name = 'dbname';
}
elsif ($name eq 'u') {
$name = 'dbuser';
}
if ($name eq 'dbport2' or $name eq 'p2') {
$name = 'port2';
}
elsif ($name eq 'dbhost2' or $name eq 'H2') {
$name = 'host2';
}
elsif ($name eq 'db2') {
$name = 'dbname2';
}
elsif ($name eq 'u2') {
$name = 'dbuser2';
}
## These options are multiples ('@s')
for my $arr (qw/include exclude includeuser excludeuser host port dbuser dbname dbpass dbservice/) {
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;
}
close $rc or die;
}
die $USAGE unless
GetOptions(
\%opt,
'version|V',
'verbose|v+',
'help|h',
'output=s',
'simple',
'showperf=i',
'perflimit=i',
'showtime=i',
'timeout|t=i',
'test',
'symlinks',
'debugoutput=s',
'no-check_postgresrc',
'action=s',
'warning=s',
'critical=s',
'include=s@',
'exclude=s@',
'includeuser=s@',
'excludeuser=s@',
'host|dbhost|H=s@',
'port|dbport|p=s@',
'dbname|db=s@',
'dbuser|u=s@',
'dbpass=s@',
'dbservice=s@',
'host2|dbhost2|H2=s@',
'port2|dbport2|p2=s@',
'dbname2|db2=s@',
'dbuser2|u2=s@',
'dbpass2=s@',
'dbservice2=s@',
'PSQL=s',
'get_method=s',
'language=s',
'mrtg=s', ## used by MRTG checks only
'logfile=s', ## used by check_logfile only
'queryname=s', ## used by query_runtime only
'query=s', ## used by custom_query only
'valtype=s', ## used by custom_query only
'reverse', ## used by custom_query only
'repinfo=s', ## used by replicate_row only
'noidle', ## used by backends only
'datadir=s', ## used by checkpoint only
)
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 = $opt{output} || '';
## Allow the optimization of the get_methods list by an argument
if ($opt{get_method}) {
my $found = 0;
for my $meth (@get_methods) {
if ($meth =~ /^$opt{get_method}/io) {
@get_methods = ($meth);
$found = 1;
last;
}
}
if (!$found) {
print "Unknown value for get_method: $opt{get_method}\n";
print "Valid choices are:\n";
print (join "\n" => map { s/(\w+).*/$1/; $_ } @get_methods);
print "\n";
exit;
}
}
## Allow the language to be changed by an explicit option
if ($opt{language}) {
$lang = substr($opt{language},0,2);
}
## Output the actual string returned by psql in the normal output
## Argument is 'a' for all, 'w' for warning, 'c' for critical, 'u' for unknown
## Can be grouped together
our $DEBUGOUTPUT = $opt{debugoutput} || '';
our $DEBUG_INFO = '?';
## If not explicitly given an output, check the current directory,
## then fall back to the default.
if (!$OUTPUT) {
my $dir = getcwd;
if ($dir =~ /(nagios|mrtg|simple|cacti)/io) {
$OUTPUT = lc $1;
}
elsif ($opt{simple}) {
$OUTPUT = 'simple';
}
else {
$OUTPUT = $DEFAULT_OUTPUT;
}
}
## Extract transforms from the output
$opt{transform} = '';
if ($OUTPUT =~ /\b(kb|mb|gb|tb|eb)\b/) {
$opt{transform} = uc $1;
}
if ($OUTPUT =~ /(nagios|mrtg|simple|cacti)/io) {
$OUTPUT = lc $1;
}
## Check for a valid output setting
if ($OUTPUT ne 'nagios' and $OUTPUT ne 'mrtg' and $OUTPUT ne 'simple' and $OUTPUT ne 'cacti') {
die msgn('opt-output-invalid');
}
our $MRTG = ($OUTPUT eq 'mrtg' or $OUTPUT eq 'simple') ? 1 : 0;
our (%stats, %statsmsg);
our $SIMPLE = $OUTPUT eq 'simple' ? 1 : 0;
## See if we need to invoke something based on our name
our $action = $opt{action} || '';
if ($ME =~ /check_postgres_(\w+)/) {
$action = $1;
}
$VERBOSE >= 3 and warn Dumper \%opt;
if ($opt{version}) {
print qq{$ME2 version $VERSION\n};
exit 0;
}
## Quick hash to put normal action information in one place:
our $action_info = {
# Name # clusterwide? # helpstring
autovac_freeze => [1, 'Checks how close databases are to autovacuum_freeze_max_age.'],
backends => [1, 'Number of connections, compared to max_connections.'],
bloat => [0, 'Check for table and index bloat.'],
checkpoint => [1, 'Checks how long since the last checkpoint'],
connection => [0, 'Simple connection check.'],
custom_query => [0, 'Run a custom query.'],
database_size => [0, 'Report if a database is too big.'],
dbstats => [1, 'Returns stats from pg_stat_database: Cacti output only'],
disabled_triggers => [0, 'Check if any triggers are disabled'],
disk_space => [1, 'Checks space of local disks Postgres is using.'],
fsm_pages => [1, 'Checks percentage of pages used in free space map.'],
fsm_relations => [1, 'Checks percentage of relations used in free space map.'],
index_size => [0, 'Checks the size of indexes only.'],
table_size => [0, 'Checks the size of tables only.'],
relation_size => [0, 'Checks the size of tables and indexes.'],
last_analyze => [0, 'Check the maximum time in seconds since any one table has been analyzed.'],
last_vacuum => [0, 'Check the maximum time in seconds since any one table has been vacuumed.'],
last_autoanalyze => [0, 'Check the maximum time in seconds since any one table has been autoanalyzed.'],
last_autovacuum => [0, 'Check the maximum time in seconds since any one table has been autovacuumed.'],
listener => [0, 'Checks for specific listeners.'],
locks => [0, 'Checks the number of locks.'],
logfile => [1, 'Checks that the logfile is being written to correctly.'],
new_version_cp => [0, 'Checks if a newer version of check_postgres.pl is available.'],
new_version_pg => [0, 'Checks if a newer version of Postgres is available.'],
prepared_txns => [1, 'Checks number and age of prepared transactions.'],
query_runtime => [0, 'Check how long a specific query takes to run.'],
query_time => [1, 'Checks the maximum running time of current queries.'],
replicate_row => [0, 'Verify a simple update gets replicated to another server.'],
same_schema => [0, 'Verify that two databases have the exact same tables, columns, etc.'],
sequence => [0, 'Checks remaining calls left in sequences.'],
settings_checksum => [0, 'Check that no settings have changed since the last check.'],
timesync => [0, 'Compare database time to local system time.'],
txn_idle => [1, 'Checks the maximum "idle in transaction" time.'],
txn_time => [1, 'Checks the maximum open transaction time.'],
txn_wraparound => [1, 'See how close databases are getting to transaction ID wraparound.'],
version => [1, 'Check for proper Postgres version.'],
wal_files => [1, 'Check the number of WAL files in the pg_xlog directory'],
};
## XXX Need to i18n the above
our $action_usage = '';
our $longname = 1;
for (keys %$action_info) {
$longname = length($_) if length($_) > $longname;
}
for (sort keys %$action_info) {
$action_usage .= sprintf " %-*s - %s\n", 2+$longname, $_, $action_info->{$_}[1];
}
if ($opt{help}) {
print qq{Usage: $ME2 <options>
Run various tests against one or more Postgres databases.
Returns with an exit code of 0 (success), 1 (warning), 2 (critical), or 3 (unknown)
This is version $VERSION.
Common connection options:
-H, --host=NAME hostname(s) to connect to; defaults to none (Unix socket)
-p, --port=NUM port(s) to connect to; defaults to $opt{defaultport}.
-db, --dbname=NAME database name(s) to connect to; defaults to 'postgres' or 'template1'
-u --dbuser=NAME database user(s) to connect as; defaults to '$opt{defaultuser}'
--dbpass=PASS database password(s); use a .pgpass file instead when possible
--dbservice=NAME service name to use inside of pg_service.conf
Connection options can be grouped: --host=a,b --host=c --port=1234 --port=3344
would connect to a-1234, b-1234, and c-3344
Limit options:
-w value, --warning=value the warning threshold, range depends on the action
-c value, --critical=value the critical threshold, range depends on the action
--include=name(s) items to specifically include (e.g. tables), depends on the action
--exclude=name(s) items to specifically exclude (e.g. tables), depends on the action
--includeuser=include objects owned by certain users
--excludeuser=exclude objects owned by certain users
Other options:
--PSQL=FILE location of the psql executable; avoid using if possible
-v, --verbose verbosity level; can be used more than once to increase the level
-h, --help display this help information
-t X, --timeout=X how long in seconds before we timeout. Defaults to 30 seconds.
--symlinks create named symlinks to the main program for each action
Actions:
Which test is determined by the --action option, or by the name of the program
$action_usage
For a complete list of options and full documentation, please view the POD for this file.
Two ways to do this is to run:
pod2text $ME | less
pod2man $ME | man -l -
Or simply visit: http://bucardo.org/check_postgres/
};
exit 0;
}
build_symlinks() if $opt{symlinks};
$action =~ /\w/ or die $USAGE;
## Be nice and figure out what they meant
$action =~ s/\-/_/g;
$action = lc $action;
## Build symlinked copies of this file
build_symlinks() if $action =~ /build_symlinks/; ## Does not return, may be 'build_symlinks_force'
## Die if Time::HiRes is needed but not found
if ($opt{showtime}) {
eval {
require Time::HiRes;
import Time::HiRes qw/gettimeofday tv_interval sleep/;
};
if ($@) {
die msg('no-time-hires');
}
}
## We don't (usually) want to die, but want a graceful Nagios-like exit instead
sub ndie {
eval { File::Temp::cleanup(); };
my $msg = shift;
chomp $msg;
print "ERROR: $msg\n";
exit 3;
}
sub msg { ## no critic
my $name = shift || '?';
my $msg = '';
if (exists $msg{$lang}{$name}) {
$msg = $msg{$lang}{$name};
}
elsif (exists $msg{'en'}{$name}) {
$msg = $msg{'en'}{$name};
}
else {
return "Invalid message: $name";
}
my $x=1;
{
my $val = $_[$x-1];
$val = '?' if ! defined $val;
last unless $msg =~ s/\$$x/$val/g;
$x++;
redo;
}
return $msg;
} ## end of msg
sub msgn { ## no critic
return msg(@_) . "\n";
}
sub msg_en {
my $name = shift || '?';
return $msg{'en'}{$name};
} ## end of msg_en
## Everything from here on out needs psql, so find and verify a working version:
if ($NO_PSQL_OPTION) {
delete $opt{PSQL} and ndie msg('opt-psql-restrict');
}
if (! defined $PSQL or ! length $PSQL) {
if (exists $opt{PSQL}) {
$PSQL = $opt{PSQL};
$PSQL =~ m{^/[\w\d\/]*psql$} or ndie msg('opt-psql-badpath');
-e $PSQL or ndie msg('opt-psql-noexist', $PSQL);
}
else {
my $psql = $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/psql" : 'psql';
chomp($PSQL = qx{which $psql});
$PSQL or ndie msg('opt-psql-nofind');
}
}
-x $PSQL or ndie msg('opt-psql-noexec', $PSQL);
$res = qx{$PSQL --version};
$res =~ /^psql \(PostgreSQL\) (\d+\.\d+)(\S*)/ or ndie msg('opt-psql-nover');
our $psql_version = $1;
our $psql_revision = $2;
$psql_revision =~ s/\D//g;
$VERBOSE >= 2 and warn qq{psql=$PSQL version=$psql_version\n};
$opt{defaultdb} = $psql_version >= 7.4 ? 'postgres' : 'template1';
sub add_response {
my ($type,$msg) = @_;
$db->{host} ||= '';
if (defined $opt{dbname2} and defined $opt{dbname2}->[0] and length $opt{dbname2}->[0]
and $opt{dbname}->[0] ne $opt{dbname2}->[0]) {
$db->{dbname} .= " => $opt{dbname2}->[0]";
}
if (defined $opt{host2} and defined $opt{host2}->[0] and length $opt{host2}->[0]
and $opt{host}->[0] ne $opt{host2}->[0]) {
$db->{host} .= " => $opt{host2}->[0]";