From 72a9fe8761a9fc3ef7638171575c8fe6da82e3bf Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 13 Sep 2023 09:55:04 +0200 Subject: [PATCH] update to support CheckMK 2.2.0 --- .../plugins/agent_based/unifi_controller.py | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) mode change 100644 => 100755 lib/check_mk/base/plugins/agent_based/unifi_controller.py diff --git a/lib/check_mk/base/plugins/agent_based/unifi_controller.py b/lib/check_mk/base/plugins/agent_based/unifi_controller.py old mode 100644 new mode 100755 index a4b9b06..44c4d0f --- a/lib/check_mk/base/plugins/agent_based/unifi_controller.py +++ b/lib/check_mk/base/plugins/agent_based/unifi_controller.py @@ -415,7 +415,7 @@ def inventory_unifi_device(section): ############ DEVICEPORT ########### @dataclass -class unifi_interface(interfaces.Interface): +class unifi_interface(interfaces.InterfaceWithCounters): jumbo : bool = False satisfaction : int = 0 poe_enable : bool = False @@ -430,9 +430,6 @@ class unifi_interface(interfaces.Interface): ip_address : Optional[str] = None portconf : Optional[str] = None - def __post_init__(self) -> None: - self.finalize() - def _convert_unifi_counters_if(section: Section) -> interfaces.Section: ## 10|port_idx|10 ## 10|port_poe|1 @@ -488,25 +485,31 @@ def _convert_unifi_counters_if(section: Section) -> interfaces.Section: return [ unifi_interface( - index=str(netif.port_idx), - descr=netif.name, - alias=netif.name, - type='6', - speed=_safe_int(netif.speed)*1000000, - oper_status=netif.oper_status, - admin_status=netif.admin_status, - in_octets=_safe_int(netif.rx_bytes), - in_ucast=_safe_int(netif.rx_packets), - in_mcast=_safe_int(netif.rx_multicast), - in_bcast=_safe_int(netif.rx_broadcast), - in_discards=_safe_int(netif.rx_dropped), - in_errors=_safe_int(netif.rx_errors), - out_octets=_safe_int(netif.tx_bytes), - out_ucast=_safe_int(netif.tx_packets), - out_mcast=_safe_int(netif.tx_multicast), - out_bcast=_safe_int(netif.tx_broadcast), - out_discards=_safe_int(netif.tx_dropped), - out_errors=_safe_int(netif.tx_errors), + attributes=interfaces.Attributes( + index=str(netif.port_idx), + descr=netif.name, + type="6", + speed=int(netif.speed) * 1000000, + oper_status="1" if netif.oper_status == "1" else "2", + out_qlen=None, + alias=netif.name, + phys_address=None, + ), + counters=interfaces.Counters( + in_octets=int(netif.rx_bytes), + in_ucast=int(netif.rx_packets), + in_mcast=int(netif.rx_multicast), + in_bcast=int(netif.rx_broadcast), + in_disc=int(netif.rx_dropped), + in_err=int(netif.rx_errors), + out_octets=int(netif.tx_bytes), + out_ucast=int(netif.tx_packets), + out_mcast=int(netif.tx_multicast), + out_bcast=int(netif.tx_broadcast), + out_disc=int(netif.tx_dropped), + out_err=int(netif.tx_errors), + ), + jumbo=True if netif.jumbo == "1" else False, satisfaction=_safe_int(netif.satisfaction) if netif.satisfaction and netif.oper_status == "1" else 0, poe_enable=True if netif.poe_enable == "1" else False, @@ -540,7 +543,7 @@ def check_unifi_network_port_if( ##fixme parsed_section_name section: Section, ) -> CheckResult: _converted_ifs = _convert_unifi_counters_if(section) - iface = next(filter(lambda x: _safe_int(item,-1) == _safe_int(x.index) or item == x.alias,_converted_ifs),None) ## fix Service Discovery appearance alias/descr + iface = next(filter(lambda x: _safe_int(item,-1) == _safe_int(x.attributes.index) or item == x.attributes.alias,_converted_ifs),None) ## fix Service Discovery appearance alias/descr yield from interfaces.check_multiple_interfaces( item, params,