He hecho un script que te coge datos de monitorización de ldap y te los devuelve en este texto:
[[('cn=Monitor', {})], [('cn=Backends,cn=Monitor', {})], [('cn=Backend 0,cn=Backends,cn=Monitor', {})], [('cn=Backend 1,cn=Backends,cn=Monitor', {})], [('cn=Backend 2,cn=Backends,cn=Monitor', {})], [('cn=Backend 3,cn=Backends,cn=Monitor', {})], [('cn=Backend 4,cn=Backends,cn=Monitor', {})], [('cn=Backend 5,cn=Backends,cn=Monitor', {})], [('cn=Connections,cn=Monitor', {})], [('cn=Connection 1003,cn=Connections,cn=Monitor', {'monitorConnectionRead': ['2'], 'monitorConnectionGet': ['2'], 'monitorConnectionOpsReceived': ['2'], 'monitorConnectionOpsCompleted': ['1'], 'monitorConnectionNumber': ['1003'], 'monitorConnectionWrite': ['0'], 'monitorConnectionOpsExecuting': ['1'], 'monitorConnectionOpsPending': ['0']})], [('cn=Max File Descriptors,cn=Connections,cn=Monitor', {'monitorCounter': ['1024']})], [('cn=Total,cn=Connections,cn=Monitor', {'monitorCounter': ['1004']})], [('cn=Current,cn=Connections,cn=Monitor', {'monitorCounter': ['1']})], [('cn=Databases,cn=Monitor', {})], [('cn=Frontend,cn=Databases,cn=Monitor', {})], [('cn=Database 0,cn=Databases,cn=Monitor', {})], [('cn=Database 1,cn=Databases,cn=Monitor', {})], [('cn=Database 2,cn=Databases,cn=Monitor', {'olmBDBEntryCache': ['0'], 'olmBDBIDLCache': ['0'], 'olmBDBDNCache': ['0']})], [('cn=Listeners,cn=Monitor', {})], [('cn=Listener 0,cn=Listeners,cn=Monitor', {})], [('cn=Listener 1,cn=Listeners,cn=Monitor', {})], [('cn=Listener 2,cn=Listeners,cn=Monitor', {})], [('cn=Log,cn=Monitor', {})], [('cn=Operations,cn=Monitor', {'monitorOpInitiated': ['11'], 'monitorOpCompleted': ['10']})], [('cn=Bind,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['4'], 'monitorOpCompleted': ['4']})], [('cn=Unbind,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['3'], 'monitorOpCompleted': ['3']})], [('cn=Search,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['4'], 'monitorOpCompleted': ['3']})], [('cn=Compare,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Modify,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Modrdn,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Add,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Delete,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Abandon,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Extended,cn=Operations,cn=Monitor', {'monitorOpInitiated': ['0'], 'monitorOpCompleted': ['0']})], [('cn=Overlays,cn=Monitor', {})], [('cn=Overlay 0,cn=Overlays,cn=Monitor', {})], [('cn=SASL,cn=Monitor', {})], [('cn=Statistics,cn=Monitor', {})], [('cn=Bytes,cn=Statistics,cn=Monitor', {'monitorCounter': ['17115']})], [('cn=PDU,cn=Statistics,cn=Monitor', {'monitorCounter': ['229']})], [('cn=Entries,cn=Statistics,cn=Monitor', {'monitorCounter': ['223']})], [('cn=Referrals,cn=Statistics,cn=Monitor', {'monitorCounter': ['0']})], [('cn=Threads,cn=Monitor', {})], [('cn=Max,cn=Threads,cn=Monitor', {})], [('cn=Max Pending,cn=Threads,cn=Monitor', {})], [('cn=Open,cn=Threads,cn=Monitor', {})], [('cn=Starting,cn=Threads,cn=Monitor', {})], [('cn=Active,cn=Threads,cn=Monitor', {})], [('cn=Pending,cn=Threads,cn=Monitor', {})], [('cn=Backload,cn=Threads,cn=Monitor', {})], [('cn=State,cn=Threads,cn=Monitor', {})], [('cn=Runqueue,cn=Threads,cn=Monitor', {})], [('cn=Tasklist,cn=Threads,cn=Monitor', {})], [('cn=Time,cn=Monitor', {})], [('cn=Start,cn=Time,cn=Monitor', {})], [('cn=Current,cn=Time,cn=Monitor', {})], [('cn=Uptime,cn=Time,cn=Monitor', {})], [('cn=TLS,cn=Monitor', {})], [('cn=Waiters,cn=Monitor', {})], [('cn=Read,cn=Waiters,cn=Monitor', {'monitorCounter': ['1']})], [('cn=Write,cn=Waiters,cn=Monitor', {'monitorCounter': ['0']})]]
Como se puede ver en la docu de openldap cogo los datos de monitorizacion de casi todo : https://www.openldap.org/doc/admin25/monitoringslapd.html
Si haces una busqueda personalizada de algun apartado como el de las conexiones por ejemplo (esto me refiero desde el terminal, no en el script) te devuelve esta información de monitoreo :
Total Connections:
dn: cn=Total,cn=Connections,cn=Monitor structuralObjectClass: monitorCounterObject monitorCounter: 4 entryDN: cn=Total,cn=Connections,cn=Monitor subschemaSubentry: cn=Subschema hasSubordinates: FALSE
Ami solo me interesa "dn" como identificativo y "monitorCounter" como valor, por eso hago una busqueda de todo "Monitor" usando esos dos atributos y me devuelve el texto antes mencionado.
Esto lo hago con la biblioteca python-ldap que da bastantes facilidades para esto, despues de autenticarme en el codigo uso este try para recoger los datos y mostrarlos :
try:
ldap_result_id = l.search(basedn, searchScope, searchFilter, searchAttribute)
result_set = []
while 1:
result_type, result_data = l.result(ldap_result_id, 0)
if (result_data == []):
break
else:
## if you are expecting multiple results you can append them
## otherwise you can just wait until the initial result and break out
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
print result_set
Donde :
basedn = "cn=Monitor"
searchFilter = '(objectClass=*)'
searchAttribute = ['dn','monitorCounter']
#this will scope the entire subtree under UserUnits
searchScope = ldap.SCOPE_SUBTREE
Es decir ese texto es el resultado de haber cogido los datos que me interesan y meterlos en result_set[].
Pero ese formato es complejo, y necesito los datos en otro como json o xml para poder cargarlos en un software en el que instalaras este script que estoy haciendo.
Lo ideal seria en el json tenerlos como identificativo : valor, como por ejemplo esto :
[('cn=PDU,cn=Statistics,cn=Monitor', {'monitorCounter': ['229']})], [('cn=Entries,cn=Statistics,cn=Monitor', {'monitorCounter': ['223']})],
donde 'cn=PDU,cn=Statistics,cn=Monitor' sería el identificativo y {'monitorCounter': ['229']} el valor.
es decir lo ideal sería algo asi como : PDUStatics:229
No se si se podría hacer esto o es muy complejo.