From a38a85ef4d89ac3fdc310bf89f93b248b996703b Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Sun, 6 Mar 2022 11:32:04 +0100 Subject: [PATCH 1/2] Update to 0.87: Fix uptime --- .../base/plugins/agent_based/unifi_controller.py | 11 +---------- share/check_mk/agents/special/agent_unifi_controller | 11 +++++++---- 2 files changed, 8 insertions(+), 14 deletions(-) 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 1d4af11..715c4f3 100644 --- a/lib/check_mk/base/plugins/agent_based/unifi_controller.py +++ b/lib/check_mk/base/plugins/agent_based/unifi_controller.py @@ -115,7 +115,6 @@ def check_unifi_controller(item,section): state=State.WARN, notice=_("Update available") ) - yield Metric("uptime",int(section.uptime)) if item == "Cloudkey": yield Result( state=State.OK, @@ -271,7 +270,6 @@ register.inventory_plugin( def discovery_unifi_device(section): yield Service(item="Device Status") yield Service(item="Unifi Device") - yield Service(item="Uptime") yield Service(item="Active-User") if section.type != "uap": # kein satisfaction bei ap .. radio/ssid haben schon yield Service(item="Satisfaction") @@ -317,14 +315,7 @@ def check_unifi_device(item,section): ) yield Metric("user_sta",_active_user) yield Metric("guest_sta",_safe_int(section.guest_num_sta)) - if item == "Uptime": - _uptime = int(section.uptime) if section.uptime else -1 - if _uptime > 0: - yield Result( - state=State.OK, - summary=render.timespan(_uptime) - ) - yield Metric("unifi_uptime",_uptime) + if item == "Satisfaction": yield Result( state=State.OK, diff --git a/share/check_mk/agents/special/agent_unifi_controller b/share/check_mk/agents/special/agent_unifi_controller index 274adbc..26bab37 100644 --- a/share/check_mk/agents/special/agent_unifi_controller +++ b/share/check_mk/agents/special/agent_unifi_controller @@ -23,7 +23,7 @@ ## SOFTWARE. ### -__VERSION__ = 0.83 +__VERSION__ = 0.87 import sys import socket @@ -353,7 +353,7 @@ class unifi_device(unifi_object): "lcm_idle_timeout_override","lcm_brightness_override","uplink_depth","mesh_sta_vap_enabled","mesh_uplink_2", "lcm_tracker_enabled","model_incompatible","model_in_lts","model_in_eol","country_code","wifi_caps", "meshv3_peer_mac","element_peer_mac","vwireEnabled","hide_ch_width","x_authkey","x_ssh_hostkey_fingerprint", - "x_fingerprint","x_inform_authkey","op_mode" + "x_fingerprint","x_inform_authkey","op_mode","uptime" ] for _k,_v in self.__dict__.items(): if _k.startswith("_") or _k in _unwanted or type(_v) not in (str,int,float): @@ -362,7 +362,10 @@ class unifi_device(unifi_object): _ret.append("<<>>") _ret.append(f"{{\"unifi_device\":\"unifi-{self.type}\"}}") - + _uptime = getattr(self,"uptime",None) + if _uptime: + _ret.append("<<>>") + _ret.append(str(_uptime)) if self._NETWORK_PORTS: _ret += ["","<<>>"] + [str(_port) for _port in self._NETWORK_PORTS] if self._NETWORK_RADIO: @@ -470,7 +473,7 @@ class unifi_controller(unifi_object): _ret = [] for _ssid,_obj in _dict.items(): - pprint(_obj) + #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)))])) From 6813a7c3080f7a73b8b25cf5a989c0d251d2e524 Mon Sep 17 00:00:00 2001 From: Thorsten Spille Date: Fri, 11 Nov 2022 20:57:41 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 148c966..4ec03a2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # check-unifi-controller Checkmk special agent for checking unifi controller + +### Usage: +Login into your checkmk instnace user on your checkmk server (e.g. via SSH). +Download and install the checkmk agent: +~~~ +wget https://github.com/bashclub/check-unifi-controller/releases/download/v0.87/unifi_controller-0.87.mkp +mkp install ./unifi_controller-0.87.mkp +~~~ + +### Configure Agent +Login into your checkmk website and go to "Setup" -> "Agents" -> "Other integrations" (Datasource programs). Under the category "Hardware" click on "Unifi Controller via API" and create a new rule. +Fill in the credentials of your Unifi controller, set the HTTPS Port, define the site name (if other than default), check "Ignore certificate validation" if using a self signed certificate, select Hostname or IP for storing piggyback data. +Under "Conditions" assign an "Explicit host" with your Unifi Controller Machine. +The agent will carry piggyback data for switches and access points and you can create new hosts to monitor, where piggyback data will be assignesd on exact match (IP or hostname).