Skip to content

Commit

Permalink
Update to 0.83
Browse files Browse the repository at this point in the history
  • Loading branch information
spille-edv committed Jan 21, 2022
1 parent 1573ea2 commit 7c03965
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
30 changes: 25 additions & 5 deletions lib/check_mk/base/plugins/agent_based/unifi_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def discovery_unifi_sites(section):
for _item in section.values():
yield Service(item=f"{_item.desc}")

def check_unifi_sites(item,section):
def check_unifi_sites(item,params,section):
site = next(filter(lambda x: x.desc == item,section.values()))
yield Metric("satisfaction",max(0,_safe_int(site.satisfaction)))

Expand All @@ -169,7 +169,8 @@ def check_unifi_sites(item,section):
#yield Metric("if_in_bps",_safe_int(site.lan_rx_bytes_r)*8)
yield Metric("if_out_octets",_safe_int(site.lan_tx_bytes_r))
#yield Metric("if_out_bps",_safe_int(site.lan_tx_bytes_r)*8)

yield Metric("lan_active_sw",_safe_int(site.lan_num_sw))
yield Metric("lan_total_sw",_safe_int(site.lan_num_adopted))
yield Result(
state=_unifi_status2state(site.lan_status),
summary=f"LAN: {site.lan_num_sw}/{site.lan_num_adopted} Switch ({site.lan_status})"
Expand All @@ -185,6 +186,8 @@ def check_unifi_sites(item,section):
yield Metric("wlan_iot_sta",_safe_int(site.wlan_num_iot))
yield Metric("wlan_if_in_octets",_safe_int(site.wlan_rx_bytes_r))
yield Metric("wlan_if_out_octets",_safe_int(site.wlan_tx_bytes_r))
yield Metric("wlan_active_ap",_safe_int(site.wlan_num_ap))
yield Metric("wlan_total_ap",_safe_int(site.wlan_num_adopted))
yield Result(
state=_unifi_status2state(site.wlan_status),
summary=f"WLAN: {site.wlan_num_ap}/{site.wlan_num_adopted} AP ({site.wlan_status})"
Expand All @@ -208,8 +211,14 @@ def check_unifi_sites(item,section):
state=_unifi_status2state(site.vpn_status),
notice=f"WWW Status: {site.vpn_status}"
)

if params.get("ignore_alarms"):
_alarmstate = State.OK
else:
_alarmstate = _expect_number(site.num_new_alarms)

yield Result(
state=_expect_number(site.num_new_alarms),
state=_alarmstate,
notice=f"{site.num_new_alarms} new Alarm"
)

Expand All @@ -223,6 +232,8 @@ def check_unifi_sites(item,section):
name='unifi_sites',
service_name='Site %s',
discovery_function=discovery_unifi_sites,
check_default_parameters={},
check_ruleset_name="unifi_sites",
check_function=check_unifi_sites,
)

Expand Down Expand Up @@ -258,6 +269,7 @@ def inventory_unifi_device_shortlist(section):

############ DEVICE ###########
def discovery_unifi_device(section):
yield Service(item="Device Status")
yield Service(item="Unifi Device")
yield Service(item="Uptime")
yield Service(item="Active-User")
Expand All @@ -271,8 +283,16 @@ def discovery_unifi_device(section):
yield Service(item="Speedtest")

def check_unifi_device(item,section):
if section.state != "1":
yield IgnoreResults(f"device not active State: {section.state}")
_device_state = UNIFI_DEVICE_STATES.get(section.state,"unknown")
## connected OK / pending Warn / Rest Crit
_hoststatus = State.OK if section.state == "1" else State.WARN if section.state == "2" else State.CRIT
if item == "Device Status":
yield Result(
state=_hoststatus,
summary=f"Status: {_device_state}"
)
#if section.state != "1":
# yield IgnoreResults(f"device not active State: {section.state}")

if item == "Unifi Device":
yield Result(
Expand Down
4 changes: 2 additions & 2 deletions share/check_mk/agents/special/agent_unifi_controller
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
## SOFTWARE.

###
__VERSION__ = 0.80
__VERSION__ = 0.83

import sys
import socket
Expand Down Expand Up @@ -591,7 +591,7 @@ class unifi_controller_api(object):
def request(self,method,url=None,path=None,site=None,json=None,**kwargs):
if not url:
if self.is_unifios:
url = f"{self.url}/proxy/network/api/"
url = f"{self.url}/proxy/network/api"
else:
url = f"{self.url}/api"
if site is not None:
Expand Down
38 changes: 38 additions & 0 deletions share/check_mk/web/plugins/metrics/unifi_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,44 @@
],
}


metric_info["lan_active_sw"] = {
"title": _("Active Switches"),
"unit": "count",
"color": "13/b",
}
metric_info["lan_total_sw"] = {
"title": _("Total Switches"),
"unit": "count",
"color": "13/a",
}

graph_info["lan_active_sw_combined"] = {
"title" : _("Active Switches"),
"metrics" : [
("lan_active_sw","area"),
("lan_total_sw","line"),
],
}
metric_info["wlan_active_ap"] = {
"title": _("Active Accesspoints"),
"unit": "count",
"color": "13/b",
}
metric_info["wlan_total_ap"] = {
"title": _("Total Accesspoints"),
"unit": "count",
"color": "13/a",
}

graph_info["wlan_active_ap_combined"] = {
"title" : _("Active Accesspoints"),
"metrics" : [
("wlan_active_ap","area"),
("wlan_total_ap","line"),
],
}

metric_info["wlan_user_sta"] = {
"title": _("WLAN User"),
"unit": "count",
Expand Down
27 changes: 27 additions & 0 deletions share/check_mk/web/plugins/wato/datasource_unifi_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
from cmk.gui.i18n import _
from cmk.gui.plugins.wato import (
HostRulespec,
CheckParameterRulespecWithItem,
IndividualOrStoredPassword,
rulespec_registry,
)
from cmk.gui.valuespec import (
Dictionary,
Tuple,
Alternative,
NetworkPort,
Checkbox,
Expand Down Expand Up @@ -72,3 +74,28 @@ def _valuespec_special_agent_unifi_controller():
valuespec=_valuespec_special_agent_unifi_controller,
))

def _item_spec_unifi_site():
return TextAscii(
title=_("Site"),
help=_("help Site Text")
)

def _parameter_valuespec_unifi_site():
return Dictionary(
title = _("Unifi Site"),
optional_keys=[],
elements = [
('ignore_alarms', Checkbox(title=_("Ignore Site Alarms"), default_value=False)),
]
)

rulespec_registry.register(
CheckParameterRulespecWithItem(
check_group_name = "unifi_sites",
group=RulespecGroupCheckParametersNetworking,
item_spec = _item_spec_unifi_site,
match_type = "dict",
parameter_valuespec=_parameter_valuespec_unifi_site,
title=lambda: _("Unifi Site Parameter")
)
)

0 comments on commit 7c03965

Please sign in to comment.