source: trunk/server/fedora/config/etc/nagios/check_ldap_mmr.real @ 1272

Last change on this file since 1272 was 1272, checked in by mitchb, 15 years ago
Wrap check_ldap_mmr with a sudo invocation, and don't spew logs about it
  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/perl -w
2
3# Originally by Emmanuel BUU <emmanuel.buu@ives.fr> (c) IVèS 2008
4# Adapted for scripts.mit.edu by Mitchell Berger <mitchb@mit.edu>
5
6use Net::LDAP;
7use strict;
8
9# Nagios codes
10my %ERRORS=('OK'=>0, 'WARNING'=>1, 'CRITICAL'=>2, 'UNKNOWN'=>3, 'DEPENDENT'=>4);
11
12my $ldapserver = 'localhost';
13my $user = 'cn=Directory Manager';
14my $passwdfile = '/etc/signup-ldap-pw';
15my $base = "cn=config";
16my $server="nsDS5ReplicaHost";
17my $status="nsds5replicaLastUpdateStatus";
18my $laststart="nsds5replicaLastUpdateStart";
19my $lastend="nsds5replicaLastUpdateEnd";
20 
21my $ldap=ConnectLdap();
22my $result=LDAPSearch($ldap,"objectClass=nsDS5ReplicationAgreement","",$base);
23my @entries = $result->entries;
24foreach my $entr ( @entries ) {
25    my $servername=$entr->get_value($server);
26    my $serverstatus=$entr->get_value($status);
27    my $serverlaststart=$entr->get_value($laststart);
28    my $serverlastend=$entr->get_value($lastend);
29    my $statuscode = $serverstatus;
30    $statuscode =~ s/(^[-0123456789]+) (.*$)/$1/;
31    $serverlaststart =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/;
32    $serverlastend =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/;
33    print "Replication to $servername last operation $serverlaststart ";
34    print "Status: $serverstatus.\n";
35    if ($statuscode) {
36        &nagios_return("ERROR", "Replication error: " . $serverstatus);
37    }
38}
39&nagios_return("OK", "All replicas are OK");
40
41sub ConnectLdap {
42    my $ldap = Net::LDAP->new ( $ldapserver ) or die "$@";
43    open (PASSWD, $passwdfile) || &nagios_return("CRITICAL", "Could not read credentials");
44    my $passwd = <PASSWD>;
45    close (PASSWD);
46    my $mesg = $ldap->bind ( "$user", password => "$passwd" , version => 3 );
47    if ($mesg->code) {
48        &nagios_return("CRITICAL", "Failed to bind to LDAP: " . $mesg->error);
49    }
50    return $ldap;
51}
52
53sub LDAPSearch {
54    my ($ldap,$searchString,$attrs,$base) = @_;
55    my $result = $ldap->search ( base    => "$base",
56                                 scope   => "sub",
57                                 filter  => "$searchString",
58                                 attrs   =>  $attrs
59                               );
60}
61
62sub nagios_return($$) {
63    my ($ret, $message) = @_;
64    my ($retval, $retstr);
65    if (defined($ERRORS{$ret})) {
66        $retval = $ERRORS{$ret};
67        $retstr = $ret;
68    } else {
69        $retstr = 'UNKNOWN';
70        $retval = $ERRORS{$retstr};
71    }
72    $message = "$retstr - $message\n";
73    print $message;
74    exit $retval;
75}
76
Note: See TracBrowser for help on using the repository browser.