[Date Prev][Date Next] [Chronological] [Thread] [Top]

ldapmon.rb for monitor backend watching



After yesterdays monitor backend discussion, I stole^W was inspired by Quanahs
cricket setup to start monitoring my own openldap servers, and found that
for some reason perl-ldap was taking an age to read everything in, so I
wrote an eqivalent version in ruby
(yes, I realise about 5 people use ruby, I'm afraid I'm one of them ).

It uses ruby-ldap from : http://raa.ruby-lang.org/project/ruby-ldap/
and is about 3 times faster than the perl version on my machines.

Posted here for the record, run it without arguments for a usage.
It's a little rough and ready (no cleartext support, since I don't use it,
and if you forget to set the bind_dn and password it outputs nothing)
but is usable as a general purpose script as well as a cricket exec target
(the exec target ignores everything after the first space, hence the leading
zeroes in the usage statements).

Anyway, it's pretty small, hope it's of use to someone:

----------------------8<----------------------------------------

#!/usr/bin/ruby
require 'ldap'

bind_dn = ''
pass= ''

# set false to use SSL
wantTLS = true

ldaphost, op = ARGV

cfg = {
  'bytes' => [ 'cn=Bytes,cn=Statistics,cn=Monitor', 'monitorCounter' ],
  'entries' => [ 'cn=Entries,cn=Statistics,cn=Monitor', 'monitorCounter' ],
  'pdus' => [ 'cn=PDU,cn=Statistics,cn=Monitor', 'monitorCounter' ],
  'totalcons' => [ 'cn=Total,cn=Connections,cn=Monitor', 'monitorCounter' ],
  'currentcons' => [ 'cn=Current,cn=Connections,cn=Monitor', 'monitorCounter' ],

  'ops' => [ 'cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'binds' => [ 'cn=Bind,cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'unbinds' => [ 'cn=Unbind,cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'adds' => [ 'cn=Add,cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'deletes' => [ 'cn=Delete,cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'mods' => [ 'cn=Modify,cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'modrdns' => [ 'cn=Modrdn,cn=Operations,cn=Monitor', 'monitorOpCompleted' ],
  'searches' => [ 'cn=Search,cn=Operations,cn=Monitor', 'monitorOpCompleted' ]
}

unless cfg.keys.include?(op)
  puts "0 usage:#{$0} server operation"
  puts "0 (operation = one of : #{cfg.keys.join(' ')} )"
  exit
end
dn, attr = cfg[op]

begin
  port = wantTLS ? 389 : 636
  conn = LDAP::SSLConn.new(ldaphost,port,wantTLS)

  conn.bind(bind_dn,pass) {
      conn.search(dn, LDAP::LDAP_SCOPE_BASE, 'objectClass=*', [attr] ) { |e|
        puts "#{e.to_hash[attr]} #{op}"
      }
  }
rescue Exception => e
	puts "0 #{e}"
end
	

----------------------8<----------------------------------------

-- 
Bender, Ship, stop arguing or I'll come back there and change
your opinions manually. - Leela
Rasputin :: Jack of All Trades - Master of Nuns