diff --git a/share/check_mk/agents/special/agent_unifi_controller b/agents/special/agent_unifi_controller old mode 100644 new mode 100755 similarity index 91% rename from share/check_mk/agents/special/agent_unifi_controller rename to agents/special/agent_unifi_controller index f87b3e0..a29920e --- a/share/check_mk/agents/special/agent_unifi_controller +++ b/agents/special/agent_unifi_controller @@ -1,19 +1,19 @@ #!/usr/bin/env python3 # -*- encoding: utf-8; py-indent-offset: 4 -*- ## MIT License -## -## Copyright (c) 2024 Bash Club -## +## +## Copyright (c) 2021 Bash Club +## ## Permission is hereby granted, free of charge, to any person obtaining a copy ## of this software and associated documentation files (the "Software"), to deal ## in the Software without restriction, including without limitation the rights ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ## copies of the Software, and to permit persons to whom the Software is ## furnished to do so, subject to the following conditions: -## +## ## The above copyright notice and this permission notice shall be included in all ## copies or substantial portions of the Software. -## +## ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -22,8 +22,8 @@ ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ## SOFTWARE. -### -__VERSION__ = 2.01 +### +__VERSION__ = "2.2.0" import sys import socket @@ -44,130 +44,117 @@ except ImportError: UNIFI_DEVICE_TABLE = { 'BZ2' : 'UAP', 'BZ2LR' : 'UAP-LR', - 'S216150' : 'US-16-150W', - 'S224250' : 'US-24-250W', - 'S224500' : 'US-24-500W', - 'S248500' : 'US-48-500W', - 'S248750' : 'US-48-750W', - 'S28150' : 'US-8-150W', 'U2HSR' : 'UAP-Outdoor+', 'U2IW' : 'UAP-IW', - 'U2L48' : 'UAP-LR', - 'U2Lv2' : 'UAP-LRv2', + 'U2L48' : 'UAP-AC-LR', + 'U2Lv2' : 'UAP-AC-LR', 'U2M' : 'UAP-Mini', 'U2O' : 'UAP-Outdoor', - 'U2S48' : 'UAP', - 'U2Sv2' : 'UAPv2', + 'U2S48' : 'UAP-AC', + 'U2Sv2' : 'UAP-AC', 'U5O' : 'UAP-Outdoor5', - 'U6ENT' : 'U6-Enterprise', - 'U6EXT' : 'U6-Extender', - 'U6IW' : 'U6-IW', - 'U6M' : 'U6-Mesh', 'U7E' : 'UAP-AC', 'U7EDU' : 'UAP-AC-EDU', 'U7Ev2' : 'UAP-AC', 'U7HD' : 'UAP-AC-HD', - 'U7IW' : 'UAP-AC-IW', - 'U7IWP' : 'UAP-AC-IW-Pro', - 'U7LR' : 'UAP-AC-LR', - 'U7LT' : 'UAP-AC-Lite', - 'U7MP' : 'UAP-AC-M-Pro', - 'U7MSH' : 'UAP-AC-M', - 'U7NHD' : 'UAP-nanoHD', - 'U7O' : 'UAP-AC-Outdoor', - 'U7P' : 'UAP-AC-Pro', - 'U7PG2' : 'UAP-AC-Pro', 'U7SHD' : 'UAP-AC-SHD', - 'UAE6' : 'U6-Extender-EA', - 'UAIW6' : 'U6-IW-EA', + 'U7NHD' : 'UAP-nanoHD', + 'UFLHD' : 'UAP-FlexHD', + 'UHDIW' : 'UAP-IW-HD', + 'UAIW6' : 'U6-IW', + 'UAE6' : 'U6-Extender', 'UAL6' : 'U6-Lite', + 'UAM6' : 'U6-Mesh', 'UALR6' : 'U6-LR-EA', + 'UAP6' : 'U6-LR', 'UALR6v2' : 'U6-LR', 'UALR6v3' : 'U6-LR', - 'UAM6' : 'U6-Mesh-EA', - 'UAP6' : 'U6-LR', - 'UAP6MP' : 'U6-Pro', - 'UASXG' : 'UAS-XG', - 'UBB' : 'UBB', - 'UBBXG' : 'UBB-XG', - 'UCK' : 'UCK', - 'UCK-v2' : 'UCK', - 'UCK-v3' : 'UCK', - 'UCKG2' : 'UCK-G2', - 'UCKP' : 'UCK-G2-Plus', - 'UCMSH' : 'UAP-XG-Mesh', 'UCXG' : 'UAP-XG', - 'UDC48X6' : 'USW-Leaf', - 'UDM' : 'UDM', + 'UXSDM' : 'UWB-XG', + 'UXBSDM' : 'UWB-XG-BK', + 'UCMSH' : 'UAP-XG-Mesh', + 'U7IW' : 'UAP-AC-IW', + 'U7IWP' : 'UAP-AC-IW-Pro', + 'U7MP' : 'UAP-AC-M-Pro', + 'U7LR' : 'UAP-AC-LR', + 'U7LT' : 'UAP-AC-Lite', + 'U7O' : 'UAP-AC-Outdoor', + 'U7P' : 'UAP-Pro', + 'U7MSH' : 'UAP-AC-M', + 'U7PG2' : 'UAP-AC-Pro', + 'p2N' : 'PICOM2HP', 'UDMB' : 'UAP-BeaconHD', - 'UDMPRO' : 'UDM-Pro', - 'UDMPROSE' : 'UDM-SE', - 'UDR' : 'UDR', - 'UDW' : 'UDW', - 'UDWPRO' : 'UDWPRO', - 'UFLHD' : 'UAP-FlexHD', - 'UGW3' : 'USG-3P', - 'UGW4' : 'USG-Pro-4', - 'UGWHD4' : 'USG', - 'UGWXG' : 'USG-XG-8', - 'UHDIW' : 'UAP-IW-HD', - 'ULTE' : 'U-LTE', - 'ULTEPEU' : 'U-LTE-Pro', - 'ULTEPUS' : 'U-LTE-Pro', - 'UP1' : 'USP-Plug', - 'UP4' : 'UVP-X', - 'UP5' : 'UVP', - 'UP5c' : 'UVP', - 'UP5t' : 'UVP-Pro', - 'UP5tc' : 'UVP-Pro', - 'UP6' : 'USP-Strip', - 'UP7' : 'UVP-Executive', - 'UP7c' : 'UVP-Executive', + 'USF5P' : 'USW-Flex', + 'US8' : 'US-8', + 'US8P60' : 'US-8-60W', + 'US8P150' : 'US-8-150W', + 'S28150' : 'US-8-150W', + 'USC8' : 'US-8', + 'USC8P60' : 'US-8-60W', + 'USC8P150' : 'US-8-150W', 'US16P150' : 'US-16-150W', - 'US24' : 'USW-24-G1', - 'US24P250' : 'US-24-250W', - 'US24P500' : 'US-24-500W', - 'US24PL2' : 'US-L2-24-PoE', + 'S216150' : 'US-16-150W', + 'US24' : 'US-24-G1', 'US24PRO' : 'USW-Pro-24-PoE', 'US24PRO2' : 'USW-Pro-24', + 'US24P250' : 'US-24-250W', + 'US24PL2' : 'US-L2-24-PoE', + 'US24P500' : 'US-24-500W', + 'S224250' : 'US-24-250W', + 'S224500' : 'US-24-500W', 'US48' : 'US-48-G1', - 'US48P500' : 'US-48-500W', - 'US48P750' : 'US-48-750W', - 'US48PL2' : 'US-L2-48-PoE', 'US48PRO' : 'USW-Pro-48-PoE', 'US48PRO2' : 'USW-Pro-48', - 'US624P' : 'USW-Enterprise-24-PoE', - 'US648P' : 'USW-Enterprise-48-PoE', - 'US68P' : 'USW-Enterprise-8-PoE', + 'US48P500' : 'US-48-500W', + 'US48PL2' : 'US-L2-48-PoE', + 'US48P750' : 'US-48-750W', + 'S248500' : 'US-48-500W', + 'S248750' : 'US-48-750W', 'US6XG150' : 'US-XG-6PoE', - 'US8' : 'US-8', - 'US8P150' : 'US-8-150W', - 'US8P60' : 'US-8-60W', - 'USAGGPRO' : 'USW-Pro-Aggregation', - 'USC8' : 'US-8', - 'USC8P150' : 'US-8-150W', + 'USMINI' : 'USW-Flex-Mini', + 'USXG' : 'US-16-XG', 'USC8P450' : 'USW-Industrial', - 'USC8P60' : 'US-8-60W', - 'USF5P' : 'USW-Flex', - 'USFXG' : 'USW-Flex-XG', - 'USL16LP' : 'USW-Lite-16-PoE', + 'UDC48X6' : 'USW-Leaf', + 'USL8A' : 'UniFi Switch Aggregation', + 'USAGGPRO' : 'UniFi Switch Aggregation Pro', + 'USL8LP' : 'USW-Lite-8-PoE', + 'USL8MP' : 'USW-Mission-Critical', 'USL16P' : 'USW-16-PoE', + 'USL16LP' : 'USW-Lite-16-PoE', 'USL24' : 'USW-24-G2', - 'USL24P' : 'USW-24-PoE', 'USL48' : 'USW-48-G2', + 'USL24P' : 'USW-24-PoE', 'USL48P' : 'USW-48-PoE', - 'USL8A' : 'USW-Aggregation', - 'USL8LP' : 'USW-Lite-8-PoE', - 'USL8MP' : 'USW-Mission-Critical', - 'USMINI' : 'USW-Flex-Mini', - 'USPPDUP' : 'USP-PDU-Pro', + 'UGW3' : 'USG-3P', + 'UGW4' : 'USG-Pro-4', + 'UGWHD4' : 'USG', + 'UGWXG' : 'USG-XG-8', + 'UDM' : 'UDM', + 'UDMSE' : 'UDM-SE', + 'UDMPRO' : 'UDM-Pro', + 'UP4' : 'UVP-X', + 'UP5' : 'UVP', + 'UP5t' : 'UVP-Pro', + 'UP7' : 'UVP-Executive', + 'UP5c' : 'UVP', + 'UP5tc' : 'UVP-Pro', + 'UP7c' : 'UVP-Executive', + 'UCK' : 'UCK', + 'UCK-v2' : 'UCK', + 'UCK-v3' : 'UCK', + 'UCKG2' : 'UCK-G2', + 'UCKP' : 'UCK-G2-Plus', + 'UASXG' : 'UAS-XG', + 'ULTE' : 'U-LTE', + 'ULTEPUS' : 'U-LTE-Pro', + 'ULTEPEU' : 'U-LTE-Pro', + 'UP1' : 'USP-Plug', + 'UP6' : 'USP-Strip', + 'USPPDUP' : 'USP - Power Distribution Unit Pro', 'USPRPS' : 'USP-RPS', - 'USXG' : 'US-16-XG', - 'USXG24' : 'USW-EnterpriseXG-24', - 'UXBSDM' : 'UWB-XG-BK', - 'UXGPRO' : 'UXG-Pro', - 'UXSDM' : 'UWB-XG', - 'p2N' : 'PICOM2HP' + 'US624P' : 'UniFi6 Switch 24', + 'UBB' : 'UBB', + 'UXGPRO' : 'UniFi NeXt-Gen Gateway PRO' } try: @@ -227,7 +214,7 @@ class unifi_network_ssid(unifi_object): ######################################## ###### -###### R A D I O +###### R A D I O ###### ######################################## class unifi_network_radio(unifi_object): @@ -246,7 +233,7 @@ class unifi_network_radio(unifi_object): continue _ret.append(f"{self.name}|{_k}|{_v}") return "\n".join(_ret) - + ######################################## ###### ###### P O R T @@ -266,9 +253,9 @@ class unifi_network_port(unifi_object): self.name = self.ifname if not hasattr(self,"port_idx") and hasattr(self,"ifname"): self.port_idx = int(self.ifname[-1])+1 ## ethX - + self.portconf = self._PARENT._PARENT._PORTCONFIGS.get(getattr(self,"portconf_id",None)) - + def _get_state(self,state): return { @@ -299,16 +286,16 @@ class unifi_device(unifi_object): self._NETWORK_PORTS = [] self._NETWORK_RADIO = [] self._NETWORK_SSIDS = [] - + for _k,_v in getattr(self,"sys_stats",{}).items(): _k = _k.replace("-","_") setattr(self,_k,_v) self.model_name = UNIFI_DEVICE_TABLE.get(self.model) - if self.type in ("ugw","udm") and hasattr(self,"connect_request_ip"): + if self.type in ("ugw","udm"): ## change ip to local ip self.wan_ip = self.ip self.ip = self.connect_request_ip - + if getattr(self,"speedtest_status_saved",False): _speedtest = getattr(self,"speedtest_status",{}) self.speedtest_time = int(_speedtest.get("rundate","0")) @@ -316,11 +303,11 @@ class unifi_device(unifi_object): self.speedtest_ping = round(_speedtest.get("latency",-1),1) self.speedtest_download = round(_speedtest.get("xput_download",0.0),1) self.speedtest_upload = round(_speedtest.get("xput_upload",0.0),1) - + _temp = list(map(lambda x: x.get("value",0),getattr(self,"temperatures",[]))) if _temp: self.general_temperature = "{0:.1f}".format(mean(_temp)) - + for _port in getattr(self,"port_table",[]): self._NETWORK_PORTS.append(unifi_network_port(_PARENT=self,**_port)) @@ -383,7 +370,7 @@ class unifi_device(unifi_object): _ret += ["","<<>>"] + [str(_port) for _port in self._NETWORK_PORTS] if self._NETWORK_RADIO: _ret += ["","<<>>"] + [str(_radio) for _radio in self._NETWORK_RADIO] - + if self._NETWORK_SSIDS: _ret += ["","<<>>"] + [str(_ssid) for _ssid in sorted(self._NETWORK_SSIDS,key=lambda x: x.essid)] return "\n".join(_ret) @@ -403,7 +390,7 @@ class unifi_site(unifi_object): continue #print(f"{_k}:{_v}") setattr(self,f"{_name}_{_k}",_v) - + ##pprint(_api.get_data("/stat/rogueap")) self._SITE_DEVICES = [] self._PORTCONFIGS = {} @@ -451,7 +438,7 @@ class unifi_controller(unifi_object): for _dev in self._UNIFI_DEVICES: _dev._get_uplink() if hasattr(self,"cloudkey_version"): - self.cloudkey_version = re.sub(".*?v(\d+\.\d+\.\d+\.[a-z0-9]+).*","\\1",self.cloudkey_version) + self.cloudkey_version = re.sub(r".*?v(\d+\.\d+\.\d+\.[a-z0-9]+).*","\\1",self.cloudkey_version) self.type = getattr(self,"ubnt_device_type","unifi-sw-controller") self.controller_version = self.version delattr(self,"version") @@ -483,13 +470,13 @@ class unifi_controller(unifi_object): _dict = defaultdict(list) for _ssid in self._UNIFI_SSIDS: _dict[f"{_ssid.essid}@{_ssid._UNIFI_SITE.desc}"].append(_ssid) - + _ret = [] for _ssid,_obj in _dict.items(): #pprint(_obj) for _key in ("num_sta","ng_num_sta","na_num_sta","ng_tcp_packet_loss","na_tcp_packet_loss","ng_wifi_retries","na_wifi_retries","ng_wifi_latency","na_wifi_latency"): _ret.append("|".join([_ssid,_key,str(sum(map(lambda x: getattr(x,_key,0),_obj)))])) - + _signals = list(map(lambda x: getattr(x,"ng_avg_client_signal",0),filter(lambda x: x.radio == "ng",_obj))) _ret.append("|".join([_ssid,"ng_avg_client_signal",str(mean(_signals if _signals else [0]))])) _signals = list(map(lambda x: getattr(x,"na_avg_client_signal",0),filter(lambda x: x.radio == "na",_obj))) @@ -501,11 +488,11 @@ class unifi_controller(unifi_object): )])) _ret.append("|".join([_ssid,"avg_client_signal",str(mean(map(lambda x: getattr(x,"avg_client_signal",0),_obj))) ])) return _ret - + def __str__(self): _ret = ["<<>>"] for _k,_v in self.__dict__.items(): - if _k.startswith("_") or type(_v) not in (str,int,float): + if _k == "uptime" or _k.startswith("_") or type(_v) not in (str,int,float): continue _ret.append(f"{_k}|{_v}") @@ -516,6 +503,10 @@ class unifi_controller(unifi_object): _udm._piggy_back = False _ret.append(str(_udm)) + if "uptime" in self.__dict__: + _ret.append("<<>>") + _ret.append(f"{self.uptime}") + _ret.append("<<>>") _ret.append(f"{{\"unifi_device\":\"unifi-{self.type}\"}}") @@ -528,7 +519,7 @@ class unifi_controller(unifi_object): if _device._piggy_back: _ret.append(_device._get_short_info()) ## device list - + ## ssid list _ret.append("<<>>") _ret += self._get_ssidlist() @@ -565,11 +556,7 @@ class unifi_controller_api(object): def check_unifi_os(self): _response = self.request("GET",url=self.url,allow_redirects=False) - _osid = re.findall('UNIFI_OS_MANIFEST.*?"id":"(\w+)"',_response.text) - if _osid and _osid[0] in ("UCKP","UNVR","UDMPRO","UDMENT","UDM","UDR"): - self.is_unifios = _osid[0] - else: - self.is_unifios = [] + self.is_unifios= _response.status_code == 200 def get_sysinfo(self): return self.get_data("/stat/sysinfo") @@ -603,21 +590,14 @@ class unifi_controller_api(object): def get_data(self,path,site="default",method="GET",**kwargs): _json = self.request(method=method,path=path,site=site,**kwargs).json() - if type(_json) == dict: - _meta = _json.get("meta",{}) - if _meta.get("rc") == "ok": - return _json.get("data",[]) - if _json.get("modelKey") == "nvr": - return _json - if type(_json) == list: - return _json + _meta = _json.get("meta",{}) + if _meta.get("rc") == "ok": + return _json.get("data",[]) raise unifi_api_exception(_meta.get("msg",_json.get("errors",repr(_json)))) def request(self,method,url=None,path=None,site=None,json=None,**kwargs): if not url: - if self.is_unifios == "UNVR": - url = f"{self.url}/proxy/protect/api" - elif self.is_unifios: + if self.is_unifios: url = f"{self.url}/proxy/network/api" else: url = f"{self.url}/api" @@ -659,6 +639,7 @@ if __name__ == '__main__': parser.add_argument("host",type=str, help="""Host name or IP address of Unifi Controller""") args = parser.parse_args() + try: _api = unifi_controller_api(**args.__dict__) except socket.error as e: @@ -666,14 +647,11 @@ if __name__ == '__main__': sys.exit(1) if _api.is_unifios: + labels = {"cmk/os_family": "UnifiOS"} print("<<>>") print(json.dumps(labels)) - if _api.is_unifios == "UNVR": - pprint(_api.get_data("/sensors",site=None)) - pprint(_api.get_data("/cameras",site=None)) - pprint(_api.get_data("/nvr",site=None)) - sys.exit(0) + ##pprint(_api.get_data("/stat/rogueap?within=4")) ##pprint(_api.get_data("/rest/user",site="default",method="GET")) ##pprint(_api.get_data("/stat/sta",site="default",method="GET")) diff --git a/share/check_mk/checkman/unifi_controller b/checkman/unifi_controller similarity index 66% rename from share/check_mk/checkman/unifi_controller rename to checkman/unifi_controller index 66a19eb..5c19c01 100644 --- a/share/check_mk/checkman/unifi_controller +++ b/checkman/unifi_controller @@ -1,7 +1,8 @@ title: Unifi Controller agents: unifi_controller -catalog: networking -licence: MIT +catalog: networking/unifi +distribution: unifi +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each device - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_device b/checkman/unifi_device similarity index 65% rename from share/check_mk/checkman/unifi_device rename to checkman/unifi_device index c83defd..23f622c 100644 --- a/share/check_mk/checkman/unifi_device +++ b/checkman/unifi_device @@ -1,7 +1,8 @@ title: Unifi Device agents: unifi_controller -catalog: networking -licence: MIT +catalog: networking/unifi +distribution: unifi +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each device - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_device_shortlist b/checkman/unifi_device_shortlist similarity index 66% rename from share/check_mk/checkman/unifi_device_shortlist rename to checkman/unifi_device_shortlist index 5a3554c..2c0a400 100644 --- a/share/check_mk/checkman/unifi_device_shortlist +++ b/checkman/unifi_device_shortlist @@ -1,7 +1,8 @@ title: Unifi Devicelist -catalog: networking +catalog: networking/unifi +distribution: unifi agents: unifi_controller -licence: MIT +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each device - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_network_ports_if b/checkman/unifi_network_ports_if similarity index 65% rename from share/check_mk/checkman/unifi_network_ports_if rename to checkman/unifi_network_ports_if index ce4eae5..2f4b833 100644 --- a/share/check_mk/checkman/unifi_network_ports_if +++ b/checkman/unifi_network_ports_if @@ -1,7 +1,8 @@ title: Unifi Network Port agents: unifi_controller -catalog: networking -licence: MIT +catalog: networking/unifi +distribution: unifi +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each Port - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_network_radios b/checkman/unifi_network_radios similarity index 65% rename from share/check_mk/checkman/unifi_network_radios rename to checkman/unifi_network_radios index 7e5a223..a609554 100644 --- a/share/check_mk/checkman/unifi_network_radios +++ b/checkman/unifi_network_radios @@ -1,7 +1,8 @@ title: Unifi WLAN Radio agents: unifi_controller -catalog: networking -licence: MIT +catalog: networking/unifi +distribution: unifi +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each Radio - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_network_ssids b/checkman/unifi_network_ssids similarity index 64% rename from share/check_mk/checkman/unifi_network_ssids rename to checkman/unifi_network_ssids index 3dc339e..6ee6568 100644 --- a/share/check_mk/checkman/unifi_network_ssids +++ b/checkman/unifi_network_ssids @@ -1,7 +1,8 @@ title: Unifi SSID agents: unifi_controller -catalog: networking -licence: MIT +catalog: networking/unifi +distribution: unifi +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each SSID - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_sites b/checkman/unifi_sites similarity index 64% rename from share/check_mk/checkman/unifi_sites rename to checkman/unifi_sites index 7295cdf..603fb0f 100644 --- a/share/check_mk/checkman/unifi_sites +++ b/checkman/unifi_sites @@ -1,7 +1,8 @@ title: Unifi Site agents: unifi_controller -catalog: networking -licence: MIT +catalog: networking/unifi +distribution: unifi +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each Site - \ No newline at end of file + diff --git a/share/check_mk/checkman/unifi_ssid_list b/checkman/unifi_ssid_list similarity index 66% rename from share/check_mk/checkman/unifi_ssid_list rename to checkman/unifi_ssid_list index 5a3554c..2c0a400 100644 --- a/share/check_mk/checkman/unifi_ssid_list +++ b/checkman/unifi_ssid_list @@ -1,7 +1,8 @@ title: Unifi Devicelist -catalog: networking +catalog: networking/unifi +distribution: unifi agents: unifi_controller -licence: MIT +license: MIT description: plz fill me @@ -10,4 +11,4 @@ item: inventory: One Service for each device - \ No newline at end of file + diff --git a/share/check_mk/checks/agent_unifi_controller b/checks/agent_unifi_controller similarity index 100% rename from share/check_mk/checks/agent_unifi_controller rename to checks/agent_unifi_controller diff --git a/lib/check_mk/base/plugins/agent_based/unifi_controller.py b/lib/check_mk/base/plugins/agent_based/unifi_controller.py index e524e69..ff6b99a 100644 --- a/lib/check_mk/base/plugins/agent_based/unifi_controller.py +++ b/lib/check_mk/base/plugins/agent_based/unifi_controller.py @@ -3,7 +3,7 @@ # ## MIT License ## -## Copyright (c) 2024 Bash Club +## Copyright (c) 2021 Bash Club ## ## Permission is hereby granted, free of charge, to any person obtaining a copy ## of this software and associated documentation files (the "Software"), to deal @@ -120,7 +120,7 @@ def check_unifi_controller(item,section): state=State.OK, summary=f"Version: {section.cloudkey_version}" ) - if _safe_int(section.cloudkey_update_available) > 0: + if int(section.cloudkey_update_available) > 0: yield Result( state=State.WARN, notice=_("Update available") @@ -761,3 +761,5 @@ def check_unifi_ssidlist(item,section): ) + + diff --git a/share/check_mk/inventory/unifi_controller b/share/check_mk/inventory/unifi_controller deleted file mode 100644 index 32b9be8..0000000 --- a/share/check_mk/inventory/unifi_controller +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 -# -*- encoding: utf-8; py-indent-offset: 4 -*- - -from pprint import pprint -from collections import defaultdict - -class dictobject(defaultdict): - def __getattr__(self,name): - return self[name] if name in self else "" - -nested_dictobject = lambda: dictobject(nested_dictobject) - -def inv_unifi_controller(info): - node = inv_tree("software.os") - node["version"] = info.get("controller_version") - -def inv_unifi_device(info): - node = inv_tree("software.configuration.snmp_info") - node["name"] = info.get("name") - node["contact"] = info.get("snmp_contact") - node["location"] = info.get("snmp_location") - node = inv_tree("software.os") - node["version"] = info.get("version") - node = inv_tree("harware.system") - node["vendor"] = "ubiquiti" - for _key in ("model","board_rev","serial","mac"): - _val = info.get(_key) - if _val: - node[_key] = _val - -def inv_unifi_port(info,params,inventory_tree): - _parsed = nested_dictobject() - for _line in info: - _parsed[_line[0]][_line[1]] = _line[2] - - _interfaces = [] - _total_ethernet_ports = 0 - _available_ethernet_ports = 0 - def _saveint(num): - try: - return int(num) - except (TypeError,ValueError): - return 0 - for _iface in _parsed.values(): - _interfaces.append({ - "index" : int(_iface.port_idx), - "description" : _iface.name, - "alias" : _iface.name, - "speed" : _saveint(_iface.speed)*1000000, - "phys_address" : "", - "oper_status" : _saveint(_iface.oper_status), - "admin_status" : _saveint(_iface.admin_status), - "port_type" : 6, - "available" : _iface.oper_status == '2' - }) - _total_ethernet_ports+=1 - _available_ethernet_ports+=1 if _iface.oper_status == '2' else 0 - - node = inventory_tree.get_list("networking.interfaces:") - node.extend(sorted(_interfaces, key=lambda i: i.get('index'))) - node = inventory_tree.get_dict("networking.") - node["available_ethernet_ports"] = _available_ethernet_ports - node["total_ethernet_ports"] = _total_ethernet_ports - node["total_interfaces"] = len(_parsed) - -inv_info["unifi_controller"] = { - "inv_function" : inv_unifi_controller -} -inv_info["unifi_device"] = { - "inv_function" : inv_unifi_device -} - -inv_info["unifi_network_ports"] = { - "inv_function" : inv_unifi_port -} - diff --git a/unifi_controller-0.88.5.mkp b/unifi_controller-0.88.5.mkp new file mode 100644 index 0000000..8210023 Binary files /dev/null and b/unifi_controller-0.88.5.mkp differ diff --git a/share/check_mk/web/plugins/metrics/unifi_metrics.py b/web/plugins/metrics/unifi_metrics.py similarity index 100% rename from share/check_mk/web/plugins/metrics/unifi_metrics.py rename to web/plugins/metrics/unifi_metrics.py diff --git a/share/check_mk/web/plugins/perfometer/unifi_performeter.py b/web/plugins/perfometer/unifi_performeter.py similarity index 100% rename from share/check_mk/web/plugins/perfometer/unifi_performeter.py rename to web/plugins/perfometer/unifi_performeter.py diff --git a/share/check_mk/web/plugins/wato/datasource_unifi_controller.py b/web/plugins/wato/datasource_unifi_controller.py similarity index 100% rename from share/check_mk/web/plugins/wato/datasource_unifi_controller.py rename to web/plugins/wato/datasource_unifi_controller.py