diff --git a/agent_based/cisco_asyncos_mem.py b/agent_based/cisco_asyncos_mem.py index 55f19f0e98a1a5d63850baa90e53ea64bb756af3..f50d747dd751ecec25e4f6eba6d6964a578da2ad 100644 --- a/agent_based/cisco_asyncos_mem.py +++ b/agent_based/cisco_asyncos_mem.py @@ -19,13 +19,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, @@ -60,7 +60,7 @@ def check_cisco_asyncos_mem(params, section: int) -> CheckResult: section, label='Memory utilization', levels_upper=params.get('util', None), - metric_name='util', # if params.get('output_metrics') else None, + metric_name='util', render_func=render_percent, ) diff --git a/agent_based/cisco_asyncos_raid.py b/agent_based/cisco_asyncos_raid.py new file mode 100644 index 0000000000000000000000000000000000000000..be917e5472a162c67580781ac9dfae1ac2014886 --- /dev/null +++ b/agent_based/cisco_asyncos_raid.py @@ -0,0 +1,140 @@ +#!/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 : 2020-02-10 +# +# +# monitors status raid arrays of Cisco IronPort Appliances (ESA/SMA/WSA) +# Tested with: C380, M380, C370, M670, S370 +# +# 2021-03-24: rewrite for CMK 2.0 +# +# OMD[cmk16x]:~$ snmpwalk -v2c -c C370-MAIL localhost -m ASYNCOS-MAIL-MIB -ObentU raidTable +# .1.3.6.1.4.1.15497.1.1.1.18.1.1.1 = INTEGER: 1 +# .1.3.6.1.4.1.15497.1.1.1.18.1.1.2 = INTEGER: 2 +# .1.3.6.1.4.1.15497.1.1.1.18.1.2.1 = INTEGER: 1 +# .1.3.6.1.4.1.15497.1.1.1.18.1.2.2 = INTEGER: 1 +# .1.3.6.1.4.1.15497.1.1.1.18.1.3.1 = STRING: Drive 0 +# .1.3.6.1.4.1.15497.1.1.1.18.1.3.2 = STRING: Drive 1 +# .1.3.6.1.4.1.15497.1.1.1.18.1.4.1 = STRING: No Errors +# .1.3.6.1.4.1.15497.1.1.1.18.1.4.2 = STRING: No Errors +# +# OMD[cmk16x]:~$ snmpwalk -v2c -c C370-MAIL localhost -m ASYNCOS-MAIL-MIB raidTable +# ASYNCOS-MAIL-MIB::raidIndex.1 = INTEGER: 1 +# ASYNCOS-MAIL-MIB::raidIndex.2 = INTEGER: 2 +# ASYNCOS-MAIL-MIB::raidStatus.1 = INTEGER: driveHealthy(1) +# ASYNCOS-MAIL-MIB::raidStatus.2 = INTEGER: driveHealthy(1) +# ASYNCOS-MAIL-MIB::raidID.1 = STRING: Drive 0 +# ASYNCOS-MAIL-MIB::raidID.2 = STRING: Drive 1 +# ASYNCOS-MAIL-MIB::raidLastError.1 = STRING: No Errors +# ASYNCOS-MAIL-MIB::raidLastError.2 = STRING: No Errors +# +from typing import Mapping, List, NamedTuple + +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, + Result, + SNMPTree, + contains, + State, +) + + +class CiscoAsyncosRaid(NamedTuple): + state: State + status_readable: str + lasterror: str + + +def get_cmk_state(st: str) -> State: + states = { + '1': State.OK, + '2': State.CRIT, + '3': State.WARN + } + return states.get(st, State.CRIT) + + +def get_status_readable(st: str) -> str: + states = { + '1': 'healthy', + '2': 'failure', + '3': 'rebuild', + } + return states.get(st, st) + + +# [[ +# ['1', 'Drive 0', 'No Errors'], +# ['2', 'Drive 1', 'UNKNOWN'], +# ['1', 'Drive 2', 'No Errors'], +# ['1', 'Drive 3', 'No Errors'], +# ['1', 'Drive 4', 'No Errors'], +# ['1', 'Drive 5', 'No Errors'] +# ]] +def parse_cisco_asyncos_raid(string_table: List[StringTable]) -> Mapping[str, CiscoAsyncosRaid]: + arrays = {} + for raidStatus, raidID, raidLastError in string_table[0]: + arrays.update({raidID: CiscoAsyncosRaid( + state=get_cmk_state(raidStatus), + status_readable=get_status_readable(raidStatus), + lasterror=raidLastError + )}) + return arrays + + +# { +# 'Drive 0': CiscoAsyncosRaid(state=<State.OK: 0>, status_readable='Ok', lasterror='No Errors'), +# 'Drive 1': CiscoAsyncosRaid(state=<State.CRIT: 2>, status_readable='failure', lasterror='UNKNOWN'), +# 'Drive 2': CiscoAsyncosRaid(state=<State.OK: 0>, status_readable='Ok', lasterror='No Errors'), +# 'Drive 3': CiscoAsyncosRaid(state=<State.OK: 0>, status_readable='Ok', lasterror='No Errors'), +# 'Drive 4': CiscoAsyncosRaid(state=<State.OK: 0>, status_readable='Ok', lasterror='No Errors'), +# 'Drive 5': CiscoAsyncosRaid(state=<State.OK: 0>, status_readable='Ok', lasterror='No Errors') +# } + +def discovery_cisco_asyncos_raid(section: Mapping[str, CiscoAsyncosRaid]) -> DiscoveryResult: + yield from (Service(item=item) for item in section.keys()) + + +def check_cisco_asyncos_raid(item, section: Mapping[str, CiscoAsyncosRaid]) -> CheckResult: + try: + yield Result(state=section[item].state, + summary='RAID status: %s, last error: %s' % (section[item].state, section[item].lasterror), + ) + except KeyError: + pass + + +register.snmp_section( + name='cisco_asyncos_raid', + parse_function=parse_cisco_asyncos_raid, + fetch=[ + SNMPTree( + base='.1.3.6.1.4.1.15497.1.1.1.18.1', # ASYNCOS-MAIL-MIB::raidEntry + oids=[ + '2', # raidStatus + '3', # raidID + '4', # raidLastError + ] + ), + ], + detect=contains('.1.3.6.1.2.1.1.1.0', 'AsyncOS'), +) + +register.check_plugin( + name='cisco_asyncos_raid', + service_name='RAID %s', + discovery_function=discovery_cisco_asyncos_raid, + check_function=check_cisco_asyncos_raid, +) diff --git a/checks/cisco_asyncos_raid b/checks/cisco_asyncos_raid deleted file mode 100644 index 1aed36da7298814fccf1104d1ea2a55acf5b9a56..0000000000000000000000000000000000000000 --- a/checks/cisco_asyncos_raid +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# -# Author: Th.L. -# Date: 10-02-2020 -# -# monitors status raid arrays of Cisco IronPort Appliances (ESA/SMA/WSA) -# Tested with: C380, M380, C370, M670, S370 -# -# -# -# OMD[cmk16x]:~$ snmpwalk -v2c -c C370-MAIL localhost -m ASYNCOS-MAIL-MIB -ObentU raidTable -# .1.3.6.1.4.1.15497.1.1.1.18.1.1.1 = INTEGER: 1 -# .1.3.6.1.4.1.15497.1.1.1.18.1.1.2 = INTEGER: 2 -# .1.3.6.1.4.1.15497.1.1.1.18.1.2.1 = INTEGER: 1 -# .1.3.6.1.4.1.15497.1.1.1.18.1.2.2 = INTEGER: 1 -# .1.3.6.1.4.1.15497.1.1.1.18.1.3.1 = STRING: Drive 0 -# .1.3.6.1.4.1.15497.1.1.1.18.1.3.2 = STRING: Drive 1 -# .1.3.6.1.4.1.15497.1.1.1.18.1.4.1 = STRING: No Errors -# .1.3.6.1.4.1.15497.1.1.1.18.1.4.2 = STRING: No Errors -# -# OMD[cmk16x]:~$ snmpwalk -v2c -c C370-MAIL localhost -m ASYNCOS-MAIL-MIB raidTable -# ASYNCOS-MAIL-MIB::raidIndex.1 = INTEGER: 1 -# ASYNCOS-MAIL-MIB::raidIndex.2 = INTEGER: 2 -# ASYNCOS-MAIL-MIB::raidStatus.1 = INTEGER: driveHealthy(1) -# ASYNCOS-MAIL-MIB::raidStatus.2 = INTEGER: driveHealthy(1) -# ASYNCOS-MAIL-MIB::raidID.1 = STRING: Drive 0 -# ASYNCOS-MAIL-MIB::raidID.2 = STRING: Drive 1 -# ASYNCOS-MAIL-MIB::raidLastError.1 = STRING: No Errors -# ASYNCOS-MAIL-MIB::raidLastError.2 = STRING: No Errors -# - - -def inventory_cisco_asyncos_raid(info, has_item, has_params=False): - if info: - params = None - if has_params: - params = {} - for line in info: - if has_item: - status, name, lasterror = line - item = name - yield item, params - - -def check_cisco_asyncos_raid_states(states): - # Now we only known the OK states and health states - # but we can expand if we know more - map_states = { - 'status': { - '1': (0, 'healthy'), - '2': (2, 'failure'), - '3': (1, 'rebuild'), - }, - } - states_evaluated = {} - for what, text in states: - states_evaluated.setdefault(text, map_states[text.lower()].get(what.lower(), (2, 'not %s' % what.lower()))) - - return states_evaluated - - -def check_cisco_asyncos_raid(item, _no_params, info): - for line in info: - status, name, lasterror = line - if item == name: - for text, (state, state_readable) in check_cisco_asyncos_raid_states([(status, 'Status')]).items(): - yield state, '%s: %s' % (text, state_readable) - if lasterror.lower() != 'no errors': - yield 0, 'Last error: %s' % lasterror - - -check_info['cisco_asyncos_raid'] = { - 'inventory_function': lambda info: inventory_cisco_asyncos_raid(info, True), - 'check_function': check_cisco_asyncos_raid, - 'service_description': 'RAID %s', - 'snmp_info': ( - '.1.3.6.1.4.1.15497.1.1.1.18.1', # ASYNCOS-MAIL-MIB::raidEntry - [ - '2', # raidStatus - '3', # raidID - '4', # raidLastError - ]), - 'snmp_scan_function': lambda oid: oid('.1.3.6.1.2.1.1.1.0').find('AsyncOS') != -1, - # 'snmp_scan_function': scan_cisco_asyncos, - # 'includes': ['cisco_asyncos.include'], -} \ No newline at end of file diff --git a/cisco_asyncos.mkp b/cisco_asyncos.mkp index 7ffc3e968140298a7b31323b262f25092a18aae7..ba5d874055af624ee806e377b40b58afb5b5c37b 100644 Binary files a/cisco_asyncos.mkp and b/cisco_asyncos.mkp differ diff --git a/packages/cisco_asyncos b/packages/cisco_asyncos index 7d32ddabd949a141eec423a2b14fcdb344ba8dbf..c319a77329c6284010020086dee1c569a3949748 100644 --- a/packages/cisco_asyncos +++ b/packages/cisco_asyncos @@ -19,19 +19,20 @@ 'ignore features\n' '\n' '- 2021-03-21: rewrite cisco_asyncos_cpu, cisco_asyncos_mem, ' - 'cisco_asyncos_temp for CMK 2.0\n', + 'cisco_asyncos_temp for CMK 2.0\n' + '- 2021-03-24: rewrite cisco_asyncos_raid\n', 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['cisco_asyncos_cpu.py', 'cisco_asyncos_mem.py', 'cisco_asyncos_temp.py', 'cisco_asyncos_fan.py', - 'cisco_asyncos_power.py'], + 'cisco_asyncos_power.py', + 'cisco_asyncos_raid.py'], 'checks': ['cisco_asyncos_bandwidth', 'cisco_asyncos_cache', 'cisco_asyncos_conn', 'cisco_asyncos_license', 'cisco_asyncos_queue', - 'cisco_asyncos_raid', 'cisco_asyncos_update', 'cisco_asyncos_dns', 'cisco_asyncos_messageage', @@ -43,7 +44,7 @@ 'name': 'cisco_asyncos', 'num_files': 19, 'title': 'Cisco AsyncOS (IronPort) checks', - 'version': '20200514_v0.1.4', + 'version': '20210324_v0.2.0', 'version.min_required': '2.0.0', 'version.packaged': '2.0.0p1', 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/metrics/cisco_asyncos.py b/web/plugins/metrics/cisco_asyncos.py index 7bfd522c926bf6f34355da9dbf96620ac1978363..ee23130a00b755078a23ad31fa43f8d35b0b8819 100644 --- a/web/plugins/metrics/cisco_asyncos.py +++ b/web/plugins/metrics/cisco_asyncos.py @@ -1,18 +1,18 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # # Cisco AsyncOS metrics plugin # # Author: Th.L. # Date : 2020-03-08 # +from cmk.gui.i18n import _ -##################################################################################################################### -# -# define units for cisco_ise perfdata -# -##################################################################################################################### - +from cmk.gui.plugins.metrics import ( + metric_info, + graph_info, + perfometer_info, +) ##################################################################################################################### @@ -87,22 +87,22 @@ check_metrics['check_mk-cisco_asyncos_mem'] = { # ###################################################################################################################### -graph_info.append({ +graph_info['cisco_async_dns'] ={ 'title': _('AsyncOS DNS requests'), 'metrics': [ ('cisco_asyncos_dns_pendingdnsrequests', '-area'), ('cisco_asyncos_dns_outstandingdnsrequests', 'area'), ], -}) +} -graph_info.append({ +graph_info['cisco_async_messageage']={ 'title': _('AsyncOS oldest message age'), 'metrics': [ ('cisco_asyncos_messageage_oldestmessageage', 'area'), ], -}) +} -graph_info.append({ +graph_info['cisco_asyncos_queue']={ 'title': _('AsyncOS E-Mail work queue'), 'metrics': [ ('cisco_asyncos_queue_work_queue', 'area'), @@ -111,9 +111,9 @@ graph_info.append({ ('cisco_asyncos_queue_work_queue:crit', _('crit')), ('cisco_asyncos_queue_work_queue:warn', _('warn')), ], -}) +} -graph_info.append({ +graph_info['cisco_asyncos_mem']={ 'title': _('AsyncOS Memory used'), 'metrics': [ ('cisco_asyncos_mem_mem_used', 'area'), @@ -122,7 +122,7 @@ graph_info.append({ ('cisco_asyncos_mem_mem_used:crit', _('crit')), ('cisco_asyncos_mem_mem_used:warn', _('warn')), ], -}) +} ###################################################################################################################### #