diff --git a/agent_based/checkpoint_mho_buffers.py b/agent_based/checkpoint_mho_buffers.py index db478d951795c8f2f49eeef7912e2db18377e47f..45607f0aac00e2ac4a0f01a5b47bf1babd20c7f4 100644 --- a/agent_based/checkpoint_mho_buffers.py +++ b/agent_based/checkpoint_mho_buffers.py @@ -45,6 +45,7 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import ( get_rate, get_value_store, IgnoreResultsError, + check_levels, render, ) @@ -61,16 +62,25 @@ class CheckPointMhoPortBuffer: label: str admin_state: str link_state: str - buffer: Dict[str, CheckPointMhoRxBuffer] + sum_frames: int + sum_octets: int + sum_discards: int + buffer: Dict[int, CheckPointMhoRxBuffer] -def parse_checkpoint_mho_buffer(string_table: StringTable) -> Dict[str, CheckPointMhoPortBuffer]: +def parse_checkpoint_mho_buffers(string_table: StringTable) -> Dict[str, CheckPointMhoPortBuffer]: section = {} for line in string_table: _0_frames, _0_octet, _0_discard, _1_frames, _1_octet, _1_discard, _2_frames, _2_octet, _2_discard, _3_frames,\ _3_octet, _3_discard, _4_frames, _4_octet, _4_discard, _5_frames, _5_octet, _5_discard, _6_frames, _6_octet,\ _6_discard, _7_frames, _7_octet, _7_discard, index, label, link_state, admin_state = line + if len(string_table) < 100: + index = f'{int(index):02}' + else: + index = f'{int(index):03}' + + sum_frames = sum_octets = sum_discards = 0 _i = 0 buffer = {} for frames, octet, discard in [ @@ -83,24 +93,30 @@ def parse_checkpoint_mho_buffer(string_table: StringTable) -> Dict[str, CheckPoi (_6_frames, _6_octet, _6_discard), (_7_frames, _7_octet, _7_discard), ]: - buffer[str(_i)] = CheckPointMhoRxBuffer( + buffer[_i] = CheckPointMhoRxBuffer( frames=int(frames) if frames.isdigit() else 0, octets=int(octet) if octet.isdigit() else 0, discard=int(discard) if discard.isdigit() else 0, ) + sum_frames += buffer[_i].frames + sum_octets += buffer[_i].octets + sum_discards += buffer[_i].discard _i += 1 - section[str(index)] = CheckPointMhoPortBuffer( + section[index] = CheckPointMhoPortBuffer( label=label, admin_state=admin_state, link_state=link_state, + sum_frames=sum_frames, + sum_octets=sum_octets, + sum_discards=sum_discards, buffer=buffer, - ) + ) return section -def discovery_checkpoint_mho_buffer(params, section: Dict[str, CheckPointMhoPortBuffer]) -> DiscoveryResult: +def discovery_checkpoint_mho_buffers(params, section: Dict[str, CheckPointMhoPortBuffer]) -> DiscoveryResult: for item in section.keys(): if params['add_admin_down'] is not True and section[item].admin_state.lower() in ['down', 'na']: continue @@ -109,56 +125,71 @@ def discovery_checkpoint_mho_buffer(params, section: Dict[str, CheckPointMhoPort yield Service(item=item) -def check_checkpoint_mho_buffer(item, params, section: Dict[str, CheckPointMhoPortBuffer]) -> CheckResult: +def check_checkpoint_mho_buffers(item, params, section: Dict[str, CheckPointMhoPortBuffer]) -> CheckResult: try: port = section[item] except KeyError: yield Result(state=State.UNKNOWN, notice='Item not found in SNMP data.') return - yield Result(state=State.OK, summary=f'Label: {port.label}') - yield Result(state=State.OK, summary=f'Admin state: {port.admin_state}') - yield Result(state=State.OK, summary=f'Link state: {port.link_state}') + yield Result(state=State.OK, notice=f'Label: {port.label}') + yield Result(state=State.OK, notice=f'Admin state: {port.admin_state}') + yield Result(state=State.OK, notice=f'Link state: {port.link_state}') now = time.time() value_store = get_value_store() metric_prefix = 'checkpoint_mho_port_buffer' - raise_ingore_res = False + raise_ignore_res = False + + for metric, value, label in [ + ('sum_octets', port.sum_octets, 'Octets'), + ('sum_frames', port.sum_frames, 'Frames'), + ('sum_discards', port.sum_discards, 'Discards'), + ]: + try: + value = get_rate(value_store, metric, now, value, raise_overflow=True, ) + except GetRateError: + raise_ignore_res = True + else: + yield from check_levels( + value=value, + label=label, + metric_name=f'{metric_prefix}_{metric}', + render_func=lambda x: f'{x:.2f}/s', + ) for buffer in port.buffer.keys(): try: value = get_rate(value_store, f'{buffer}_frames', now, port.buffer[buffer].frames, raise_overflow=True, ) except GetRateError: - raise_ingore_res = True + raise_ignore_res = True else: yield Metric(value=value, name=f'{metric_prefix}_{buffer}_frames') try: value = get_rate(value_store, f'{buffer}_octets', now, port.buffer[buffer].octets, raise_overflow=True, ) except GetRateError: - raise_ingore_res = True + raise_ignore_res = True else: yield Metric(value=value, name=f'{metric_prefix}_{buffer}_octets') try: value = get_rate(value_store, f'{buffer}_discards', now, port.buffer[buffer].discard, raise_overflow=True, ) except GetRateError: - raise_ingore_res = True + raise_ignore_res = True else: yield Metric(value=value, name=f'{metric_prefix}_{buffer}_discards') - if raise_ingore_res: + if raise_ignore_res: raise IgnoreResultsError('Initializing counters') register.snmp_section( - name='checkpoint_mho_buffer', - parse_function=parse_checkpoint_mho_buffer, + name='checkpoint_mho_buffers', + parse_function=parse_checkpoint_mho_buffers, fetch=SNMPTree( base='.1.3.6.1.4.1.2620.1.55.1', # CHECKPOINT-MIB::mhoPortsStatus oids=[ - # '3.1.1', # mhoRxBuffPortIndex - # '3.1.2', # mhoRxBuffPortLabel '3.1.3', # mhoRxBuff0Frames '3.1.4', # mhoRxBuff0Octet '3.1.5', # mhoRxBuff0Discard @@ -188,21 +219,6 @@ register.snmp_section( '4.1.2', # mhoStatePortLabel '4.1.3', # mhoStateLinkState '4.1.4', # mhoStateAdminState - # '4.1.5', # mhoStateSpeed - - # '5.1.1', # mhoSummaryPortIndex - # '5.1.2', # mhoSummaryPortLabel - # '5.1.3', # mhoSummaryLinkState - # '5.1.4', # mhoSummaryAdminState - # '5.1.5', # mhoSummarySpeed - # '5.1.6', # mhoSummaryRxFcsErr - # '5.1.7', # mhoSummaryRxErr - # '5.1.8', # mhoSummaryRxFrames - # '5.1.9', # mhoSummaryRxBytes - # '5.1.10', # mhoSummaryTxErr - # '5.1.11', # mhoSummaryTxFrames - # '5.1.12', # mhoSummaryTxBytes - ] ), detect=any_of( @@ -215,15 +231,16 @@ register.snmp_section( ) register.check_plugin( - name='checkpoint_mho_buffer', + name='checkpoint_mho_buffers', service_name='RX buffers port %s', - discovery_function=discovery_checkpoint_mho_buffer, - discovery_ruleset_name='discovery_checkpoint_mho_buffer', + discovery_function=discovery_checkpoint_mho_buffers, + discovery_ruleset_name='discovery_checkpoint_mho_buffers', discovery_default_parameters={ - 'add_admin_down': False, - 'add_link_down': False, + 'add_admin_down': True, + 'add_link_down': True, + }, + check_function=check_checkpoint_mho_buffers, + check_default_parameters={ }, - check_function=check_checkpoint_mho_buffer, - check_default_parameters={}, - check_ruleset_name='checkpoint_mho_buffer', + check_ruleset_name='checkpoint_mho_buffers', ) diff --git a/checkpoint_mho_buffers.mkp b/checkpoint_mho_buffers.mkp index e55967d7afff3677883e55211f90fc2ec9207547..8ed18242dbb00d354baea41e8187c146a775a903 100644 Binary files a/checkpoint_mho_buffers.mkp and b/checkpoint_mho_buffers.mkp differ diff --git a/packages/checkpoint_mho_buffers b/packages/checkpoint_mho_buffers index f75b7df545cab2c0164409bb2a1b939d74d2bf92..4ade262d22842664ab38fad8638a5061f39f4c8a 100644 --- a/packages/checkpoint_mho_buffers +++ b/packages/checkpoint_mho_buffers @@ -4,9 +4,10 @@ 'Tested on Orchestrator MHO-140 with R8020.SP HFA_317\n', 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['checkpoint_mho_buffers.py'], - 'web': ['plugins/metrics/checkpoint_mho_buffers.py']}, + 'web': ['plugins/metrics/checkpoint_mho_buffers.py', + 'plugins/wato/checkpoint_mho_buffers.py']}, 'name': 'checkpoint_mho_buffers', - 'num_files': 2, + 'num_files': 3, 'title': 'Check Point MHO port RX buffers', 'version': '20211130.v0.0.1', 'version.min_required': '2.0.0', diff --git a/web/plugins/metrics/checkpoint_mho_buffers.py b/web/plugins/metrics/checkpoint_mho_buffers.py index 9723e497eaf5d0c9ef691e35acc862c6b810d155..3c19faaa4e1f8d838247d0586c0864ceaee91574 100644 --- a/web/plugins/metrics/checkpoint_mho_buffers.py +++ b/web/plugins/metrics/checkpoint_mho_buffers.py @@ -32,9 +32,28 @@ while _i < 8: _i += 1 +metric_info['checkpoint_mho_port_buffer_sum_frames'] = { + 'title': _('RX buffer frames summary'), + 'unit': '1/s', + 'color': '15/a', +} +metric_info['checkpoint_mho_port_buffer_sum_octets'] = { + 'title': _('RX buffer octets summary'), + 'unit': '1/s', + 'color': '25/a', +} + +metric_info['checkpoint_mho_port_buffer_sum_discards'] = { + 'title': _('RX buffer discards summary'), + 'unit': '1/s', + 'color': f'35/a', +} + + graph_info['checkpoint_mho_port_buffer_frames'] = { 'title': _('Check Point MHO RX buffer frames'), 'metrics': [ + ('checkpoint_mho_port_buffer_sum_frames', 'line'), ('checkpoint_mho_port_buffer_0_frames', 'line'), ('checkpoint_mho_port_buffer_1_frames', 'line'), ('checkpoint_mho_port_buffer_2_frames', 'line'), @@ -49,6 +68,7 @@ graph_info['checkpoint_mho_port_buffer_frames'] = { graph_info['checkpoint_mho_port_buffer_octets'] = { 'title': _('Check Point MHO RX buffer octets'), 'metrics': [ + ('checkpoint_mho_port_buffer_sum_octets', 'line'), ('checkpoint_mho_port_buffer_0_octets', 'line'), ('checkpoint_mho_port_buffer_1_octets', 'line'), ('checkpoint_mho_port_buffer_2_octets', 'line'), @@ -63,6 +83,7 @@ graph_info['checkpoint_mho_port_buffer_octets'] = { graph_info['checkpoint_mho_port_buffer_discards'] = { 'title': _('Check Point MHO RX buffer discards'), 'metrics': [ + ('checkpoint_mho_port_buffer_sum_discards', 'line'), ('checkpoint_mho_port_buffer_0_discards', 'line'), ('checkpoint_mho_port_buffer_1_discards', 'line'), ('checkpoint_mho_port_buffer_2_discards', 'line'), diff --git a/web/plugins/wato/checkpoint_mho_buffers.py b/web/plugins/wato/checkpoint_mho_buffers.py new file mode 100644 index 0000000000000000000000000000000000000000..7fddc2ab53afd07ab47695bfaecddba42364cc32 --- /dev/null +++ b/web/plugins/wato/checkpoint_mho_buffers.py @@ -0,0 +1,89 @@ +#!/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 : 2021-12-02 +# +from cmk.gui.i18n import _ +from cmk.gui.valuespec import ( + Dictionary, + TextAscii, + MonitoringState, + FixedValue, +) + +from cmk.gui.plugins.wato import ( + CheckParameterRulespecWithItem, + rulespec_registry, + RulespecGroupCheckParametersNetworking, + RulespecGroupCheckParametersDiscovery, + HostRulespec, +) + + +# def _parameter_valuespec_checkpoint_mho_buffers(): +# return Dictionary( +# elements=[ +# ('state_admin_down', +# MonitoringState( +# title=_('State if port is Admin down'), +# help=_('Monitoring state if port is Admin down'), +# default_value=1, +# )), +# ('state_link_down', +# MonitoringState( +# title=_('State if port Link state is down'), +# help=_('Monitoring state if port link state is down'), +# default_value=2, +# )), +# ('state_speed_changed', +# MonitoringState( +# title=_('State if port speed has changed'), +# help=_('Monitoring state if port speed has changed from discovery'), +# default_value=1, +# )), +# ], +# ) +# +# +# rulespec_registry.register( +# CheckParameterRulespecWithItem( +# check_group_name='checkpoint_mho_buffers', +# group=RulespecGroupCheckParametersNetworking, +# match_type='dict', +# parameter_valuespec=_parameter_valuespec_checkpoint_mho_buffers, +# title=lambda: _('Check Point MHO buffers'), +# item_spec=lambda: TextAscii(title=_('Port index'), ), +# )) + + +def _valuespec_discovery_checkpoint_mho_buffers(): + return Dictionary( + title=_('Check Point MHO buffers'), + elements=[ + ('add_admin_down', + FixedValue( + False, + title=_('Do not add Admin down ports'), + totext=_('If enabled the plugin will not add ports in Admin down state'), + )), + ('add_link_down', + FixedValue( + False, + title=_('Do not add Link down ports'), + totext=_('If enabled the plugin will not add ports in Link down state'), + )), + ], + ) + + +rulespec_registry.register( + HostRulespec( + group=RulespecGroupCheckParametersDiscovery, + match_type='dict', + name='discovery_checkpoint_mho_buffers', + valuespec=_valuespec_discovery_checkpoint_mho_buffers, + ))