PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin/default/ldap_stats.pm

http://epicnms.googlecode.com/
Perl | 68 lines | 50 code | 18 blank | 0 comment | 3 complexity | 83bbf864830e6f97e5e736f439c50324 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, AGPL-1.0, GPL-2.0
  1. package ldap_stats;
  2. use Net::LDAP;
  3. sub getMonitorDesc {
  4. my($ldap,
  5. $dn,
  6. $attr,
  7. $statname,
  8. $stattype) = @_;
  9. my(@reply,
  10. $searchResults,
  11. $entry);
  12. if (!$attr) {
  13. $attr = "description";
  14. }
  15. $searchResults = $ldap->search(base => "$dn",
  16. scope => 'base',
  17. filter => 'objectClass=*',
  18. attrs => ["$attr"],);
  19. $entry = $searchResults->pop_entry() if $searchResults->count() == 1;
  20. push(@reply, "Start $statname");
  21. push(@reply, "$stattype: " . $entry->get_value("$attr"));
  22. push(@reply, "End $statname");
  23. return(@reply);
  24. }
  25. sub plugin_main {
  26. my($self,
  27. %hash) = @_;
  28. my(@reply,
  29. $ldap);
  30. my $ldap = new Net::LDAP($hash{'ip'}, port=> $hash{'port'}) or die "Failed to create socket to $hash{'ip'}:$hash{'port'}: Perl error: $@";
  31. $ldap->bind("base" => "",
  32. "version" => 3) or die "Failed to bind to LDAP server: Perl error: $@";
  33. push(@reply, getMonitorDesc($ldap, "cn=Total,cn=Connections,cn=Monitor", "monitorCounter", "total_connections", 'Counter'));
  34. push(@reply, getMonitorDesc($ldap, "cn=Bytes,cn=Statistics,cn=Monitor", "monitorCounter", "bytes_sent", 'Counter'));
  35. push(@reply, getMonitorDesc($ldap, "cn=Operations,cn=Monitor", "monitorOpCompleted", "completed_operations", 'Counter'));
  36. push(@reply, getMonitorDesc($ldap, "cn=Operations,cn=Monitor", "monitorOpInitiated", "initiated_operations", 'Counter'));
  37. push(@reply, getMonitorDesc($ldap, "cn=Referrals,cn=Statistics,cn=Monitor", "monitorCounter", "referrals_sent", 'Counter'));
  38. push(@reply, getMonitorDesc($ldap, "cn=Entries,cn=Statistics,cn=Monitor", "monitorCounter", "entries_sent", 'Counter'));
  39. push(@reply, getMonitorDesc($ldap, "cn=Bind,cn=Operations,cn=Monitor", "monitorOpCompleted", "bind_operations", 'Counter'));
  40. push(@reply, getMonitorDesc($ldap, "cn=Unbind,cn=Operations,cn=Monitor", "monitorOpCompleted", "bind_operations", 'Counter'));
  41. push(@reply, getMonitorDesc($ldap, "cn=Add,cn=Operations,cn=Monitor", "monitorOpInitiated", "add_operations", 'Counter'));
  42. push(@reply, getMonitorDesc($ldap, "cn=Delete,cn=Operations,cn=Monitor", "monitorOpCompleted", "delete_operations", 'Counter'));
  43. push(@reply, getMonitorDesc($ldap, "cn=Modify,cn=Operations,cn=Monitor", "monitorOpCompleted", "modify_operations", 'Counter'));
  44. push(@reply, getMonitorDesc($ldap, "cn=Compare,cn=Operations,cn=Monitor", "monitorOpCompleted", "compare_operations", 'Counter'));
  45. push(@reply, getMonitorDesc($ldap, "cn=Search,cn=Operations,cn=Monitor", "monitorOpCompleted", "search_operations", 'Counter'));
  46. push(@reply, getMonitorDesc($ldap, "cn=Write,cn=Waiters,cn=Monitor", "monitorCounter", "write_waiters", 'Gauge'));
  47. push(@reply, getMonitorDesc($ldap, "cn=Read,cn=Waiters,cn=Monitor", "monitorCounter", "read_waiters", 'Gauge'));
  48. return(\@reply, 2);
  49. }
  50. 1