Browse Source

Update 'plugins/edirectory_monitor/libexec/agent_edirectory_monitor'

Michael Honkoop 2 months ago
parent
commit
028327f3e2
1 changed files with 2 additions and 66 deletions
  1. 2 66
      plugins/edirectory_monitor/libexec/agent_edirectory_monitor

+ 2 - 66
plugins/edirectory_monitor/libexec/agent_edirectory_monitor

@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-
+'''special agent call file'''
 # -*- mode: Python; encoding: utf-8; indent-offset: 4; autowrap: nil -*-
 
 # (c) Michael Honkoop <mhonkoop@comsolve.nl>
@@ -8,74 +8,10 @@
 
 import sys
 import ldap
-import re
 from cmk_addons.plugins.edirectory_monitor.lib import (
-    format_partition_data,
+    print_sections,
 )
 
-def clean_key(key):
-    """Clean and format the key by removing unwanted parts."""
-    cleaned_key = ' '.join(key.split(',')[::-1]).replace('cn=Monitor', '').replace('cn=', '').strip()
-    return cleaned_key
-
-def clean_value(value):
-    """Clean and format the values by removing unwanted parts."""
-    cleaned_value = re.sub(' Bytes| KB| MB| ms', '', value)
-    return cleaned_value
-
-def print_sections(raw_result):
-    separator = 124 # '|';
-    lines = []
-    def process_item(item):
-        """Process an individual item in the raw result."""
-        if isinstance(item, list):
-            for sub_item in item:
-                process_item(sub_item)
-        elif isinstance(item, dict):
-            for key, value in item.items():
-                if isinstance(value, list):
-                    value_str = chr(separator).join(value)  # Preserve list information by joining elements
-                else:
-                    value_str = value
-                lines.append(f"{key}={value_str}")
-        else:
-            if "BackGroundProcInterval" not in str(item):  # Skip irrelevant sections
-                lines.append(str(item))
-    
-    for each_item in raw_result:
-        if isinstance(each_item, list):
-            print_sections(each_item)  # Recursive call for nested lists
-        elif isinstance(each_item, tuple) and len(each_item) == 2:
-            dn, attributes = each_item
-            if "BackGroundProcInterval" in dn:
-                continue  # Skip irrelevant DNs
-            lines.append(clean_key(dn))
-            for key, value in attributes.items():
-                if key == "objectclass":
-                    continue  # Skip objectclass attribute
-                if isinstance(value, list):  # Handle list values
-                    for item in value:
-                        try:
-                            decoded_value = item.decode("utf-8")
-                            if len(decoded_value) != 0:
-                                lines.append(f"{key}={clean_value(decoded_value)}")
-                        except AttributeError:
-                            if len(item) != 0:
-                                lines.append(f"{key}={clean_value(item)}")
-                else:  # Handle scalar values
-                    try:
-                        decoded_value = value.decode("utf-8")
-                        if len(decoded_value) != 0:
-                            lines.append(f"{key}={clean_value(decoded_value)}")
-                    except AttributeError:
-                        if len(item) != 0:
-                            lines.append(f"{key}={clean_value(value)}")
-        else:
-            process_item(each_item)
-    
-    if lines:
-        print(chr(separator).join(lines))
-
 def main():
     args = sys.argv[1:]
     if len(args) < 3: