# HG changeset patch # User Matthias Förste # Date 1461073989 -7200 # Node ID ce6d096929899ea0c9a0ae825dd73c8c34d43084 # Parent 7202e55a0713407e2058fbedf9d7941bfc6e8890 [perltidy] diff -r 7202e55a0713 -r ce6d09692989 check_ldap_repl.pl --- a/check_ldap_repl.pl Tue Apr 19 15:50:36 2016 +0200 +++ b/check_ldap_repl.pl Tue Apr 19 15:53:09 2016 +0200 @@ -35,11 +35,11 @@ use if $ENV{DEBUG} => "Smart::Comments"; my %ERRORS = ( - OK => 0, - WARNING => 1, - CRITICAL => 2, - UNKNOWN => 3, - DEPENDENT => 4 + OK => 0, + WARNING => 1, + CRITICAL => 2, + UNKNOWN => 3, + DEPENDENT => 4 ); my $ME = basename $0; @@ -66,7 +66,8 @@ sub stamp { my ($u, $dn, $attr) = @_; - my $l = ref $u eq 'Net::LDAP' ? $u : Net::LDAP->new($u, onerror => 'die') or die "$@"; + my $l = ref $u eq 'Net::LDAP' ? $u : Net::LDAP->new($u, onerror => 'die') + or die "$@"; my $r = $l->search(base => $dn, scope => 'base', filter => '(objectClass=*)'); die "unexpected result count: ", $r->count unless $r->count == 1; my @v = $r->entry(0)->get_value($attr); @@ -76,9 +77,9 @@ } sub version { - my ( $progname, $version ) = @_; - - print <<_VERSION; + my ($progname, $version) = @_; + + print <<_VERSION; $progname version $version Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support. Copyright (C) 2016 by Matthias Förste and Schlittermann internet & unix support. @@ -91,31 +92,42 @@ MAIN: { - my $c = AppConfig->new( { CASE => 1 }, - map { $_, { ref $defaults->{$_} eq 'CODE' ? 'ACTION' : 'DEFAULT' => $defaults->{$_} } } keys %{$defaults} + my $c = AppConfig->new( + { CASE => 1 }, + map { + $_, + { ref $defaults->{$_} eq 'CODE' + ? 'ACTION' + : 'DEFAULT' => $defaults->{$_} } + } keys %{$defaults} ) or die "Can't initialize"; my $cf = $c->get('config'); + # ignore default configuration file if it does not exist $c->file($cf) if -e $cf; # read configuration file if passed on command line $c->getopt(qw(no_ignore_case)); $c->file($cf) if $cf ne ($cf = $c->get('config')); + # make sure that command line options override any config file options $c->getopt; my %o = $c->varlist('.'); my $t = time(); - my $p = Net::LDAP->new($o{provider}, onerror => 'die' ) or die $@; + my $p = Net::LDAP->new($o{provider}, onerror => 'die') or die $@; $p->bind($o{binddn}, password => $o{password}); $p->modify($o{dn}, replace => { $o{attribute} => $t }); my $tp = stamp($p, $o{dn}, $o{attribute}); die "Provider update failed for unknown reason\n" unless $tp == $t; sleep $o{wait}; - for (@{$o{consumer}}) { critical "'$_' out of sync\n" unless $tp == stamp($_, $o{dn}, $o{attribute}); } + for (@{ $o{consumer} }) { + critical "'$_' out of sync\n" + unless $tp == stamp($_, $o{dn}, $o{attribute}); + } print "$NAME OK: servers are in sync\n"; exit $ERRORS{OK};