/plugin/default/ldap_stats.pm
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
- package ldap_stats;
- use Net::LDAP;
- sub getMonitorDesc {
- my($ldap,
- $dn,
- $attr,
- $statname,
- $stattype) = @_;
- my(@reply,
- $searchResults,
- $entry);
- if (!$attr) {
- $attr = "description";
- }
- $searchResults = $ldap->search(base => "$dn",
- scope => 'base',
- filter => 'objectClass=*',
- attrs => ["$attr"],);
- $entry = $searchResults->pop_entry() if $searchResults->count() == 1;
- push(@reply, "Start $statname");
- push(@reply, "$stattype: " . $entry->get_value("$attr"));
- push(@reply, "End $statname");
- return(@reply);
- }
- sub plugin_main {
- my($self,
- %hash) = @_;
- my(@reply,
- $ldap);
- my $ldap = new Net::LDAP($hash{'ip'}, port=> $hash{'port'}) or die "Failed to create socket to $hash{'ip'}:$hash{'port'}: Perl error: $@";
- $ldap->bind("base" => "",
- "version" => 3) or die "Failed to bind to LDAP server: Perl error: $@";
- push(@reply, getMonitorDesc($ldap, "cn=Total,cn=Connections,cn=Monitor", "monitorCounter", "total_connections", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Bytes,cn=Statistics,cn=Monitor", "monitorCounter", "bytes_sent", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Operations,cn=Monitor", "monitorOpCompleted", "completed_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Operations,cn=Monitor", "monitorOpInitiated", "initiated_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Referrals,cn=Statistics,cn=Monitor", "monitorCounter", "referrals_sent", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Entries,cn=Statistics,cn=Monitor", "monitorCounter", "entries_sent", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Bind,cn=Operations,cn=Monitor", "monitorOpCompleted", "bind_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Unbind,cn=Operations,cn=Monitor", "monitorOpCompleted", "bind_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Add,cn=Operations,cn=Monitor", "monitorOpInitiated", "add_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Delete,cn=Operations,cn=Monitor", "monitorOpCompleted", "delete_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Modify,cn=Operations,cn=Monitor", "monitorOpCompleted", "modify_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Compare,cn=Operations,cn=Monitor", "monitorOpCompleted", "compare_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Search,cn=Operations,cn=Monitor", "monitorOpCompleted", "search_operations", 'Counter'));
- push(@reply, getMonitorDesc($ldap, "cn=Write,cn=Waiters,cn=Monitor", "monitorCounter", "write_waiters", 'Gauge'));
- push(@reply, getMonitorDesc($ldap, "cn=Read,cn=Waiters,cn=Monitor", "monitorCounter", "read_waiters", 'Gauge'));
- return(\@reply, 2);
- }
- 1