|
@@ -0,0 +1,103 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+'''functions used by multiple parts of the plugin'''
|
|
|
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
|
|
|
+
|
|
|
+# (c) Michael Honkoop <mhonkoop@comsolve.nl>
|
|
|
+
|
|
|
+# License: GNU General Public License v2
|
|
|
+
|
|
|
+import re
|
|
|
+import pytz
|
|
|
+import datetime
|
|
|
+import time
|
|
|
+from dateutil import tz
|
|
|
+
|
|
|
+from cmk.agent_based.v2 import (
|
|
|
+ get_rate,
|
|
|
+ GetRateError,
|
|
|
+ DiscoveryResult,
|
|
|
+ Service,
|
|
|
+)
|
|
|
+
|
|
|
+uptime_attributes = [
|
|
|
+ "Status_eDirectoryUpTime",
|
|
|
+]
|
|
|
+
|
|
|
+time_attributes = [
|
|
|
+ "Status_eDirectorySystemCurrTime",
|
|
|
+ "CheckPointThreadData_CheckPointThreadStartTime",
|
|
|
+]
|
|
|
+
|
|
|
+time_attributes_ignored = [
|
|
|
+ "BackGroundProcInterval",
|
|
|
+ "CheckPointThreadData_CheckPointThreadForceStartTime",
|
|
|
+ "CheckPointThreadData_CheckPointThreadStartTime",
|
|
|
+]
|
|
|
+
|
|
|
+non_graphable = [
|
|
|
+ "Status_eDirectorySystemCurrTime",
|
|
|
+ "Status_eDirectoryUpTime",
|
|
|
+ "Status_eDirectoryAgentVersion",
|
|
|
+ "CheckPointThreadData_CheckPointThreadStartTime",
|
|
|
+ "CheckPointThreadData_CheckPointThreadForceStartTime",
|
|
|
+ "CheckPointThreadData_CheckPointThreadIsForced",
|
|
|
+ "Size_CurrentTransactionID",
|
|
|
+]
|
|
|
+
|
|
|
+total_counters = [
|
|
|
+ "Trafficvolume_inBytes",
|
|
|
+ "Trafficvolume_outBytes",
|
|
|
+ "Errors_securityErrors",
|
|
|
+ "Errors_errors",
|
|
|
+ "Bindings_simpleAuthBinds",
|
|
|
+ "Bindings_unAuthBinds",
|
|
|
+ "Bindings_bindSecurityErrors",
|
|
|
+ "Bindings_strongAuthBinds",
|
|
|
+ "IncomingOperations_extendedOps",
|
|
|
+ "IncomingOperations_abandonOps",
|
|
|
+ "IncomingOperations_wholeSubtreeSearchOps",
|
|
|
+ "IncomingOperations_oneLevelSearchOps",
|
|
|
+ "IncomingOperations_searchOps",
|
|
|
+ "IncomingOperations_listOps",
|
|
|
+ "IncomingOperations_modifyRDNOps",
|
|
|
+ "IncomingOperations_modifyEntryOps",
|
|
|
+ "IncomingOperations_removeEntryOps",
|
|
|
+ "IncomingOperations_addEntryOps",
|
|
|
+ "IncomingOperations_compareOps",
|
|
|
+ "IncomingOperations_readOps",
|
|
|
+ "IncomingOperations_inOps",
|
|
|
+ "OutgoingOperations_chainings",
|
|
|
+]
|
|
|
+
|
|
|
+def format_partition_agent(value):
|
|
|
+ """strip unwanted data from Agent Partition data"""
|
|
|
+ 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)
|