Explorar o código

Update 'plugins/edirectory_monitor/agent_based/edirectory_monitor.py'

Michael Honkoop hai 4 meses
pai
achega
01603859f7
Modificáronse 1 ficheiros con 32 adicións e 2 borrados
  1. 32 2
      plugins/edirectory_monitor/agent_based/edirectory_monitor.py

+ 32 - 2
plugins/edirectory_monitor/agent_based/edirectory_monitor.py

@@ -5,6 +5,9 @@
 # License: GNU General Public License v2
 
 from typing import Dict
+from datetime import datetime
+import pytz
+import re
 from cmk.agent_based.v2 import (
     AgentSection,
     CheckPlugin,
@@ -13,8 +16,31 @@ from cmk.agent_based.v2 import (
     Result,
     Service,
     State,
+    Metric,
 )
 
+non_graphable = [
+    "eDirectorySystemCurrTime",
+    "eDirectoryUpTime",
+    "eDirectoryAgentVersion",
+    "CheckPointThreadStartTime",
+    "CheckPointThreadForceStartTime",
+    "CheckPointThreadIsForced",
+]
+
+def format_partition_agent(value):
+    formatted = re.sub('CN=|OU=|O=|T=', '', value).replace("=", " ")
+    return formatted
+
+def convert_timestamp(value):
+    """convert Zulu time to current time in local timezone"""
+    utc_dt = datetime.strptime(value, "%Y%m%d%H%M%SZ")
+    utc = pytz.utc
+    utc_dt = utc.localize(utc_dt)
+    local_tz = pytz.timezone(pytz.timezone('local'))
+    local_dt = utc_dt.astimezone(local_tz)
+    return local_dt
+
 def parse_ldap_data(string_table):
     """parse one lines of data to dictionary"""
     parsed = {}
@@ -23,8 +49,11 @@ def parse_ldap_data(string_table):
         parsed.setdefault(item, {})
         for _count, data in enumerate(line[1:]):
             if item == "Agent Partition":
+                #print(format_partition_agent(data))
                 continue
-            key, value=data.split("=")
+                #key, value=format_partition_agent(data).split("#")
+            else:
+                key, value=data.split("=")
             parsed[item].setdefault(key, value)
     return parsed
 
@@ -41,7 +70,8 @@ def check_edirectory_items(item: str, section) -> CheckResult:
         return
     for key, value in data.items():
         yield Result(state=State(0), summary=f"{key}: {value}", details=f"{key}: {value}")
-
+        if key not in non_graphable:
+            yield Metric(key, float(value))
 
 agent_section_edirectory_monitor = AgentSection(
     name="edirectory_monitor",