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 f48ab1f7 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

Delete fritzbox_smarthome_battery.py

parent ddee5ac7
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-29
# File : fritzbox_smarthome_battery.py (check plugin)
#
#
from typing import Dict
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
Result,
Service,
State,
register,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import CheckResult, DiscoveryResult
from cmk.base.plugins.agent_based.utils.fritzbox_smarthome import AvmSmartHomeDevice
def discovery_fritzbox_smarthome_battery_single(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if isinstance(section, AvmSmartHomeDevice):
if section.battery_low is not None:
yield Service()
def discovery_fritzbox_smarthome_battery_multiple(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if not isinstance(section, AvmSmartHomeDevice):
for device_id, device in section.items():
if device.battery_low is not None:
yield Service(item=str(device_id))
def check_fritzbox_smarthome_battery_single(
params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if not isinstance(section, AvmSmartHomeDevice):
return
if section.battery_low is None:
return
_battery_low = {
0: 'no',
1: 'yes',
}
_message = f'Battery low: {_battery_low.get(section.battery_low, f"unknown ({section.battery_low})")}'
if section.battery_low == 0:
yield Result(state=State.OK, summary=_message)
else:
yield Result(state=State(params.get('battery_low', 2)), summary=_message)
def check_fritzbox_smarthome_battery_multiple(
item, params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if isinstance(section, Dict):
try:
yield from check_fritzbox_smarthome_battery_single(params, section[item])
except KeyError:
return
register.check_plugin(
name='fritzbox_smarthome_battery_single',
service_name='Battery',
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_battery_single,
check_function=check_fritzbox_smarthome_battery_single,
check_ruleset_name='fritzbox_smarthome_battery_single',
check_default_parameters={}
)
register.check_plugin(
name='fritzbox_smarthome_battery_multiple',
service_name='Smarthome Battery %s',
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_battery_multiple,
check_function=check_fritzbox_smarthome_battery_multiple,
check_ruleset_name='fritzbox_smarthome_battery_multiple',
check_default_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