瀏覽代碼

Added exclusion option for sections

Michael Honkoop 2 月之前
父節點
當前提交
f9f48bdef5
共有 1 個文件被更改,包括 54 次插入17 次删除
  1. 54 17
      plugins/edirectory_monitor/libexec/agent_edirectory_monitor

+ 54 - 17
plugins/edirectory_monitor/libexec/agent_edirectory_monitor

@@ -17,20 +17,40 @@ from cmk_addons.plugins.edirectory_monitor.lib import (
     print_sections,
 )
 
-def main():
-    args = sys.argv[1:]
+# possible subsections of cn=Monitor
+monitor_sections = [
+    "Agent",
+    "Dclient",
+    "DHOST",
+    "LDAP",
+    "RecordManager",
+    "IDM",
+]
 
+def main():
     verify_tls = False
-    if "--verify_tls" in args:
-        verify_tls = True
-        args.remove("--verify_tls")
+    exclude_sections = []
+    for args in sys.argv[1:]:  # Skip the script name (sys.argv[0])
+        if args.startswith("--exclude="):
+            # Extract the part after "--exclude "
+            exclude_params = args.split("=", 1)[1]            
+            # Split the value by commas, strip whitespace, and ignore empty parts
+            exclude_sections = exclude_params.split(",")
+            #print(exclude_sections)
+        else:
+            exclude_sections = None
+
+        if "--verify-tls" in args:
+            verify_tls = True
+
+    args = sys.argv[1:]
 
     env_verify = os.environ.get("LDAP_VERIFY_TLS", "").lower()
     if env_verify in ("1", "true", "yes"):
         verify_tls = True
 
     if len(args) < 3:
-        print("Usage: script.py [--verify_tls] <LDAP_URI> <BIND_DN> <PASSWORD>")
+        print("Usage: script.py [--verify-tls] [--exclude=<section(s)>] <LDAP_URI> <BIND_DN> <PASSWORD>")
         return 1
     
     ldap_uri = args[0]
@@ -57,17 +77,34 @@ def main():
         try:
             # Attempt to bind with given credentials
             l.simple_bind_s(binddn, pw)
-
-            ldap_result_id = l.search(basedn, searchScope, searchFilter, searchAttribute)
-            result_set = []
-
-            while True:
-                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)
-
+            
+            if exclude_sections is None:
+                ldap_result_id = l.search(basedn, searchScope, searchFilter, searchAttribute)
+
+                result_set = []
+
+                while True:
+                    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)
+            else:
+                result_set = []
+
+                for entry in monitor_sections:
+                    if entry.lower() in exclude_sections:
+                        continue
+                    else:
+                        ldap_result_id = l.search("cn=" + entry + "," + basedn, searchScope, searchFilter, searchAttribute)
+
+                        while True:
+                            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]: