diff -r da08b2a30e06 -r 52faa36ba7f8 check --- a/check Fri Jan 10 11:20:30 2014 +0100 +++ b/check Sat Jan 11 17:20:05 2014 +0100 @@ -1,4 +1,5 @@ #! /usr/bin/perl +# source: https://ssl.schlittermann.de/hg/ius/nagios/nagios-plugin-amanda-client use 5.010; use strict; @@ -28,20 +29,29 @@ sub warning; sub critical; sub unknown; +sub verbose; +sub unique { my %h; @h{@_} = (); keys %h } $SIG{__DIE__} = sub { unknown @_ unless $^S }; exit main @ARGV; + #---- sub main { + my $opt_verbose = 0; GetOptions( 'h|help' => sub { pod2usage(-verbose => 1, -exit => 0) }, 'm|man' => sub { pod2usage(-verbose => 2, -exit => 0) }, + 'v|verbose' => \$opt_verbose, ) or pod2usage; + if ($opt_verbose) { *::verbose = sub { say '# ', @_ } } + else { *::verbose = sub { } } + + # test needs to be run as root:* or as backup:backup my $USER = 'backup'; my $CFDIR = '/etc/amanda'; @@ -51,6 +61,7 @@ # amservice needs to be suid root, but executable # by the backup user/group + verbose q{checking permissions for `amservice'}; eval { check_perms find_tool('amservice'), 04750, 'root', $) } or unknown $@; @@ -58,13 +69,14 @@ # here we suppose that it's possible to find strings like # 'conf "foo"' in files named 'amanda-client.conf' below /etc/amanda - my @confs = eval { config_names $CFDIR } + verbose qq{find config names from $CFDIR}; + my @confs = sort +unique eval { config_names $CFDIR } or unknown $@; eval { amchecks @confs } or critical $@; my @dles = eval { amlists @confs } or critical $@; - ok @dles; + ok 'config: ' .join(', ', @confs), @dles; # never reached return 0; @@ -94,6 +106,8 @@ } endgrent; $) = "@groups"; + + verbose "su to $uid:$gid"; setgid $gid; setuid $uid; } @@ -249,6 +263,10 @@ Show the man page of this tool. +=item B<-v>|B<--verbose> + +Show what's going only. Many for debugging purpose. (default: off) + =back =head1 PREPARATIONS @@ -293,4 +311,4 @@ =cut - +# vim:et ts=4 sw=4 aw ai: