|
@@ -16,26 +16,53 @@ def clean_value(value):
|
|
|
return cleaned_value
|
|
|
|
|
|
def print_sections(raw_result):
|
|
|
- separator = 124 # '|'; for more fun use separator=7 (which is a bell)
|
|
|
+ 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)
|
|
|
+ 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")
|
|
|
+ lines.append(f"{key}={clean_value(decoded_value)}")
|
|
|
+ except AttributeError:
|
|
|
+ lines.append(f"{key}={clean_value(item)}")
|
|
|
+ else: # Handle scalar values
|
|
|
+ try:
|
|
|
+ decoded_value = value.decode("utf-8")
|
|
|
+ lines.append(f"{key}={clean_value(decoded_value)}")
|
|
|
+ except AttributeError:
|
|
|
+ lines.append(f"{key}={clean_value(value)}")
|
|
|
else:
|
|
|
- if "BackGroundProcInterval" in each_item[0]:
|
|
|
- continue
|
|
|
- lines.append(clean_key(each_item[0]))
|
|
|
- for k,v in each_item[1].items():
|
|
|
- if k == "objectclass":
|
|
|
- continue
|
|
|
- decoded_value = v[0].decode("utf-8")
|
|
|
- if "CheckPointThreadForceStartTime" in k or "CheckPointThreadStartTime" in k:
|
|
|
- continue
|
|
|
- lines.append(chr(separator).join(['{}={}'.format(k,clean_value(decoded_value))]))
|
|
|
-
|
|
|
+ process_item(each_item)
|
|
|
+
|
|
|
if lines:
|
|
|
-# print('<<<edirectory_monitor:sep({})>>>'.format(separator))
|
|
|
- print('|'.join(lines))
|
|
|
+ print(chr(separator).join(lines))
|
|
|
|
|
|
def main():
|
|
|
args = sys.argv[1:]
|
|
@@ -83,10 +110,13 @@ def main():
|
|
|
elif result_type == ldap.RES_SEARCH_ENTRY:
|
|
|
result_set.append(result_data)
|
|
|
|
|
|
-# for i in range(len(result_set)):
|
|
|
print('<<<edirectory_monitor:sep(124)>>>')
|
|
|
-# print_sections(result_set[i])
|
|
|
- print_sections(result_set)
|
|
|
+ for i in range(len(result_set)):
|
|
|
+ print_sections(result_set[i])
|
|
|
+
|
|
|
+ #parse_data(result_set)
|
|
|
+ #print_sections(result_set)
|
|
|
+
|
|
|
|
|
|
|
|
|
except ldap.LDAPError as e:
|