lib.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/usr/bin/env python3
  2. '''functions used by multiple parts of the plugin'''
  3. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  4. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  5. # License: GNU General Public License v2
  6. import re
  7. import pytz
  8. import datetime
  9. from dateutil import tz
  10. from cmk.agent_based.v2 import (
  11. DiscoveryResult,
  12. Service,
  13. )
  14. ignored_items = [
  15. "IDM jvm_stats",
  16. ]
  17. uptime_attributes = [
  18. "Status_eDirectoryUpTime",
  19. ]
  20. time_attributes = [
  21. "Status_eDirectorySystemCurrTime",
  22. "CheckPointThreadData_CheckPointThreadStartTime",
  23. ]
  24. time_attributes_ignored = [
  25. "BackGroundProcInterval",
  26. "CheckPointThreadData_CheckPointThreadForceStartTime",
  27. "CheckPointThreadData_CheckPointThreadStartTime",
  28. ]
  29. non_graphable_attributes = [
  30. "Status_eDirectorySystemCurrTime",
  31. "Status_eDirectoryUpTime",
  32. "Status_eDirectoryAgentVersion",
  33. "CheckPointThreadData_CheckPointThreadStartTime",
  34. "CheckPointThreadData_CheckPointThreadForceStartTime",
  35. "CheckPointThreadData_CheckPointThreadIsForced",
  36. "Size_CurrentTransactionID",
  37. "EngineVersion_EngineVersion",
  38. "driverSet_Stats_driverSetDN",
  39. "Driver_startOption",
  40. "Driver_type",
  41. "Driver_uptime",
  42. "Driver_driver-state",
  43. "Driver_DriverDN",
  44. "Finalizer_lock",
  45. "Finalizer_state",
  46. "Dispatcher_state",
  47. "DirXML_state",
  48. "Scheduler_lock",
  49. "Scheduler_state",
  50. "Scheduler_Id",
  51. "Handler_lock",
  52. "Handler_state",
  53. "IDM jvm_stats",
  54. "IDM job_stats",
  55. "system_properties",
  56. ]
  57. idm_nongraphable_attributes = [
  58. "arch",
  59. "average_load",
  60. "comitted",
  61. "configuration",
  62. "containment",
  63. "downTime",
  64. "DriverDN",
  65. "driver-state",
  66. "id",
  67. "initial",
  68. "JobDN",
  69. "lock",
  70. "name",
  71. "processors",
  72. "startOption",
  73. "state",
  74. "status",
  75. "total",
  76. "type",
  77. "uptime",
  78. "upTime",
  79. "used",
  80. "version",
  81. ]
  82. total_counter_attributes = [
  83. "TrafficVolume_inBytes",
  84. "TrafficVolume_outBytes",
  85. "Errors_securityErrors",
  86. "Errors_errors",
  87. "Bindings_simpleAuthBinds",
  88. "Bindings_unAuthBinds",
  89. "Bindings_bindSecurityErrors",
  90. "Bindings_strongAuthBinds",
  91. "IncomingOperations_extendedOps",
  92. "IncomingOperations_abandonOps",
  93. "IncomingOperations_wholeSubtreeSearchOps",
  94. "IncomingOperations_oneLevelSearchOps",
  95. "IncomingOperations_searchOps",
  96. "IncomingOperations_listOps",
  97. "IncomingOperations_modifyRDNOps",
  98. "IncomingOperations_modifyEntryOps",
  99. "IncomingOperations_removeEntryOps",
  100. "IncomingOperations_addEntryOps",
  101. "IncomingOperations_compareOps",
  102. "IncomingOperations_readOps",
  103. "IncomingOperations_inOps",
  104. "OutgoingOperations_chainings",
  105. "CacheFaultLooks_Total",
  106. "CacheFaultLooks_BlockCache",
  107. "CacheFaultLooks_EntryCache",
  108. "Hits_Total",
  109. "Hits_BlockCache",
  110. "Hits_EntryCache",
  111. "HitLooks_Total",
  112. "HitLooks_BlockCache",
  113. "HitLooks_EntryCache",
  114. "Thread_Stats_Total_Shared_Count",
  115. ]
  116. def format_partition_agent(value):
  117. """strip unwanted data from Agent Partition data"""
  118. formatted = re.sub('CN=|OU=|O=|T=', '', value).replace("=", " ").replace(" ", "").split("#")
  119. return formatted
  120. def format_partition_data(value):
  121. """strip unwanted data from Agent Partition data"""
  122. formatted = (re.sub('CN=|OU=|O=', '', value).replace(',', '.')).split("=")
  123. return formatted
  124. def convert_timestamp(value):
  125. """convert Zulu time to current time in local timezone"""
  126. utc_dt = datetime.datetime.strptime(str(value), "%Y%m%d%H%M%SZ")
  127. utc = pytz.utc
  128. utc_dt = utc_dt.replace(tzinfo=tz.UTC)
  129. local_tz = tz.tzlocal()
  130. local_dt = utc_dt.astimezone(local_tz)
  131. return local_dt
  132. def parse_ldap_data(string_table):
  133. """parse one lines of data to dictionary"""
  134. parsed = {}
  135. for line in string_table:
  136. item = line[0]
  137. parsed.setdefault(item, {})
  138. for _count, data in enumerate(line[1:]):
  139. if item == "Agent Partition":
  140. key, value=format_partition_agent(data)
  141. else:
  142. key, value=format_partition_data(data)
  143. parsed[item].setdefault(key, value)
  144. return parsed
  145. def discover_edirectory_items(section) -> DiscoveryResult:
  146. '''discover one item per key'''
  147. for key, data in section.items():
  148. '''Yield a Service, unless the key is empty'''
  149. if len(key) != 0:
  150. if not key.startswith("IDM jvm_stats"):
  151. print(key)
  152. yield Service(item=key)