|
@@ -2,122 +2,67 @@
|
|
|
|
|
|
# -*- encoding: utf-8; py-indent-offset: 4 -*-
|
|
|
|
|
|
+# (c) Michael Honkoop <mhonkoop@comsolve.nl>
|
|
|
+
|
|
|
# License: GNU General Public License v2
|
|
|
|
|
|
from typing import Dict
|
|
|
import datetime
|
|
|
-import pytz
|
|
|
-import time
|
|
|
-from dateutil import tz
|
|
|
-import re
|
|
|
+
|
|
|
from cmk.agent_based.v2 import (
|
|
|
AgentSection,
|
|
|
CheckPlugin,
|
|
|
CheckResult,
|
|
|
- DiscoveryResult,
|
|
|
Result,
|
|
|
- Service,
|
|
|
State,
|
|
|
Metric,
|
|
|
get_rate,
|
|
|
get_value_store,
|
|
|
- GetRateError,
|
|
|
)
|
|
|
|
|
|
-non_graphable = [
|
|
|
- "eDirectorySystemCurrTime",
|
|
|
- "eDirectoryUpTime",
|
|
|
- "eDirectoryAgentVersion",
|
|
|
- "CheckPointThreadStartTime",
|
|
|
- "CheckPointThreadForceStartTime",
|
|
|
- "CheckPointThreadIsForced",
|
|
|
-]
|
|
|
-
|
|
|
-uptime_attributes = [
|
|
|
- "eDirectoryUpTime",
|
|
|
-]
|
|
|
-
|
|
|
-time_attributes_ignored = [
|
|
|
- "BackGroundProcInterval",
|
|
|
- "CheckPointThreadForceStartTime",
|
|
|
- "CheckPointThreadStartTime",
|
|
|
-]
|
|
|
-
|
|
|
-time_attributes = [
|
|
|
- "eDirectorySystemCurrTime",
|
|
|
- "CheckPointThreadStartTime",
|
|
|
-]
|
|
|
-
|
|
|
-total_counters = [
|
|
|
- "inBytes",
|
|
|
- "outBytes",
|
|
|
- "Total",
|
|
|
- "EntryCache",
|
|
|
- "BlockCache",
|
|
|
- "TotalSize",
|
|
|
-]
|
|
|
-
|
|
|
-def format_partition_agent(value):
|
|
|
- formatted = re.sub('CN=|OU=|O=|T=', '', value).replace("=", " ").replace(" ", "").split("#")
|
|
|
- return formatted
|
|
|
-
|
|
|
-def convert_timestamp(value):
|
|
|
- """convert Zulu time to current time in local timezone"""
|
|
|
- utc_dt = datetime.datetime.strptime(str(value), "%Y%m%d%H%M%SZ")
|
|
|
- utc = pytz.utc
|
|
|
- utc_dt = utc_dt.replace(tzinfo=tz.UTC)
|
|
|
- local_tz = tz.tzlocal()
|
|
|
- local_dt = utc_dt.astimezone(local_tz)
|
|
|
- return local_dt
|
|
|
-
|
|
|
-def parse_ldap_data(string_table):
|
|
|
- """parse one lines of data to dictionary"""
|
|
|
- parsed = {}
|
|
|
- for line in string_table:
|
|
|
- item = line[0]
|
|
|
- parsed.setdefault(item, {})
|
|
|
- for _count, data in enumerate(line[1:]):
|
|
|
- if item == "Agent Partition":
|
|
|
- key, value=format_partition_agent(data)
|
|
|
- else:
|
|
|
- key, value=data.split("=")
|
|
|
- parsed[item].setdefault(key, value)
|
|
|
- return parsed
|
|
|
-
|
|
|
-def discover_edirectory_items(section) -> DiscoveryResult:
|
|
|
- '''discover one item per key'''
|
|
|
- for key, data in section.items():
|
|
|
- yield Service(item=key)
|
|
|
+from cmk_addons.plugins.edirectory_monitor.lib import (
|
|
|
+ format_partition_agent,
|
|
|
+ convert_timestamp,
|
|
|
+ parse_ldap_data,
|
|
|
+ discover_edirectory_items,
|
|
|
+ uptime_attributes,
|
|
|
+ time_attributes,
|
|
|
+ time_attributes_ignored,
|
|
|
+ non_graphable,
|
|
|
+ total_counters,
|
|
|
+)
|
|
|
|
|
|
def check_edirectory_items(item: str, section) -> CheckResult:
|
|
|
value_store = get_value_store()
|
|
|
+ '''Split the item key and store the last part'''
|
|
|
+ item_detail = item.split()[-1]
|
|
|
data = section.get(item)
|
|
|
if not data:
|
|
|
return
|
|
|
for key, value in data.items():
|
|
|
- if key in time_attributes_ignored:
|
|
|
+ if (item_detail + "_" + key) in time_attributes_ignored:
|
|
|
'''do not iternate keys which only hold a timestamp'''
|
|
|
continue
|
|
|
- elif key in uptime_attributes:
|
|
|
+ elif (item_detail + "_" + key) in uptime_attributes:
|
|
|
'''create readable notation of uptime attributes from seconds'''
|
|
|
uptime = datetime.timedelta(seconds=float(value))
|
|
|
- yield Result(state=State(0), summary=f"{key}: {uptime}", details=f"{key}: {uptime}")
|
|
|
- elif key in time_attributes:
|
|
|
+ yield Result(state=State(0), summary=f"{item_detail}_{key}: {uptime}", details=f"{key}: {uptime}")
|
|
|
+ elif (item_detail + "_" + key) in time_attributes:
|
|
|
'''if a timestamp attribute is not ignored, convert it to local time in (human) readable format'''
|
|
|
datevalue = convert_timestamp(value)
|
|
|
- yield Result(state=State(0), summary=f"{key}: {datevalue}", details=f"{key}: {datevalue}")
|
|
|
+ yield Result(state=State(0), summary=f"{item_detail}_{key}: {datevalue}", details=f"{key}: {datevalue}")
|
|
|
else:
|
|
|
'''create a default result if above does not apply'''
|
|
|
- yield Result(state=State(0), summary=f"{key}: {value}", details=f"{key}: {value}")
|
|
|
- if key in total_counters:
|
|
|
+ yield Result(state=State(0), summary=f"{item_detail}_{key}: {value}", details=f"{key}: {value}")
|
|
|
+ if (item_detail + "_" + key) in total_counters:
|
|
|
'''create a metric which is the difference between previous check value and current check value'''
|
|
|
- previous_value = value_store.get(key, 0)
|
|
|
- value_store[key] = value
|
|
|
+ previous_value = value_store.get((item_detail + "_" + key), 0)
|
|
|
+ value_store[(item_detail + "_" + key)] = value
|
|
|
value_difference = float(value) - float(previous_value)
|
|
|
- yield Metric(key, abs(value_difference), boundaries=(0, None))
|
|
|
- elif key not in non_graphable:
|
|
|
+ yield Metric((item_detail + "_" + key), abs(value_difference), boundaries=(0, None))
|
|
|
+ elif (item_detail + "_" + key) not in non_graphable:
|
|
|
'''Only create a metric for graphable values'''
|
|
|
- yield Metric(key, float(value))
|
|
|
+ yield Metric((item_detail + "_" + key), float(value))
|
|
|
|
|
|
agent_section_edirectory_monitor = AgentSection(
|
|
|
name="edirectory_monitor",
|