diff --git a/agent_based/checkpoint_powersupply.py b/agent_based/checkpoint_powersupply.py new file mode 100644 index 0000000000000000000000000000000000000000..5a65d5c26b01b6c344c544e3b359b20711aa12c0 --- /dev/null +++ b/agent_based/checkpoint_powersupply.py @@ -0,0 +1,115 @@ +#!/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 : 2018-07-31 +# +# Monitor status of Check Point appliance power supply +# +# 2020-06-08: changed snmp-scan function +# 2021-08-10: rewritten for CMK 2.0 +# added WATO +# +# +# ToDo: remove VSX... +# +# sample snmpwalk (two power supplys) +# +# CHECKPOINT-MIB::powerSupplyIndex.1.0 = INTEGER: 1 +# CHECKPOINT-MIB::powerSupplyIndex.2.0 = INTEGER: 2 +# CHECKPOINT-MIB::powerSupplyStatus.1.0 = STRING: Up +# CHECKPOINT-MIB::powerSupplyStatus.2.0 = STRING: Up +# +# +# .1.3.6.1.4.1.2620.1.6.7.9.1.1.1.1.0 = INTEGER: 1 +# .1.3.6.1.4.1.2620.1.6.7.9.1.1.1.2.0 = INTEGER: 2 +# .1.3.6.1.4.1.2620.1.6.7.9.1.1.2.1.0 = STRING: Up +# .1.3.6.1.4.1.2620.1.6.7.9.1.1.2.2.0 = STRING: Up + +# +# +# sample section +# smart-1 5150 +# {'1': 'Present', '2': 'Present'} +# 23800 appliance +# {'1': 'Up', '2': 'Up'} + +from typing import Dict, Optional + +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( + DiscoveryResult, + CheckResult, + StringTable, +) + +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( + register, + Service, + equals, + Result, + State, + SNMPTree, + startswith, + all_of, + any_of, +) + + +def parse_checkpoint_powersupply(string_table: StringTable) -> Dict[str, str]: + powersupplys = {} + for psindex, psstatus in string_table: + if psindex.isdigit(): + powersupplys.update({psindex: psstatus}) + + return powersupplys + + +def discovery_checkpoint_powersupply(section: Dict[str, str]) -> DiscoveryResult: + for key in section.keys(): + yield Service(item=key) + + +def check_checkpoint_powersupply(item, params, section: Dict[str, str]) -> Optional[CheckResult]: + try: + psstatus = section[item] + except KeyError: + return + + if psstatus.lower() in ['up', 'present']: + yield Result(state=State.OK, summary=f'Status: {psstatus}') + else: + yield Result(state=State(params['ps_not_up']), summary=f'Status: {psstatus}') + + +register.snmp_section( + name='checkpoint_powersupply', + parse_function=parse_checkpoint_powersupply, + fetch=SNMPTree( + base='.1.3.6.1.4.1.2620.1.6.7.9.1.1', # CHECKPOINT-MIB::powerSupplyEntry + oids=[ + '1', # powerSupplyIndex + '2', # powerSupplyStatus + ] + ), + detect=any_of( + startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.2620'), + all_of( + equals('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.8072.3.2.10'), + equals('.1.3.6.1.4.1.2620.1.6.1.0', 'SVN Foundation'), + ) + ) +) + +register.check_plugin( + name='checkpoint_powersupply', + service_name='Power Supply %s', + discovery_function=discovery_checkpoint_powersupply, + check_function=check_checkpoint_powersupply, + check_default_parameters={ + 'ps_not_up': 2 + }, + check_ruleset_name='checkpoint_powersupply', +) diff --git a/checkpoint_powersupply.mkp b/checkpoint_powersupply.mkp index b2633f067d99ebb4deb896c616024b283e1161c2..8911bbf6b847123e369b5bb27d0105bf049a5f2c 100644 Binary files a/checkpoint_powersupply.mkp and b/checkpoint_powersupply.mkp differ diff --git a/packages/checkpoint_powersupply b/packages/checkpoint_powersupply index 992276ab520254bf2ab6c1a5fa64ce288cb87358..8787d7ac60b181c1cf456099d0c8145727968d3a 100644 --- a/packages/checkpoint_powersupply +++ b/packages/checkpoint_powersupply @@ -1,10 +1,16 @@ -{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)', - 'description': u'Monitor Check Point appliance power supply status\n\n- critical if state not "up".\n- no perfdata\n- no wato\n', +{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', + 'description': 'Monitor Check Point appliance power supply status\n' + '\n' + 'critical if state not "Up"/"Present", can be configured via ' + 'WATO\n', 'download_url': 'https://thl-cmk.hopto.org', - 'files': {'checks': ['checkpoint_powersupply']}, + 'files': {'agent_based': ['checkpoint_powersupply.py'], + 'checkman': ['checkpoint_powersupply'], + 'web': ['plugins/wato/checkpoint_powersupply.py']}, 'name': 'checkpoint_powersupply', - 'num_files': 1, - 'title': u'Check Point power supply status', - 'version': '20180731.v0.0.1', - 'version.min_required': '1.2.8b8', - 'version.packaged': '1.4.0p38'} \ No newline at end of file + 'num_files': 3, + 'title': 'Check Point power supply status', + 'version': '20210810.v0.0.2', + 'version.min_required': '2.0.0', + 'version.packaged': '2021.07.14', + 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/wato/checkpoint_powersupply.py b/web/plugins/wato/checkpoint_powersupply.py new file mode 100644 index 0000000000000000000000000000000000000000..5f5ee3c5fe7a1efec87707e30c580351fe24e1f0 --- /dev/null +++ b/web/plugins/wato/checkpoint_powersupply.py @@ -0,0 +1,41 @@ +#!/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 +# +from cmk.gui.i18n import _ +from cmk.gui.valuespec import ( + Dictionary, + TextAscii, + MonitoringState, +) + +from cmk.gui.plugins.wato import ( + CheckParameterRulespecWithItem, + rulespec_registry, + RulespecGroupCheckParametersNetworking, +) + + +def _parameter_valuespec_checkpoint_powersupply(): + return Dictionary(elements=[ + ('ps_not_up', + MonitoringState( + default_value=2, + title=_('State if power supply is not "UP" or "Present".'), + )), + ]) + + +rulespec_registry.register( + CheckParameterRulespecWithItem( + check_group_name='checkpoint_powersupply', + group=RulespecGroupCheckParametersNetworking, + item_spec=lambda: TextAscii(title=_('Power Supply index'), ), + match_type='dict', + parameter_valuespec=_parameter_valuespec_checkpoint_powersupply, + title=lambda: _('Check Point Power Supply'), + ))