mirror of
https://github.com/bashclub/check-unifi-controller.git
synced 2024-11-08 12:32:00 +01:00
Merge branch 'cmk2.2' of github.com:HeinleinSupport/check_mk-unifi-controller into cmk2.2
This commit is contained in:
commit
8863966ce7
10
share/check_mk/agents/special/agent_unifi_controller → agents/special/agent_unifi_controller
Normal file → Executable file
10
share/check_mk/agents/special/agent_unifi_controller → agents/special/agent_unifi_controller
Normal file → Executable file
@ -23,7 +23,7 @@
|
|||||||
## SOFTWARE.
|
## SOFTWARE.
|
||||||
|
|
||||||
###
|
###
|
||||||
__VERSION__ = 2.2.0
|
__VERSION__ = "2.2.0"
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import socket
|
import socket
|
||||||
@ -492,7 +492,7 @@ class unifi_controller(unifi_object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
_ret = ["<<<unifi_controller:sep(124)>>>"]
|
_ret = ["<<<unifi_controller:sep(124)>>>"]
|
||||||
for _k,_v in self.__dict__.items():
|
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
|
continue
|
||||||
_ret.append(f"{_k}|{_v}")
|
_ret.append(f"{_k}|{_v}")
|
||||||
|
|
||||||
@ -503,6 +503,10 @@ class unifi_controller(unifi_object):
|
|||||||
_udm._piggy_back = False
|
_udm._piggy_back = False
|
||||||
_ret.append(str(_udm))
|
_ret.append(str(_udm))
|
||||||
|
|
||||||
|
if "uptime" in self.__dict__:
|
||||||
|
_ret.append("<<<uptime>>>")
|
||||||
|
_ret.append(f"{self.uptime}")
|
||||||
|
|
||||||
_ret.append("<<<labels:sep(0)>>>")
|
_ret.append("<<<labels:sep(0)>>>")
|
||||||
_ret.append(f"{{\"unifi_device\":\"unifi-{self.type}\"}}")
|
_ret.append(f"{{\"unifi_device\":\"unifi-{self.type}\"}}")
|
||||||
|
|
||||||
@ -645,7 +649,7 @@ if __name__ == '__main__':
|
|||||||
if _api.is_unifios:
|
if _api.is_unifios:
|
||||||
|
|
||||||
labels = {"cmk/os_family": "UnifiOS"}
|
labels = {"cmk/os_family": "UnifiOS"}
|
||||||
print("<<<labels:sep(0)>>>"
|
print("<<<labels:sep(0)>>>")
|
||||||
print(json.dumps(labels))
|
print(json.dumps(labels))
|
||||||
|
|
||||||
##pprint(_api.get_data("/stat/rogueap?within=4"))
|
##pprint(_api.get_data("/stat/rogueap?within=4"))
|
@ -115,7 +115,6 @@ def check_unifi_controller(item,section):
|
|||||||
state=State.WARN,
|
state=State.WARN,
|
||||||
notice=_("Update available")
|
notice=_("Update available")
|
||||||
)
|
)
|
||||||
yield Metric("uptime",int(section.uptime))
|
|
||||||
if item == "Cloudkey":
|
if item == "Cloudkey":
|
||||||
yield Result(
|
yield Result(
|
||||||
state=State.OK,
|
state=State.OK,
|
||||||
@ -271,7 +270,6 @@ register.inventory_plugin(
|
|||||||
def discovery_unifi_device(section):
|
def discovery_unifi_device(section):
|
||||||
yield Service(item="Device Status")
|
yield Service(item="Device Status")
|
||||||
yield Service(item="Unifi Device")
|
yield Service(item="Unifi Device")
|
||||||
yield Service(item="Uptime")
|
|
||||||
yield Service(item="Active-User")
|
yield Service(item="Active-User")
|
||||||
if section.type != "uap": # kein satisfaction bei ap .. radio/ssid haben schon
|
if section.type != "uap": # kein satisfaction bei ap .. radio/ssid haben schon
|
||||||
yield Service(item="Satisfaction")
|
yield Service(item="Satisfaction")
|
||||||
@ -317,14 +315,6 @@ def check_unifi_device(item,section):
|
|||||||
)
|
)
|
||||||
yield Metric("user_sta",_active_user)
|
yield Metric("user_sta",_active_user)
|
||||||
yield Metric("guest_sta",_safe_int(section.guest_num_sta))
|
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":
|
if item == "Satisfaction":
|
||||||
yield Result(
|
yield Result(
|
||||||
state=State.OK,
|
state=State.OK,
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
BIN
unifi_controller-0.88.2.mkp
Normal file
BIN
unifi_controller-0.88.2.mkp
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user