Sfoglia il codice sorgente

Added timeout setting for query

Michael Honkoop 3 mesi fa
parent
commit
6b5a6e9fe2

+ 4 - 8
plugins/edirectory_monitor/libexec/agent_edirectory_monitor

@@ -17,7 +17,6 @@ def main():
     if len(args) < 3:
         print("Usage: script.py <LDAP_URI> <BIND_DN> <PASSWORD>")
         sys.exit(1)
-
     ldap_uri = args[0]
     binddn = args[1] 
     pw = args[2]
@@ -25,7 +24,6 @@ def main():
     searchFilter = "(objectClass=*)"
     searchAttribute = ["*"]
     searchScope = ldap.SCOPE_SUBTREE
-
     try:
         # ignore TLS certificate checking
         ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
@@ -36,7 +34,6 @@ def main():
     except ldap.LDAPError as e:
         print(f"Failed to initialize LDAP connection: {e}")
         sys.exit(f"Failed to initialize LDAP connection: {e}")
-
     try:
         # Attempt to bind with given credentials
         l.simple_bind_s(binddn, pw)
@@ -46,18 +43,16 @@ def main():
     except ldap.LDAPError as e:
         print(f"LDAP error during bind: {e}")
         sys.exit(f"LDAP error during bind: {e}")
-
     try:
         ldap_result_id = l.search(basedn, searchScope, searchFilter, searchAttribute)
         result_set = []
 
         while True:
-            result_type, result_data = l.result(ldap_result_id, 0)
+            result_type, result_data = l.result(ldap_result_id, 0, timeout=40)
             if (result_data == []):
                 break
             elif result_type == ldap.RES_SEARCH_ENTRY:
                 result_set.append(result_data)
-
         print('<<<edirectory_monitor_agent:sep(124)>>>')
         for i in range(len(result_set)):
             for val in result_set[i]:
@@ -99,8 +94,9 @@ def main():
         print(f"LDAP search failed: {e}")
         sys.exit(f"LDAP search failed: {e}")
     finally:
-        l.unbind_s()
-
+        if l is not None:
+                l.unbind_s()
+                
 if __name__ == "__main__":
     main()