lib.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. ]
  35. total_counter_attributes = [
  36. "TrafficVolume_inBytes",
  37. "TrafficVolume_outBytes",
  38. "Errors_securityErrors",
  39. "Errors_errors",
  40. "Bindings_simpleAuthBinds",
  41. "Bindings_unAuthBinds",
  42. "Bindings_bindSecurityErrors",
  43. "Bindings_strongAuthBinds",
  44. "IncomingOperations_extendedOps",
  45. "IncomingOperations_abandonOps",
  46. "IncomingOperations_wholeSubtreeSearchOps",
  47. "IncomingOperations_oneLevelSearchOps",
  48. "IncomingOperations_searchOps",
  49. "IncomingOperations_listOps",
  50. "IncomingOperations_modifyRDNOps",
  51. "IncomingOperations_modifyEntryOps",
  52. "IncomingOperations_removeEntryOps",
  53. "IncomingOperations_addEntryOps",
  54. "IncomingOperations_compareOps",
  55. "IncomingOperations_readOps",
  56. "IncomingOperations_inOps",
  57. "OutgoingOperations_chainings",
  58. "CacheFaultLooks_Total",
  59. "CacheFaultLooks_BlockCache",
  60. "CacheFaultLooks_EntryCache",
  61. "Hits_Total",
  62. "Hits_BlockCache",
  63. "Hits_EntryCache",
  64. "HitLooks_Total",
  65. "HitLooks_BlockCache",
  66. "HitLooks_EntryCache",
  67. ]
  68. def format_partition_agent(value):
  69. """strip unwanted data from Agent Partition data"""
  70. formatted = re.sub('CN=|OU=|O=|T=', '', value).replace("=", " ").replace(" ", "").split("#")
  71. return formatted
  72. def format_partition_data(value):
  73. """strip unwanted data from Agent Partition data"""
  74. formatted = re.sub('CN=|OU=|O=', '', value).replace(',', '.')
  75. return formatted
  76. def convert_timestamp(value):
  77. """convert Zulu time to current time in local timezone"""
  78. utc_dt = datetime.datetime.strptime(str(value), "%Y%m%d%H%M%SZ")
  79. utc = pytz.utc
  80. utc_dt = utc_dt.replace(tzinfo=tz.UTC)
  81. local_tz = tz.tzlocal()
  82. local_dt = utc_dt.astimezone(local_tz)
  83. return local_dt
  84. def parse_ldap_data(string_table):
  85. """parse one lines of data to dictionary"""
  86. parsed = {}
  87. for line in string_table:
  88. item = line[0]
  89. parsed.setdefault(item, {})
  90. for _count, data in enumerate(line[1:]):
  91. if item == "Agent Partition":
  92. key, value=format_partition_agent(data)
  93. else:
  94. key, value=data.split("=")
  95. parsed[item].setdefault(key, value)
  96. return parsed
  97. def discover_edirectory_items(section) -> DiscoveryResult:
  98. '''discover one item per key'''
  99. for key, data in section.items():
  100. yield Service(item=key)