Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit d7296950 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

Delete fritzbox_smarthome.py

parent a97226b3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2023-12-28
# File : fritzbox_smarthome.py (check plugin)
#
# Based on the work of Maximilian Clemens, see https://github.com/MaximilianClemens/checkmk_fritzbox
#
#
import json
from typing import Dict
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
Result,
Service,
State,
register,
HostLabel,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
CheckResult,
DiscoveryResult,
HostLabelGenerator,
StringTable,
)
from cmk.base.plugins.agent_based.utils.fritzbox_smarthome import (
AvmSmartHomeDevice,
parse_avm_smarthome_device,
)
def host_label_fritzbox_smarthome(section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]) -> HostLabelGenerator:
yield HostLabel(name="fritz/smarthome/device", value="yes")
if isinstance(section, AvmSmartHomeDevice): # piggyback
yield HostLabel(
name="fritz/smarthome/device_type",
value=section.product_name.replace(' ', '_').lower()
)
def parse_fritzbox_smarthome(string_table: StringTable) -> AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice] | None:
try:
raw_devices = json.loads(str(string_table[0][0]))
except json.JSONDecodeError:
return
if isinstance(raw_devices, Dict):
return parse_avm_smarthome_device(raw_devices)
else:
return {raw_device['id']: parse_avm_smarthome_device(raw_device) for raw_device in raw_devices}
register.agent_section(
name="fritzbox_smarthome",
parse_function=parse_fritzbox_smarthome,
host_label_function=host_label_fritzbox_smarthome,
)
def discovery_fritzbox_smarthome_single(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if isinstance(section, AvmSmartHomeDevice):
yield Service()
def discovery_fritzbox_smarthome_multiple(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if not isinstance(section, AvmSmartHomeDevice):
for device_id, device in section.items():
yield Service(item=str(device_id))
def check_fritzbox_smarthome_single(
params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if not isinstance(section, AvmSmartHomeDevice):
return
_tx_busy = {
0: 'no',
1: 'yes',
}
yield Result(
state=State.OK,
notice=f'Device: {section.manufacturer} {section.product_name}, FW: {section.fw_version}'
)
if section.present == 0:
yield Result(state=State(params['present']), summary='Device is offline')
# stop if device is not present
return
yield Result(state=State.OK, summary='Device is online')
if section.tx_busy is not None:
yield Result(
state=State.OK,
notice=f'Sending command: {_tx_busy.get(section.tx_busy, f"unknown ({section.tx_busy})")}'
)
def check_fritzbox_smarthome_multiple(
item, params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if isinstance(section, Dict):
try:
device = section[item]
except KeyError:
return
yield from check_fritzbox_smarthome_single(params, device)
yield Result(state=State.OK, summary=f'[{device.name}]')
_fritzbox_smarthome_parameters = {
'present': 1,
}
register.check_plugin(
name="fritzbox_smarthome_single",
service_name="Device status",
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_single,
check_function=check_fritzbox_smarthome_single,
check_ruleset_name="fritzbox_smarthome_single",
check_default_parameters=_fritzbox_smarthome_parameters,
)
register.check_plugin(
name="fritzbox_smarthome_multiple",
service_name="Smarthome Device status %s",
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_multiple,
check_function=check_fritzbox_smarthome_multiple,
check_ruleset_name="fritzbox_smarthome_multiple",
check_default_parameters=_fritzbox_smarthome_parameters,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment