Skip to content

Commit 7c03965

Browse files
committed
Update to 0.83
1 parent 1573ea2 commit 7c03965

File tree

4 files changed

+92
-7
lines changed

4 files changed

+92
-7
lines changed

lib/check_mk/base/plugins/agent_based/unifi_controller.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def discovery_unifi_sites(section):
158158
for _item in section.values():
159159
yield Service(item=f"{_item.desc}")
160160

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

@@ -169,7 +169,8 @@ def check_unifi_sites(item,section):
169169
#yield Metric("if_in_bps",_safe_int(site.lan_rx_bytes_r)*8)
170170
yield Metric("if_out_octets",_safe_int(site.lan_tx_bytes_r))
171171
#yield Metric("if_out_bps",_safe_int(site.lan_tx_bytes_r)*8)
172-
172+
yield Metric("lan_active_sw",_safe_int(site.lan_num_sw))
173+
yield Metric("lan_total_sw",_safe_int(site.lan_num_adopted))
173174
yield Result(
174175
state=_unifi_status2state(site.lan_status),
175176
summary=f"LAN: {site.lan_num_sw}/{site.lan_num_adopted} Switch ({site.lan_status})"
@@ -185,6 +186,8 @@ def check_unifi_sites(item,section):
185186
yield Metric("wlan_iot_sta",_safe_int(site.wlan_num_iot))
186187
yield Metric("wlan_if_in_octets",_safe_int(site.wlan_rx_bytes_r))
187188
yield Metric("wlan_if_out_octets",_safe_int(site.wlan_tx_bytes_r))
189+
yield Metric("wlan_active_ap",_safe_int(site.wlan_num_ap))
190+
yield Metric("wlan_total_ap",_safe_int(site.wlan_num_adopted))
188191
yield Result(
189192
state=_unifi_status2state(site.wlan_status),
190193
summary=f"WLAN: {site.wlan_num_ap}/{site.wlan_num_adopted} AP ({site.wlan_status})"
@@ -208,8 +211,14 @@ def check_unifi_sites(item,section):
208211
state=_unifi_status2state(site.vpn_status),
209212
notice=f"WWW Status: {site.vpn_status}"
210213
)
214+
215+
if params.get("ignore_alarms"):
216+
_alarmstate = State.OK
217+
else:
218+
_alarmstate = _expect_number(site.num_new_alarms)
219+
211220
yield Result(
212-
state=_expect_number(site.num_new_alarms),
221+
state=_alarmstate,
213222
notice=f"{site.num_new_alarms} new Alarm"
214223
)
215224

@@ -223,6 +232,8 @@ def check_unifi_sites(item,section):
223232
name='unifi_sites',
224233
service_name='Site %s',
225234
discovery_function=discovery_unifi_sites,
235+
check_default_parameters={},
236+
check_ruleset_name="unifi_sites",
226237
check_function=check_unifi_sites,
227238
)
228239

@@ -258,6 +269,7 @@ def inventory_unifi_device_shortlist(section):
258269

259270
############ DEVICE ###########
260271
def discovery_unifi_device(section):
272+
yield Service(item="Device Status")
261273
yield Service(item="Unifi Device")
262274
yield Service(item="Uptime")
263275
yield Service(item="Active-User")
@@ -271,8 +283,16 @@ def discovery_unifi_device(section):
271283
yield Service(item="Speedtest")
272284

273285
def check_unifi_device(item,section):
274-
if section.state != "1":
275-
yield IgnoreResults(f"device not active State: {section.state}")
286+
_device_state = UNIFI_DEVICE_STATES.get(section.state,"unknown")
287+
## connected OK / pending Warn / Rest Crit
288+
_hoststatus = State.OK if section.state == "1" else State.WARN if section.state == "2" else State.CRIT
289+
if item == "Device Status":
290+
yield Result(
291+
state=_hoststatus,
292+
summary=f"Status: {_device_state}"
293+
)
294+
#if section.state != "1":
295+
# yield IgnoreResults(f"device not active State: {section.state}")
276296

277297
if item == "Unifi Device":
278298
yield Result(

share/check_mk/agents/special/agent_unifi_controller

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
## SOFTWARE.
2424

2525
###
26-
__VERSION__ = 0.80
26+
__VERSION__ = 0.83
2727

2828
import sys
2929
import socket
@@ -591,7 +591,7 @@ class unifi_controller_api(object):
591591
def request(self,method,url=None,path=None,site=None,json=None,**kwargs):
592592
if not url:
593593
if self.is_unifios:
594-
url = f"{self.url}/proxy/network/api/"
594+
url = f"{self.url}/proxy/network/api"
595595
else:
596596
url = f"{self.url}/api"
597597
if site is not None:

share/check_mk/web/plugins/metrics/unifi_metrics.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,44 @@
121121
],
122122
}
123123

124+
125+
metric_info["lan_active_sw"] = {
126+
"title": _("Active Switches"),
127+
"unit": "count",
128+
"color": "13/b",
129+
}
130+
metric_info["lan_total_sw"] = {
131+
"title": _("Total Switches"),
132+
"unit": "count",
133+
"color": "13/a",
134+
}
135+
136+
graph_info["lan_active_sw_combined"] = {
137+
"title" : _("Active Switches"),
138+
"metrics" : [
139+
("lan_active_sw","area"),
140+
("lan_total_sw","line"),
141+
],
142+
}
143+
metric_info["wlan_active_ap"] = {
144+
"title": _("Active Accesspoints"),
145+
"unit": "count",
146+
"color": "13/b",
147+
}
148+
metric_info["wlan_total_ap"] = {
149+
"title": _("Total Accesspoints"),
150+
"unit": "count",
151+
"color": "13/a",
152+
}
153+
154+
graph_info["wlan_active_ap_combined"] = {
155+
"title" : _("Active Accesspoints"),
156+
"metrics" : [
157+
("wlan_active_ap","area"),
158+
("wlan_total_ap","line"),
159+
],
160+
}
161+
124162
metric_info["wlan_user_sta"] = {
125163
"title": _("WLAN User"),
126164
"unit": "count",

share/check_mk/web/plugins/wato/datasource_unifi_controller.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
from cmk.gui.i18n import _
2626
from cmk.gui.plugins.wato import (
2727
HostRulespec,
28+
CheckParameterRulespecWithItem,
2829
IndividualOrStoredPassword,
2930
rulespec_registry,
3031
)
3132
from cmk.gui.valuespec import (
3233
Dictionary,
34+
Tuple,
3335
Alternative,
3436
NetworkPort,
3537
Checkbox,
@@ -72,3 +74,28 @@ def _valuespec_special_agent_unifi_controller():
7274
valuespec=_valuespec_special_agent_unifi_controller,
7375
))
7476

77+
def _item_spec_unifi_site():
78+
return TextAscii(
79+
title=_("Site"),
80+
help=_("help Site Text")
81+
)
82+
83+
def _parameter_valuespec_unifi_site():
84+
return Dictionary(
85+
title = _("Unifi Site"),
86+
optional_keys=[],
87+
elements = [
88+
('ignore_alarms', Checkbox(title=_("Ignore Site Alarms"), default_value=False)),
89+
]
90+
)
91+
92+
rulespec_registry.register(
93+
CheckParameterRulespecWithItem(
94+
check_group_name = "unifi_sites",
95+
group=RulespecGroupCheckParametersNetworking,
96+
item_spec = _item_spec_unifi_site,
97+
match_type = "dict",
98+
parameter_valuespec=_parameter_valuespec_unifi_site,
99+
title=lambda: _("Unifi Site Parameter")
100+
)
101+
)

0 commit comments

Comments
 (0)