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

Last change on this file since 1342 was 1342, checked in by mitchb, 14 years ago
Improvements to check_ldap_mmr plugin o Don't put a newline after each replica's output; the Nagios status page only captures the first line, so run them all together on one line. o Don't return immediately upon finding an error; continue to check the other replicas and print status info about them. o If any replicas have issues, upgrade the return from "ERROR" (which is "UNKNOWN" and doesn't cause an alert) to "WARNING" (a replication failure is usually not a problem on the server running the plugin, so it's probably not a CRITICAL issue for that machine).
  • Property svn:executable set to *
File size: 2.6 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;
24my $errors = 0;
25my $errorstring = "Replication error(s): ";
26foreach my $entr ( @entries ) {
27    my $servername=$entr->get_value($server);
28    my $serverstatus=$entr->get_value($status);
29    my $serverlaststart=$entr->get_value($laststart);
30    my $serverlastend=$entr->get_value($lastend);
31    my $statuscode = $serverstatus;
32    $statuscode =~ s/(^[-0123456789]+) (.*$)/$1/;
33    $serverlaststart =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/;
34    $serverlastend =~ s/(....)(..)(..)(..)(..)(..)./$1-$2-$3\ $4:$5:$6/;
35    print "Replication to $servername last operation $serverlaststart ";
36    print "Status: $serverstatus.     ";
37    if ($statuscode) {
38        $errors++;
39        $errorstring = $errorstring . $serverstatus . ", ";
40    }
41}
42if ($errors > 0) {
43    &nagios_return("WARNING", $errorstring);
44} else {
45    &nagios_return("OK", "All replicas are OK");
46}
47
48sub ConnectLdap {
49    my $ldap = Net::LDAP->new ( $ldapserver ) or die "$@";
50    open (PASSWD, $passwdfile) || &nagios_return("CRITICAL", "Could not read credentials");
51    my $passwd = <PASSWD>;
52    close (PASSWD);
53    my $mesg = $ldap->bind ( "$user", password => "$passwd" , version => 3 );
54    if ($mesg->code) {
55        &nagios_return("CRITICAL", "Failed to bind to LDAP: " . $mesg->error);
56    }
57    return $ldap;
58}
59
60sub LDAPSearch {
61    my ($ldap,$searchString,$attrs,$base) = @_;
62    my $result = $ldap->search ( base    => "$base",
63                                 scope   => "sub",
64                                 filter  => "$searchString",
65                                 attrs   =>  $attrs
66                               );
67}
68
69sub nagios_return($$) {
70    my ($ret, $message) = @_;
71    my ($retval, $retstr);
72    if (defined($ERRORS{$ret})) {
73        $retval = $ERRORS{$ret};
74        $retstr = $ret;
75    } else {
76        $retstr = 'UNKNOWN';
77        $retval = $ERRORS{$retstr};
78    }
79    $message = "$retstr - $message\n";
80    print $message;
81    exit $retval;
82}
83
Note: See TracBrowser for help on using the repository browser.