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

Delete fritzbox_smarthome_power_socket.py

parent b8cba490
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-30
# File : fritzbox_smarthome_power_socket.py (check plugin)
#
#
from typing import Dict
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
Service,
register,
Result,
State,
)
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_power_socket_single(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if isinstance(section, AvmSmartHomeDevice):
if section.switch is not None:
yield Service()
def discovery_fritzbox_smarthome_power_socket_multiple(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if not isinstance(section, AvmSmartHomeDevice):
for device_id, device in section.items():
if device.switch is not None:
yield Service(item=str(device_id))
def check_fritzbox_smarthome_power_socket_single(
params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if not isinstance(section, AvmSmartHomeDevice):
return
if not section.switch:
return
def _get_status(status: int):
_switch_state = {
0: 'off',
1: 'on',
}
return _switch_state.get(status, f'unknown ({status})')
yield Result(state=State.OK, summary=f'State: {_get_status(section.switch.state)}')
yield Result(state=State.OK, summary=f'Mode: {section.switch.mode}')
def check_fritzbox_smarthome_power_socket_multiple(
item, params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if isinstance(section, Dict):
try:
yield from check_fritzbox_smarthome_power_socket_single(params, section[item])
except KeyError:
return
register.check_plugin(
name='fritzbox_smarthome_power_socket_single',
service_name='Power socket',
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_power_socket_single,
check_function=check_fritzbox_smarthome_power_socket_single,
# check_ruleset_name='fritzbox_smarthome_power_socket',
check_default_parameters={}
)
register.check_plugin(
name='fritzbox_smarthome_power_socket_multiple',
service_name='Smarthome Power socket %s',
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_power_socket_multiple,
check_function=check_fritzbox_smarthome_power_socket_multiple,
# check_ruleset_name='fritzbox_smarthome_power_socket',
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