Hmmm I'm a BTS newbie, thought I could email control to add the patch
tag and include the attachment in the email.

Oh well, trying again... sorry if you receive the patch twice.

-- 
Gerald Turner  Email: gtur...@unzane.com  JID: gtur...@jabber.unzane.com
GPG: 0xFA8CD6D5  21D9 B2E8 7FE7 F19E 5F7D  4D0C 3FA0 810F FA8C D6D5
--- munin-1.4.5.orig/plugins/node.d/slapd_.in	2009-11-11 18:38:54.000000000 -0800
+++ munin-1.4.5/plugins/node.d/slapd_.in	2010-09-07 17:57:16.000000000 -0700
@@ -37,7 +37,7 @@
 # Change these to reflect your LDAP ACL. The given DN must have
 # read access to the Monitor branch.
 my $basedn = "cn=Monitor";
-my $server = "localhost";
+my $server = ($ENV{'server'} || 'localhost');
 my $userdn = ($ENV{'binddn'} || '');
 my $userpw = ($ENV{'bindpw'} || '');
 
@@ -149,10 +149,21 @@
           print "$name.type GAUGE\n";
         }
     } elsif ($action =~ /^operations(?:_diff)?$/) {
-        my $ldap = Net::LDAP->new ($server) or die "$@";
-        $ldap->bind ($userdn, password => $userpw) or die "$@";
+        my $ldap = Net::LDAP->new ($server)
+            or die "Failed to connect to server $server: $@";
+        my $mesg;
+        if ($userdn ne '') {
+          $mesg = $ldap->bind ($userdn, password => $userpw)
+              or die "Failed to bind with $userdn: $@";
+        } else {
+          $mesg = $ldap->bind
+              or die "Failed to bind anonymously: $@";
+        }
+        if ($mesg->code) {
+          die "Failed to bind: " . $mesg->error;
+        }
         my $searchdn = $ops{$action}->{'search'} . "," . $basedn;
-        my $mesg =
+        $mesg =
             $ldap->search (
                            base   => $searchdn,
                            scope  => 'one',
@@ -179,6 +190,8 @@
                 print "$name.warning 1\n";
             }            
         }
+
+        $ldap->unbind;
     } else {
         print "$action.label $ops{$action}->{'label'}\n";
         print "$action.type DERIVE\n";
@@ -196,10 +209,34 @@
 
         # Check for LDAP version 3
         my $ldap = Net::LDAP->new ($server, version => 3)
-            or do { print "no (Needs LDAPv3)\n"; exit 0; };
-        $ldap->bind ($userdn, password => $userpw)
-            or do { print "no (Can't log in, check env file)\n"; exit 0; };
+            or do { print "no ($@)\n"; exit 0; };
+
+        my $mesg;
+        if ($userdn ne '') {
+          $mesg = $ldap->bind ($userdn, password => $userpw)
+            or do { print "no ($@)\n"; exit 0; };
+        } else {
+          $mesg = $ldap->bind
+            or do { print "no ($@)\n"; exit 0; };
+        }
+        if ($mesg->code) {
+          print "no (" . $mesg->error . ")\n";
+          exit 0;
+        }
 
+        $mesg =
+            $ldap->search (
+                           base   => $basedn,
+                           scope  => 'one',
+                           filter => '(objectClass=monitorServer)',
+                           attrs  => 'cn',
+                           );
+        if ($mesg->code) {
+          print "no (" . $mesg->error . ")\n";
+          exit 0;
+        }
+        print "yes\n";
+        exit 0;
     } elsif ($ARGV[0] eq "config") {
         if ($0 =~ /slapd_([\w\d_]+)$/) {
             my $action = $1;
@@ -225,9 +262,18 @@
 
 # Net::LDAP variant
 my $ldap = Net::LDAP->new ($server, version => 3)
-    or die "$@";
-$ldap->bind ($userdn,password => $userpw)
-    or die "$@";
+    or die "Failed to connect to server $server: $@";
+my $mesg;
+if ($userdn ne '') {
+  $mesg = $ldap->bind ($userdn, password => $userpw)
+      or die "Failed to bind with $userdn: $@";
+} else {
+  $mesg = $ldap->bind
+      or die "Failed to bind anonymously: $@";
+}
+if ($mesg->code) {
+  die "Failed to bind: " . $mesg->error;
+}
 
 my $searchdn = $ops{$action}->{'search'} . "," . $basedn;
 my $searchattrs;
@@ -250,7 +296,7 @@
   $scope = $ops{$action}->{'scope'};
 }
 
-my $mesg =
+$mesg =
     $ldap->search (
                    base   => $searchdn,
                    scope  => $scope,

Reply via email to