浏览代码

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

Michael Honkoop 2 月之前
父节点
当前提交
57cb971475
共有 1 个文件被更改,包括 16 次插入10 次删除
  1. 16 10
      plugins/edirectory_monitor/agent_based/edirectory_monitor.py

+ 16 - 10
plugins/edirectory_monitor/agent_based/edirectory_monitor.py

@@ -6,7 +6,6 @@
 
 # License: GNU General Public License v2
 
-from typing import Dict
 import datetime
 
 from cmk.agent_based.v2 import (
@@ -21,18 +20,20 @@ from cmk.agent_based.v2 import (
 
 from cmk_addons.plugins.edirectory_monitor.lib import (
     convert_timestamp,
+    discover_edirectory_items,    
     parse_ldap_data,
-    discover_edirectory_items,
+    ignored_items,
     uptime_attributes,
     time_attributes,
     time_attributes_ignored,
     non_graphable_attributes,
     total_counter_attributes,
+    idm_nongraphable_attributes,
 )
 
 def check_edirectory_items(item: str, section) -> CheckResult:
     value_store = get_value_store()
-    '''Split the item key and store the last part'''
+    '''Split the item key and store the last part for making the returned result and/or metric more unique'''
     item_detail = item.split()[-1]
     data = section.get(item)
     if not data:
@@ -41,26 +42,31 @@ def check_edirectory_items(item: str, section) -> CheckResult:
         if (item_detail + "_" + key) in time_attributes_ignored:
             '''do not iternate keys which only hold a timestamp'''
             continue
+        elif key in ignored_items:
+            '''do not iternate keys which hold unwanted data'''
+            continue
         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"{item_detail}_{key}: {uptime}", details=f"{key}: {uptime}")
+            uptime = datetime.timedelta(seconds=int(value))
+            yield Result(state=State(0), summary=f"{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"{item_detail}_{key}: {datevalue}", details=f"{key}: {datevalue}")
+            yield Result(state=State(0), summary=f"{key}: {datevalue}", details=f"{key}: {datevalue}")
         else:
-            '''create a default result if above does not apply'''
-            yield Result(state=State(0), summary=f"{item_detail}_{key}: {value}", details=f"{key}: {value}")
+            '''create a default result if above criteria do not apply'''
+            yield Result(state=State(0), summary=f"{key}: {value}", details=f"{key}: {value}")
         if (item_detail + "_" + key) in total_counter_attributes:
             '''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
-            value_difference = float(value) - float(previous_value)
+            value_difference = int(value) - int(previous_value)
             yield Metric((item_detail + "_" + key), abs(value_difference), boundaries=(0, None))
+        elif item.startswith("IDM") and key in idm_nongraphable_attributes:
+            continue
         elif (item_detail + "_" + key) not in non_graphable_attributes:
             '''Only create a metric for graphable values'''
-            yield Metric((item_detail + "_" + key), float(value))
+            yield Metric((item_detail + "_" + key), abs(int(value)))
 
 agent_section_edirectory_monitor = AgentSection(
     name="edirectory_monitor",