diff --git a/agent_based/cisco_asyncos_cpu.py b/agent_based/cisco_asyncos_cpu.py index 5822be0e8edda0866b4a089b7f15abb11758074d..51235007ffd2f3228fef560caa3fc45d63db9b97 100644 --- a/agent_based/cisco_asyncos_cpu.py +++ b/agent_based/cisco_asyncos_cpu.py @@ -9,13 +9,13 @@ from typing import Mapping, Dict, List, Tuple, NamedTuple -from .agent_based_api.v1.type_defs import ( +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, CheckResult, StringTable, ) -from .agent_based_api.v1 import ( +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Service, check_levels, diff --git a/agent_based/cisco_asyncos_fan.py b/agent_based/cisco_asyncos_fan.py index 13363dc0e311fc5cae4d21964e8a80acfa3f7d74..13e66181c0158755cc76f32de4cc55a853564f85 100644 --- a/agent_based/cisco_asyncos_fan.py +++ b/agent_based/cisco_asyncos_fan.py @@ -43,13 +43,13 @@ from typing import Dict, List -from .agent_based_api.v1.type_defs import ( +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, CheckResult, StringTable, ) -from .agent_based_api.v1 import ( +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Service, check_levels, diff --git a/agent_based/cisco_asyncos_license.py b/agent_based/cisco_asyncos_feature_keys.py similarity index 94% rename from agent_based/cisco_asyncos_license.py rename to agent_based/cisco_asyncos_feature_keys.py index 91f8e4205468cc5e6d00cdd44d3930e08c4e7338..4d75a73b4a4b1c43c9d46b653f2dac022255f279 100644 --- a/agent_based/cisco_asyncos_license.py +++ b/agent_based/cisco_asyncos_feature_keys.py @@ -156,7 +156,7 @@ class CiscoAsyncosLicense(NamedTuple): # ['Outbreak Filters', '2', '32542740'], # ['Sophos Anti-Virus', '2', '32542740'] # ]] -def parse_cisco_asyncos_license(string_table: List[StringTable]) -> Mapping[str, CiscoAsyncosLicense]: +def parse_cisco_asyncos_feature_keys(string_table: List[StringTable]) -> Mapping[str, CiscoAsyncosLicense]: licenses = {} for license, isperpetual, secondsuntilexpire in string_table[0]: licenses.update({license: CiscoAsyncosLicense( @@ -182,12 +182,12 @@ def parse_cisco_asyncos_license(string_table: List[StringTable]) -> Mapping[str, # 'Sophos Anti-Virus': CiscoAsyncosLicense(perpetual=False, secondsuntilexpire=32542740, daysuntilexpire=376, expiredate='06 Apr 2022') # } -def discovery_cisco_asyncos_license(section: Mapping[str, CiscoAsyncosLicense]) -> DiscoveryResult: +def discovery_cisco_asyncos_feature_keys(section: Mapping[str, CiscoAsyncosLicense]) -> DiscoveryResult: yield Service() # Parameters({'expire': (400, 360), 'features_ignore': ['Data Loss Prevention']}) -def check_cisco_asyncos_license(params, section: Mapping[str, CiscoAsyncosLicense]) -> CheckResult: +def check_cisco_asyncos_feature_keys(params, section: Mapping[str, CiscoAsyncosLicense]) -> CheckResult: features_ignore = params.get('features_ignore', []) warn, crit = params.get('expire') ignore_count = 0 @@ -215,8 +215,8 @@ def check_cisco_asyncos_license(params, section: Mapping[str, CiscoAsyncosLicens register.snmp_section( - name='cisco_asyncos_license', - parse_function=parse_cisco_asyncos_license, + name='cisco_asyncos_feature_keys', + parse_function=parse_cisco_asyncos_feature_keys, fetch=[ SNMPTree( base='.1.3.6.1.4.1.15497.1.1.1.12.1', # ASYNCOS-MAIL-MIB::keyExpirationEntry @@ -231,10 +231,10 @@ register.snmp_section( ) register.check_plugin( - name='cisco_asyncos_license', - service_name='License', - discovery_function=discovery_cisco_asyncos_license, - check_function=check_cisco_asyncos_license, + name='cisco_asyncos_feature_keys', + service_name='Feature keys', + discovery_function=discovery_cisco_asyncos_feature_keys, + check_function=check_cisco_asyncos_feature_keys, check_default_parameters={'expire': (30, 7)}, - check_ruleset_name='cisco_asyncos_license', + check_ruleset_name='cisco_asyncos_feature_keys', ) diff --git a/agent_based/cisco_asyncos_power.py b/agent_based/cisco_asyncos_power.py index d63ef493ccd8b12234a58fff0361e55f80b345b8..2ea635ef64099d743702862c95cbc8b86ee8a8ad 100644 --- a/agent_based/cisco_asyncos_power.py +++ b/agent_based/cisco_asyncos_power.py @@ -34,13 +34,13 @@ from typing import Dict, List, NamedTuple -from .agent_based_api.v1.type_defs import ( +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, CheckResult, StringTable, ) -from .agent_based_api.v1 import ( +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Service, Result, diff --git a/agent_based/cisco_asyncos_temp.py b/agent_based/cisco_asyncos_temp.py index a8b476951c5e479a2922425985ea42a049f88fbf..d2d0fe1862d19175b27378a1ea518925b667732b 100644 --- a/agent_based/cisco_asyncos_temp.py +++ b/agent_based/cisco_asyncos_temp.py @@ -24,13 +24,13 @@ from typing import Mapping, Dict, List, Tuple, NamedTuple -from .agent_based_api.v1.type_defs import ( +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( DiscoveryResult, CheckResult, StringTable, ) -from .agent_based_api.v1 import ( +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Service, check_levels, @@ -38,7 +38,7 @@ from .agent_based_api.v1 import ( contains, ) -from .utils.temperature import ( +from cmk.base.plugins.agent_based.utils.temperature import ( check_temperature, TempParamType, ) diff --git a/agent_based/cisco_asyncos_update.py b/agent_based/cisco_asyncos_updates.py similarity index 68% rename from agent_based/cisco_asyncos_update.py rename to agent_based/cisco_asyncos_updates.py index 3e18099e4a3eefa9410170b9867c9c7661f6002c..db567ceb11480cd6540e79e69f7d821881f58aad 100644 --- a/agent_based/cisco_asyncos_update.py +++ b/agent_based/cisco_asyncos_updates.py @@ -7,7 +7,7 @@ # URL : https://thl-cmk.hopto.org # Date : 2020-02-19 # -# 2020-05-14: added wato oprion to ignore items +# 2020-05-14: added wato option to ignore items # 2021-03-25: rewrite for CMK2.0 # # @@ -148,14 +148,17 @@ from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Service, - check_levels, Result, SNMPTree, contains, State, - render, + Metric, ) +from cmk.base.item_state import ( + get_item_state, + set_item_state, +) class CiscoAsyncosUpdate(NamedTuple): updates: int @@ -178,7 +181,7 @@ class CiscoAsyncosUpdate(NamedTuple): # ['support_request', '1', '0'], # ['timezones', '1', '0'] # ]] -def parse_cisco_asyncos_update(string_table: List[StringTable]) -> Mapping[str, CiscoAsyncosUpdate]: +def parse_cisco_asyncos_updates(string_table: List[StringTable]) -> Mapping[str, CiscoAsyncosUpdate]: features = {} for feature, updates, update_failures in string_table[0]: features.update({feature: CiscoAsyncosUpdate( @@ -204,90 +207,76 @@ def parse_cisco_asyncos_update(string_table: List[StringTable]) -> Mapping[str, # 'support_request': CiscoAsyncosUpdate(updates=1, updatefailures=0), # 'timezones': CiscoAsyncosUpdate(updates=1, updatefailures=0) # } -def discovery_cisco_asyncos_update(section:Mapping[str, CiscoAsyncosUpdate])-> DiscoveryResult: +def discovery_cisco_asyncos_updates(section:Mapping[str, CiscoAsyncosUpdate])-> DiscoveryResult: yield Service() -def check_cisco_asyncos_update(params, section:Mapping[str, CiscoAsyncosUpdate]) -> CheckResult: +def check_cisco_asyncos_updates(params, section:Mapping[str, CiscoAsyncosUpdate]) -> CheckResult: features_ignore = params.get('features_ignore', []) warn, crit = params.get('failedLevel') ignore_count = 0 for feature in section.keys(): - if feature in features_ignore: - yield Result(state=State.OK, notice='Feature %s: %d/%d updates/update failures. Feature ignored!' % (feature, section[feature].updates, section[feature].updatefailures)) - ignore_count += 1 + failed = section[feature].updatefailures + passed = section[feature].updates + + # read counters + passedLast = get_item_state('cisco_asyncos_updates_%s_passedLast' % feature) + failedLast = get_item_state('cisco_asyncos_updates_%s_failedLast' % feature) + failedAttempts = get_item_state('cisco_asyncos_updates_%s_failedAttempts' % feature) + + # print('Feature %s, passed: %s/%s failed: %s/%s, Attempts: %s' % (feature, passed,passedLast, failed,failedLast, failedAttempts)) + + if (passedLast == None) or (failedLast == None) or (failedAttempts == None): # or (lastState == None): + # init counters + set_item_state('cisco_asyncos_updates_%s_passedLast' % feature, passed) + set_item_state('cisco_asyncos_updates_%s_failedLast' % feature, failed) + set_item_state('cisco_asyncos_updates_%s_failedAttempts' % feature, 0) else: - yield Result(state=State.OK, notice='Feature %s: %d/%d updates/update failures. Feature ignored!' % (feature, section[feature].updates, section[feature].updatefailures)) + set_item_state('cisco_asyncos_updates_%s_passedLast' % feature, passed) + set_item_state('cisco_asyncos_updates_%s_failedLast' % feature, failed) + passedLast = int(passedLast) + failedLast = int(failedLast) + failedAttempts = int(failedAttempts) - yield Result(state=State.OK, summary='%d/%d Features found/ignored' % (len(section.keys()), ignore_count)) + # reset counter if overrun + if failed < failedLast: + set_item_state('cisco_asyncos_updates_%s_failedLast' % feature, failed) + failedLast = failed + if passed < passedLast: + set_item_state('cisco_asyncos_updates_%s_passedLast' % feature, passed) + passedLast = passed + + if passed > passedLast: + # reset error counter after passed update attempt + set_item_state('cisco_asyncos_updates_%s_failedAttempts' % feature, 0) + else: + failedAttempts = failedAttempts + failed - failedLast + set_item_state('cisco_asyncos_updates_%s_failedAttempts' % feature, failedAttempts) + if feature in features_ignore: + yield Result(state=State.OK, notice='%s: %d/%d updates/update failures. Feature ignored!' % (feature, passed, failed)) + ignore_count += 1 + else: + if failedAttempts >= crit: + yield Result(state=State.CRIT, notice='%s: %d/%d passed/failed.' % (feature, passed, failed)) + lastState=-1 + elif failedAttempts >= warn: + yield Result(state=State.WARN, notice='%s: %d/%d passed/failed.' % (feature, passed, failed)) + lastState=-1 + else: + yield Result(state=State.OK, notice='%s: %d/%d passed/failed.' % (feature, passed, failed)) + lastState=1 - # if len(info) > 0: - # infotext = '' - # longoutput = '' - # perfdata = [] - # failedItemsWarn = [] - # failedItemsCrit = [] - # failedWarn, failedCrit = params.get('failedLevel') - # features_ignore = params['features_ignore'] - # lastState = 1 - # - # for line in info: - # name, passed, failed = line - # longoutput += '\n%s: %s/%s passed/failed attempt(s)' % (name, passed, failed) - # # read counters - # passedLast = get_item_state('cisco_asyncos_update_%s_passedLast' % name) - # failedLast = get_item_state('cisco_asyncos_update_%s_failedLast' % name) - # failedAttempts = get_item_state('cisco_asyncos_update_%s_failedAttempts' % name) - # - # if (passedLast == None) or (failedLast == None) or (failedAttempts == None): # or (lastState == None): - # # init counters - # set_item_state('cisco_asyncos_update_%s_passedLast' % name, passed) - # set_item_state('cisco_asyncos_update_%s_failedLast' % name, failed) - # set_item_state('cisco_asyncos_update_%s_failedAttempts' % name, 0) - # else: - # set_item_state('cisco_asyncos_update_%s_passedLast' % name, passed) - # set_item_state('cisco_asyncos_update_%s_failedLast' % name, failed) - # passedLast = int(passedLast) - # failedLast = int(failedLast) - # failedAttempts = int(failedAttempts) - # failed = int(failed) - # passed = int(passed) - # # reset counter if overrun - # if failed < failedLast: - # set_item_state('cisco_asyncos_update_%s_failedLast' % name, failed) - # failedLast = failed - # if passed < passedLast: - # set_item_state('cisco_asyncos_update_%s_passedLast' % name, passed) - # passedLast = passed - # - # if passed > passedLast: - # # rest error counter after passed update attempt - # set_item_state('cisco_asyncos_update_%s_failedAttempts' % name, 0) - # else: - # failedAttempts = failedAttempts + failed - failedLast - # set_item_state('cisco_asyncos_update_%s_failedAttempts' % name, failedAttempts) - # if name not in features_ignore: - # if failedAttempts >= failedCrit: - # failedItemsCrit.append(name) - # lastState = -1 - # elif failedAttempts >= failedWarn: - # failedItemsWarn.append(name) - # lastState = -1 - # - # perfdata.append((name.replace(' ', '_'), lastState, None, None, -1, 1)) - # - # infotext += '%d item(s) found' % len(info) - # if len(failedItemsCrit) > 0: - # yield 2, '%d failed item(s) (%s), failed attempts >= %d' % (len(failedItemsCrit), ', '.join(failedItemsCrit), failedCrit) - # if len(failedItemsWarn) > 0: - # yield 1, '%d failed item(s) (%s), failed attempts >= %d' % (len(failedItemsWarn), ', '.join(failedItemsWarn), failedWarn) - # - # yield 0, infotext + longoutput, perfdata + yield Metric( + name=feature.replace(' ', '_'), + value=lastState, + boundaries=(2,-2) + ) + yield Result(state=State.OK, summary='%d/%d Features found/ignored' % (len(section.keys()), ignore_count)) register.snmp_section( - name='cisco_asyncos_update', - parse_function=parse_cisco_asyncos_update, + name='cisco_asyncos_updates', + parse_function=parse_cisco_asyncos_updates, fetch=[ SNMPTree( base='.1.3.6.1.4.1.15497.1.1.1.13.1', # ASYNCOS-MAIL-MIB::updateEntry @@ -302,11 +291,11 @@ register.snmp_section( ) register.check_plugin( - name='cisco_asyncos_update', - service_name='Update', - discovery_function=discovery_cisco_asyncos_update, - check_function=check_cisco_asyncos_update, + name='cisco_asyncos_updates', + service_name='Updates', + discovery_function=discovery_cisco_asyncos_updates, + check_function=check_cisco_asyncos_updates, check_default_parameters={'failedLevel': (5, 10)}, - check_ruleset_name='cisco_asyncos_update', + check_ruleset_name='cisco_asyncos_updates', ) diff --git a/cisco_asyncos.mkp b/cisco_asyncos.mkp index c654bdad2d4fea5d73745de47ea1d405cbb3442f..3102a3f16c6c7ba54cb850112f5f2df6cb36ff9b 100644 Binary files a/cisco_asyncos.mkp and b/cisco_asyncos.mkp differ diff --git a/packages/cisco_asyncos b/packages/cisco_asyncos index 09191723e0028ac4a00a680683a572f84e2dd008..ab2cde272c85fd3623ae69b8801b9707546adc2e 100644 --- a/packages/cisco_asyncos +++ b/packages/cisco_asyncos @@ -37,12 +37,12 @@ 'cisco_asyncos_messageage.py', 'cisco_asyncos_queue.py', 'cisco_asyncos_resources.py', - 'cisco_asyncos_license.py', - 'cisco_asyncos_update.py'], - 'web': ['plugins/wato/cisco_asyncos_license.py', - 'plugins/wato/cisco_asyncos_queue.py', - 'plugins/wato/cisco_asyncos_update.py', - 'plugins/metrics/cisco_asyncos.py']}, + 'cisco_asyncos_feature_keys.py', + 'cisco_asyncos_updates.py'], + 'web': ['plugins/wato/cisco_asyncos_queue.py', + 'plugins/metrics/cisco_asyncos.py', + 'plugins/wato/cisco_asyncos_feature_keys.py', + 'plugins/wato/cisco_asyncos_updates.py']}, 'name': 'cisco_asyncos', 'num_files': 19, 'title': 'Cisco AsyncOS (IronPort) checks', diff --git a/web/plugins/wato/cisco_asyncos_feature_keys.py b/web/plugins/wato/cisco_asyncos_feature_keys.py new file mode 100644 index 0000000000000000000000000000000000000000..47cc786117944628a684fbd0b709ba8e1ad78ae6 --- /dev/null +++ b/web/plugins/wato/cisco_asyncos_feature_keys.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# +from cmk.gui.i18n import _ +from cmk.gui.valuespec import ( + Dictionary, + Integer, + TextAscii, + ListOfStrings, + Tuple, +) + +from cmk.gui.plugins.wato import ( + CheckParameterRulespecWithItem, + rulespec_registry, + RulespecGroupCheckParametersNetworking, +) + + +def _parameter_valuespec_cisco_asyncos_feature_keys(): + return Dictionary(elements=[ + ('features_ignore', + ListOfStrings( + title=_('feature keys features to ignore'), + orientation='vertical', + allow_empty=False, + help=_('there will be no warning/critical if this features are expired' + 'Examples: McAfee, IronPort Email Encryption, Data Loss Prevention, etc.'), + ) + ), + ('expire', + Tuple( + title=_('Levels for feature key expiration in days'), + elements=[ + Integer(title=_('Warning'), default_value=30, unit=_('days before expiration')), + Integer(title=_('Critical'), default_value=7, unit=_('days before expiration')), + ])), + ]) + + +rulespec_registry.register( + CheckParameterRulespecWithItem( + check_group_name='cisco_asyncos_feature_keys', + group=RulespecGroupCheckParametersNetworking, + item_spec=lambda: TextAscii(title=_('Cisco AsyncOS feature keys'), ), + match_type='dict', + parameter_valuespec=_parameter_valuespec_cisco_asyncos_feature_keys, + title=lambda: _('Cisco AsyncOS feature keys'), + )) diff --git a/web/plugins/wato/cisco_asyncos_updates.py b/web/plugins/wato/cisco_asyncos_updates.py new file mode 100644 index 0000000000000000000000000000000000000000..9344a58ca9fbaa6c53fb959a5ad3e11ba8dbed56 --- /dev/null +++ b/web/plugins/wato/cisco_asyncos_updates.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# +from cmk.gui.i18n import _ +from cmk.gui.valuespec import ( + Dictionary, + Integer, + TextAscii, + ListOfStrings, + Tuple, +) + +from cmk.gui.plugins.wato import ( + CheckParameterRulespecWithItem, + rulespec_registry, + RulespecGroupCheckParametersNetworking, +) + + +def _parameter_valuespec_cisco_asyncos_updates(): + return Dictionary(elements=[ + ('features_ignore', + ListOfStrings( + title=_('Update features to ignore'), + orientation='vertical', + help=_('there will be no warning/critical if this features are not updated' + 'Examples: geo_countries, timezones, etc.'), + ) + ), + ('failedLevel', + Tuple( + title=_('Levels for failed attempts'), + elements=[ + Integer(title=_('Warning'), default_value=5, unit=_('# of failed attempts')), + Integer(title=_('Critical'), default_value=10, unit=_('# of failed attempts')), + ])), + ]) + + +rulespec_registry.register( + CheckParameterRulespecWithItem( + check_group_name='cisco_asyncos_updates', + group=RulespecGroupCheckParametersNetworking, + item_spec=lambda: TextAscii(title=_('Cisco AsyncOS updates'), ), + match_type='dict', + parameter_valuespec=_parameter_valuespec_cisco_asyncos_updates, + title=lambda: _('Cisco AsyncOS updates'), + ))