|
@@ -17,20 +17,40 @@ from cmk_addons.plugins.edirectory_monitor.lib import (
|
|
print_sections,
|
|
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
|
|
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()
|
|
env_verify = os.environ.get("LDAP_VERIFY_TLS", "").lower()
|
|
if env_verify in ("1", "true", "yes"):
|
|
if env_verify in ("1", "true", "yes"):
|
|
verify_tls = True
|
|
verify_tls = True
|
|
|
|
|
|
if len(args) < 3:
|
|
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
|
|
return 1
|
|
|
|
|
|
ldap_uri = args[0]
|
|
ldap_uri = args[0]
|
|
@@ -57,17 +77,34 @@ def main():
|
|
try:
|
|
try:
|
|
# Attempt to bind with given credentials
|
|
# Attempt to bind with given credentials
|
|
l.simple_bind_s(binddn, pw)
|
|
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)>>>')
|
|
print('<<<edirectory_monitor_agent:sep(124)>>>')
|
|
for i in range(len(result_set)):
|
|
for i in range(len(result_set)):
|
|
for val in result_set[i]:
|
|
for val in result_set[i]:
|