1
0

lib.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. uptime_attributes = [
  15. "Status_eDirectoryUpTime",
  16. ]
  17. time_attributes = [
  18. "Status_eDirectorySystemCurrTime",
  19. "CheckPointThreadData_CheckPointThreadStartTime",
  20. ]
  21. time_attributes_ignored = [
  22. "BackGroundProcInterval",
  23. "CheckPointThreadData_CheckPointThreadForceStartTime",
  24. "CheckPointThreadData_CheckPointThreadStartTime",
  25. ]
  26. non_graphable_attributes = [
  27. "Status_eDirectorySystemCurrTime",
  28. "Status_eDirectoryUpTime",
  29. "Status_eDirectoryAgentVersion",
  30. "CheckPointThreadData_CheckPointThreadStartTime",
  31. "CheckPointThreadData_CheckPointThreadForceStartTime",
  32. "CheckPointThreadData_CheckPointThreadIsForced",
  33. "Size_CurrentTransactionID",
  34. "EngineVersion_EngineVersion",
  35. "driverSet_Stats_driverSetDN",
  36. "Driver_startOption",
  37. "Driver_type",
  38. "Driver_uptime",
  39. "Driver_driver-state",
  40. "Driver_DriverDN",
  41. "Finalizer_lock",
  42. "Finalizer_state",
  43. "Dispatcher_state",
  44. "DirXML_state",
  45. "Scheduler_lock",
  46. "Scheduler_state",
  47. "Scheduler_Id",
  48. "Handler_lock",
  49. "Handler_state",
  50. ]
  51. total_counter_attributes = [
  52. "TrafficVolume_inBytes",
  53. "TrafficVolume_outBytes",
  54. "Errors_securityErrors",
  55. "Errors_errors",
  56. "Bindings_simpleAuthBinds",
  57. "Bindings_unAuthBinds",
  58. "Bindings_bindSecurityErrors",
  59. "Bindings_strongAuthBinds",
  60. "IncomingOperations_extendedOps",
  61. "IncomingOperations_abandonOps",
  62. "IncomingOperations_wholeSubtreeSearchOps",
  63. "IncomingOperations_oneLevelSearchOps",
  64. "IncomingOperations_searchOps",
  65. "IncomingOperations_listOps",
  66. "IncomingOperations_modifyRDNOps",
  67. "IncomingOperations_modifyEntryOps",
  68. "IncomingOperations_removeEntryOps",
  69. "IncomingOperations_addEntryOps",
  70. "IncomingOperations_compareOps",
  71. "IncomingOperations_readOps",
  72. "IncomingOperations_inOps",
  73. "OutgoingOperations_chainings",
  74. "CacheFaultLooks_Total",
  75. "CacheFaultLooks_BlockCache",
  76. "CacheFaultLooks_EntryCache",
  77. "Hits_Total",
  78. "Hits_BlockCache",
  79. "Hits_EntryCache",
  80. "HitLooks_Total",
  81. "HitLooks_BlockCache",
  82. "HitLooks_EntryCache",
  83. ]
  84. def format_partition_agent(value):
  85. """strip unwanted data from Agent Partition data"""
  86. formatted = re.sub('CN=|OU=|O=|T=', '', value).replace("=", " ").replace(" ", "").split("#")
  87. return formatted
  88. def format_partition_data(value):
  89. """strip unwanted data from Agent Partition data"""
  90. formatted = (re.sub('CN=|OU=|O=', '', value).replace(',', '.')).split("=")
  91. return formatted
  92. def convert_timestamp(value):
  93. """convert Zulu time to current time in local timezone"""
  94. utc_dt = datetime.datetime.strptime(str(value), "%Y%m%d%H%M%SZ")
  95. utc = pytz.utc
  96. utc_dt = utc_dt.replace(tzinfo=tz.UTC)
  97. local_tz = tz.tzlocal()
  98. local_dt = utc_dt.astimezone(local_tz)
  99. return local_dt
  100. def parse_ldap_data(string_table):
  101. """parse one lines of data to dictionary"""
  102. parsed = {}
  103. for line in string_table:
  104. item = line[0]
  105. parsed.setdefault(item, {})
  106. for _count, data in enumerate(line[1:]):
  107. if item == "Agent Partition":
  108. key, value=format_partition_agent(data)
  109. else:
  110. key, value=format_partition_data(data)
  111. parsed[item].setdefault(key, value)
  112. return parsed
  113. def discover_edirectory_items(section) -> DiscoveryResult:
  114. '''discover one item per key'''
  115. for key, data in section.items():
  116. '''Yield a Service, unless the key is empty'''
  117. if len(key) != 0:
  118. yield Service(item=key)