diff --git a/README.md b/README.md index c817dd2a7afe925c8c406f16111b044e2a0a0f6d..8222bf21514d51bc9dfeb770202c1353c0b292fa 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[PACKAGE]: ../../raw/master/mkp/cisco_flash-0.3.0-20230607.mkp "cisco_flash-0.3.0-20230607.mkp" +[PACKAGE]: ../../raw/master/mkp/cisco_flash-0.4.0-20240407.mkp "cisco_flash-0.4.0-20240407.mkp" # Cisco flash Collection of plugins for Cisco flash diff --git a/mkp/cisco_flash-0.4.0-20240407.mkp b/mkp/cisco_flash-0.4.0-20240407.mkp new file mode 100644 index 0000000000000000000000000000000000000000..f67933f2a2022ba07f868a584b683daf3cbd1eb5 Binary files /dev/null and b/mkp/cisco_flash-0.4.0-20240407.mkp differ diff --git a/source/agent_based/cisco_flash.py b/source/agent_based/cisco_flash.py index 9f6e0ebe2ad0a2de145fec326a6c54a052f7352f..3b5d1cbec4997bd48deb2777859fedb9bb69dcf3 100644 --- a/source/agent_based/cisco_flash.py +++ b/source/agent_based/cisco_flash.py @@ -12,7 +12,9 @@ # 2019-10-28: initial release # 2019-11-04: added wato for cisco_flash # 2021-07-31: rewritten for CMK 2.0 +# 2024-04-07: some code cleanup # + # snmpwalk sample # # .1.3.6.1.4.1.9.9.10.1.1.4.1.1.2.1.1 = INTEGER: 1 @@ -54,42 +56,42 @@ # from dataclasses import dataclass -from typing import Optional, Dict +from typing import Dict from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( - DiscoveryResult, CheckResult, + DiscoveryResult, StringTable, ) from cmk.base.plugins.agent_based.agent_based_api.v1 import ( - register, - Service, - SNMPTree, - contains, - check_levels, + Metric, OIDEnd, Result, - render, + SNMPTree, + Service, State, - Metric, all_of, + check_levels, + contains, exists, + register, + render, ) -@dataclass +@dataclass(frozen=True) class Partition: - size: Optional[int] = None - freespace: Optional[int] = None - usedspace: Optional[int] = None - index: Optional[int] = None - flashindex: Optional[int] = None - neederasure: Optional[bool] = None - lowspacenotifythreshold: Optional[int] = None - filecount: Optional[int] = None + size: int | None + free_space: int | None + used_space: int | None + index: int | None + flash_index: int | None + need_erasure: bool | None + low_space_notify_threshold: int | None + file_count: int | None -_partneederasure = { +_part_need_erasure = { '1': True, '2': False, } @@ -105,32 +107,39 @@ _partneederasure = { def parse_cisco_flash(string_table: StringTable) -> Dict[str, Partition]: partitions: Dict[str, Partition] = {} - for cflPartition in string_table: - cflpartOID_END, cflpartSize, cflpartFreeSpace, cflpartFileCount, cflpartName, cflpartNeedErasure, \ - cflpartSizeExtended, cflpartFreeSpaceExtended, cflpartLowSpaceNotifThreshold = cflPartition + for partition in string_table: + try: + part_oid_end, part_size, part_free_pace, part_file_count, part_name, part_need_erasure, \ + part_size_extended, part_free_space_extended, part_low_space_notif_threshold = partition + except ValueError: + continue - cflDevIndex, cflPartIndex = cflpartOID_END.split('.') + try: + dev_index, part_index = part_oid_end.split('.') + except ValueError: + continue - cflpartFreeSpace = int(cflpartFreeSpace) if cflpartFreeSpace.isdigit() else None - cflpartFreeSpaceExtended = int(cflpartFreeSpaceExtended) if cflpartFreeSpaceExtended.isdigit() else None - cflpartSize = int(cflpartSize) if cflpartSize.isdigit() else None - cflpartSizeExtended = int(cflpartSizeExtended) if cflpartSizeExtended.isdigit() else None + part_free_pace = int(part_free_pace) if part_free_pace.isdigit() else None + part_free_space_extended = int(part_free_space_extended) if part_free_space_extended.isdigit() else None + part_size = int(part_size) if part_size.isdigit() else None + part_size_extended = int(part_size_extended) if part_size_extended.isdigit() else None - freespace = cflpartFreeSpaceExtended if cflpartFreeSpaceExtended else cflpartFreeSpace - size = cflpartSizeExtended if cflpartSizeExtended else cflpartSize + free_space = part_free_space_extended if part_free_space_extended else part_free_pace + size = part_size_extended if part_size_extended else part_size if size > 0: partitions.update({ - cflpartName: Partition( - index=int(cflPartIndex) if cflPartIndex.isdigit() else None, - flashindex=int(cflDevIndex) if cflDevIndex.isdigit() else None, + part_name: Partition( + index=int(part_index) if part_index.isdigit() else None, + flash_index=int(dev_index) if dev_index.isdigit() else None, size=size, - freespace=freespace, - usedspace=size - freespace, - filecount=int(cflpartFileCount) if cflpartFileCount.isdigit() else None, - neederasure=_partneederasure.get(cflpartNeedErasure, None), - lowspacenotifythreshold=int( - cflpartLowSpaceNotifThreshold) if cflpartLowSpaceNotifThreshold.isdigit() else None + free_space=free_space, + used_space=size - free_space, + file_count=int(part_file_count) if part_file_count.isdigit() else None, + need_erasure=_part_need_erasure.get(part_need_erasure, None), + low_space_notify_threshold=int( + part_low_space_notif_threshold + ) if part_low_space_notif_threshold.isdigit() else None )}) return partitions @@ -161,24 +170,24 @@ def check_cisco_flash(item, params, section: Dict[str, Partition]) -> CheckResul except KeyError: return - if partition.lowspacenotifythreshold: - spacewarn = partition.size - ((partition.size / 100) * partition.lowspacenotifythreshold) + if partition.low_space_notify_threshold: + space_warn = partition.size - ((partition.size / 100) * partition.low_space_notify_threshold) else: - spacewarn = partition.size + space_warn = partition.size yield from check_levels( - value=partition.usedspace, + value=partition.used_space, label='Space used', metric_name='cisco_flash_partusedspace', render_func=render.disksize, - levels_upper=(spacewarn, partition.size - 10), + levels_upper=(space_warn, partition.size - 10), boundaries=(0, partition.size), ) - percentused = 100 * partition.usedspace / partition.size + percent_used = 100 * partition.used_space / partition.size yield from check_levels( - value=percentused, + value=percent_used, label='Percent', levels_upper=params['levels_upper_percent'], render_func=render.percent, @@ -186,33 +195,33 @@ def check_cisco_flash(item, params, section: Dict[str, Partition]) -> CheckResul metric_name='cisco_flash_percent_used' ) - if partition.neederasure: + if partition.need_erasure: yield Result(state=State.WARN, notice='Partition needs erasure') yield Metric( - value=partition.filecount, + value=partition.file_count, name='cisco_flash_partfilecount', boundaries=(0, None) ) for key, value in [ - ('Device index', partition.flashindex), + ('Device index', partition.flash_index), ('Partition index', partition.index), - ('Partition need erasure', partition.neederasure), - ('Partition low space notify threshold', partition.lowspacenotifythreshold), + ('Partition need erasure', partition.need_erasure), + ('Partition low space notify threshold', partition.low_space_notify_threshold), ]: if value: yield Result(state=State.OK, notice=f'{key}: {value}') size = max(partition.size, 1) # for size = 0 --> div/0 size = size / 1000 / 1000 - usedspace = partition.usedspace / 1000 / 1000 - freespace = partition.freespace / 1000 / 1000 + used_space = partition.used_space / 1000 / 1000 + free_space = partition.free_space / 1000 / 1000 - yield Result(state=State.OK, notice=f'Used: {usedspace:.2f} of {size:.2f} MB, {freespace:.2f} MB free') + yield Result(state=State.OK, notice=f'Used: {used_space:.2f} of {size:.2f} MB, {free_space:.2f} MB free') - if partition.filecount: - yield Result(state=State.OK, summary=f'File count: {partition.filecount}') + if partition.file_count: + yield Result(state=State.OK, summary=f'File count: {partition.file_count}') ########################################################################### diff --git a/source/agent_based/inv_cisco_flash.py b/source/agent_based/inv_cisco_flash.py index 2a23f76eb6f07d6654ec5d0b995f098ab5a41282..113f6e7d30c5234ca6804c95c63de5cb99e1e27a 100644 --- a/source/agent_based/inv_cisco_flash.py +++ b/source/agent_based/inv_cisco_flash.py @@ -9,29 +9,29 @@ # # invetory of cisco flash devices # -# 2019-10-22 : initial release +# 2019-10-22: initial release # 2021-07-31: rewritten for CMK 2.0 -# +# 2023-04-07: some code cleanup +# moved the Flash inventory from 'hardware.components.flash' to 'hardware.flash' # -from typing import List, Dict, Any from dataclasses import dataclass +from typing import List, Dict, Any + from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( - StringTable, InventoryResult, + StringTable, ) - from cmk.base.plugins.agent_based.agent_based_api.v1 import ( OIDEnd, ) - from cmk.base.plugins.agent_based.agent_based_api.v1 import ( - register, SNMPTree, TableRow, - exists, all_of, contains, + exists, + register, ) @@ -42,13 +42,13 @@ class Section: flash_partitions: List[Dict[str, Any]] -_DevProgrammingJumper = { +_dev_programming_jumper = { '1': 'installed', '2': 'not installed', '3': 'unknown', } -_DevRemovable = { +_dev_removable = { '1': True, '2': False, } @@ -59,62 +59,68 @@ _PartStatus = { '3': 'Read Write', } -_PartChecksumAlgorithm = { +_part_checksum_algorithm = { '1': 'simple Checksum', '2': 'undefined', '3': 'simple CRC', } -_PartUpgradeMethod = { - '1': 'unkown', +_part_upgrade_method = { + '1': 'unknown', '2': 'rxboot Flash Load Helper', '3': 'direct', } -_PartNeedErasure = { +_part_need_erasure = { '1': True, '2': False, } -def parse_inv_cisco_flash(string_table: List[StringTable]) -> Section: - cflDevices, cflChips, cflPartitions = string_table +def parse_inv_cisco_flash(string_table: List[StringTable]) -> Section | None: + try: + devices, chips, partitions = string_table + except ValueError: + return flash_devices = [] - for cflDevice in cflDevices: - clfOID_END, cflDevSize, cflDevMinPartitionSize, cflDevMaxPartitions, cflDevPartitions, cflDevChipCount, \ - cflDevName, cflDevDescr, cflDevController, cflDevProgrammingJumper, cflDevInitTime, cflDevRemovable, \ - cflDevPhyEntIndex, cflDevNameExtended, cflDevSizeExtended, cflDevMinPartitionSizeExtended = cflDevice - - cflDevSize = int(cflDevSize) if cflDevSize.isdigit() else None - cflDevSizeExtended = int(cflDevSizeExtended) if cflDevSizeExtended.isdigit() else None - cflDevMinPartitionSize = int(cflDevMinPartitionSize) if cflDevMinPartitionSize.isdigit() else None - cflDevMinPartitionSizeExtended = int( - cflDevMinPartitionSizeExtended) if cflDevMinPartitionSizeExtended.isdigit() else None + for cflDevice in devices: + try: + oid_end, dev_size, dev_min_partition_size, dev_max_partitions, dev_partitions, dev_chip_count, \ + dev_name, dev_descr, dev_controller, dev_programming_jumper, dev_init_time, dev_removable, \ + dev_phy_ent_index, dev_name_extended, dev_size_extended, dev_min_partition_size_extended = cflDevice + except ValueError: + continue + + dev_size = int(dev_size) if dev_size.isdigit() else None + dev_size_extended = int(dev_size_extended) if dev_size_extended.isdigit() else None + dev_min_partition_size = int(dev_min_partition_size) if dev_min_partition_size.isdigit() else None + dev_min_partition_size_extended = int( + dev_min_partition_size_extended) if dev_min_partition_size_extended.isdigit() else None # change sizes to MB - size = cflDevSizeExtended if cflDevSizeExtended else cflDevSize + size = dev_size_extended if dev_size_extended else dev_size size = size / 1024 / 1024 if size else None - minpartitionsize = cflDevMinPartitionSizeExtended if cflDevMinPartitionSizeExtended else cflDevMinPartitionSize - minpartitionsize = minpartitionsize / 1024 / 1024 if minpartitionsize else None + min_partition_size = dev_min_partition_size_extended if dev_min_partition_size_extended else dev_min_partition_size + min_partition_size = min_partition_size / 1024 / 1024 if min_partition_size else None flash_device = {} for key, value in [ - ('index', clfOID_END), - ('name', cflDevName), - ('description', cflDevDescr), - ('controller', cflDevController), - ('programmingjumper', _DevProgrammingJumper.get(cflDevProgrammingJumper)), - ('inittime', cflDevInitTime), - ('removable', _DevRemovable.get(cflDevRemovable)), - ('nameextended', cflDevNameExtended), - ('physentindex', cflDevPhyEntIndex), + ('index', oid_end), + ('name', dev_name), + ('description', dev_descr), + ('controller', dev_controller), + ('programmingjumper', _dev_programming_jumper.get(dev_programming_jumper)), + ('inittime', dev_init_time), + ('removable', _dev_removable.get(dev_removable)), + ('nameextended', dev_name_extended), + ('physentindex', dev_phy_ent_index), ('size', size), - ('minpartitionsize', minpartitionsize), - ('maxprtitions', cflDevMaxPartitions), - ('partitions', cflDevPartitions), - ('chipcount', cflDevChipCount), + ('minpartitionsize', min_partition_size), + ('maxprtitions', dev_max_partitions), + ('partitions', dev_partitions), + ('chipcount', dev_chip_count), ]: if value: flash_device.update({key: value}) @@ -122,22 +128,28 @@ def parse_inv_cisco_flash(string_table: List[StringTable]) -> Section: flash_chips = [] - for cflChip in cflChips: - cflOID_END, cflChipCode, cflChipDescr, cflChipWriteRetries, cflChipEraseRetries, cflChipMaxWriteRetries, \ - cflChipMaxEraseRetries = cflChip + for chip in chips: + try: + oid_end, chip_code, chip_descr, chip_write_retries, chip_erase_retries, chip_max_write_retries, \ + chip_max_erase_retries = chip + except ValueError: + continue - cflDevIndex, cflChipIndex = cflOID_END.split('.') + try: + dev_index, chip_index = oid_end.split('.') + except ValueError: + continue flash_chip = {} for key, value in [ - ('index', cflChipIndex), - ('flashindex', cflDevIndex), - ('code', cflChipCode), - ('description', cflChipDescr), - ('writeretries', cflChipWriteRetries), - ('eraseretries', cflChipEraseRetries), - ('maxwriteretries', cflChipMaxWriteRetries), - ('maxeraseretries', cflChipMaxEraseRetries), + ('index', chip_index), + ('flashindex', dev_index), + ('code', chip_code), + ('description', chip_descr), + ('writeretries', chip_write_retries), + ('eraseretries', chip_erase_retries), + ('maxwriteretries', chip_max_write_retries), + ('maxeraseretries', chip_max_erase_retries), ]: if value: flash_chip.update({key: value}) @@ -145,42 +157,48 @@ def parse_inv_cisco_flash(string_table: List[StringTable]) -> Section: flash_chips.append(flash_chip) flash_partitions = [] - for cflPartition in cflPartitions: - cflpartOID_END, cflpartStartChip, cflpartEndChip, cflpartSize, cflpartFreeSpace, cflpartFileCount, \ - cflpartChecksumAlgorithm, cflpartStatus, cflpartUpgradeMethod, cflpartName, cflpartNeedErasure, \ - cflpartFileNameLength, cflpartSizeExtended, cflpartFreeSpaceExtended, \ - cflpartLowSpaceNotifThreshold = cflPartition - - cflDevIndex, cflPartIndex = cflpartOID_END.split('.') - - cflpartSize = int(cflpartSize) if cflpartSize.isdigit() else None - cflpartFreeSpace = int(cflpartFreeSpace) if cflpartFreeSpace.isdigit() else None - cflpartSizeExtended = int(cflpartSizeExtended) if cflpartSizeExtended.isdigit() else None - cflpartFreeSpaceExtended = int(cflpartFreeSpaceExtended) if cflpartFreeSpaceExtended.isdigit() else None + for partition in partitions: + try: + part_oid_end, part_start_chip, part_end_chip, part_size, part_free_space, part_file_count, \ + part_checksum_algorithm, part_status, part_upgrade_method, part_name, part_need_erasure, \ + part_file_name_length, part_size_extended, part_free_space_extended, \ + part_low_space_notif_threshold = partition + except ValueError: + continue + + try: + dev_index, part_index = part_oid_end.split('.') + except ValueError: + continue + + part_size = int(part_size) if part_size.isdigit() else None + part_free_space = int(part_free_space) if part_free_space.isdigit() else None + part_size_extended = int(part_size_extended) if part_size_extended.isdigit() else None + part_free_space_extended = int(part_free_space_extended) if part_free_space_extended.isdigit() else None # change sizes to MB - size = cflpartSizeExtended if cflpartSizeExtended else cflpartSize + size = part_size_extended if part_size_extended else part_size size = size / 1024 / 1024 if size else None - freespace = cflpartFreeSpaceExtended if cflpartFreeSpaceExtended else cflpartFreeSpace - freespace = freespace / 1024 / 1024 if freespace else None + free_space = part_free_space_extended if part_free_space_extended else part_free_space + free_space = free_space / 1024 / 1024 if free_space else None flash_partition = {} for key, value in [ - ('index', cflPartIndex), - ('flashindex', cflDevIndex), - ('startchip', cflpartStartChip), - ('endchip', cflpartEndChip), - ('filecount', cflpartFileCount), - ('crcsumalgo', _PartChecksumAlgorithm.get(cflpartChecksumAlgorithm)), - ('status', _PartStatus.get(cflpartStatus)), - ('upgrademethod', _PartUpgradeMethod.get(cflpartUpgradeMethod)), - ('name', cflpartName), - ('neederasure', _PartNeedErasure.get(cflpartNeedErasure)), - ('filenamelength', cflpartFileNameLength), - ('lowspacenotifythreshold', cflpartLowSpaceNotifThreshold), + ('index', part_index), + ('flashindex', dev_index), + ('startchip', part_start_chip), + ('endchip', part_end_chip), + ('filecount', part_file_count), + ('crcsumalgo', _part_checksum_algorithm.get(part_checksum_algorithm)), + ('status', _PartStatus.get(part_status)), + ('upgrademethod', _part_upgrade_method.get(part_upgrade_method)), + ('name', part_name), + ('neederasure', _part_need_erasure.get(part_need_erasure)), + ('filenamelength', part_file_name_length), + ('lowspacenotifythreshold', part_low_space_notif_threshold), ('size', size), - ('freespace', freespace), + ('freespace', free_space), ]: if value: flash_partition.update({key: value}) @@ -198,25 +216,24 @@ def inventory_cisco_flash(params, section: Section) -> InventoryResult: flash_devices = section.flash_devices flash_chips = section.flash_chips flash_partitions = section.flash_partitions - + base_path = ['hardware', 'flash'] # inventory of cisco flash devices - removecolumns = [] + remove_columns = [] disabled = False # if params: disabled = params.get('cflDeviceDisable', disabled) # get list of columns to remove from inventory - removecolumns = params.get('cflDeviceRemovecolumns', removecolumns) + remove_columns = params.get('cflDeviceRemovecolumns', remove_columns) if not disabled: - - path = ['hardware', 'components', 'flash', 'devices'] + path = base_path + ['devices'] for flash_device in flash_devices: key_columns = {'index': flash_device['index'], } flash_device.pop('index') for key in flash_device.keys(): - if key in removecolumns: + if key in remove_columns: flash_device.pop(key) yield TableRow( @@ -227,23 +244,23 @@ def inventory_cisco_flash(params, section: Section) -> InventoryResult: # inventory of cisco flash chips - removecolumns = [] + remove_columns = [] disabled = False if params: disabled = params.get('cflChipDisable', disabled) # get list of columns to remove from inventory - removecolumns = params.get('cflChipRemovecolumns', removecolumns) + remove_columns = params.get('cflChipRemovecolumns', remove_columns) if not disabled: - path = ['hardware', 'components', 'flash', 'chips'] + path = base_path + ['chips'] for flash_chip in flash_chips: key_columns = {'index': flash_chip['index'], 'flashindex': flash_chip['flashindex']} flash_chip.pop('index') flash_chip.pop('flashindex') for key in flash_chip.keys(): - if key in removecolumns: + if key in remove_columns: flash_chip.pop(key) yield TableRow( @@ -254,23 +271,22 @@ def inventory_cisco_flash(params, section: Section) -> InventoryResult: # inventory of cisco flash partitions - removecolumns = [] + remove_columns = [] disabled = False if params: disabled = params.get('cflPartitionDisable', disabled) # get list of columns to remove from inventory - removecolumns = params.get('cflPartitionRemovecolumns', removecolumns) + remove_columns = params.get('cflPartitionRemovecolumns', remove_columns) if not disabled: - path = ['hardware', 'components', 'flash', 'partitions'] - + path = base_path + ['partitions'] for flash_partition in flash_partitions: key_columns = {'index': flash_partition['index'], 'flashindex': flash_partition['flashindex']} flash_partition.pop('index') flash_partition.pop('flashindex') for key in flash_partition.keys(): - if key in removecolumns: + if key in remove_columns: flash_partition.pop(key) yield TableRow( diff --git a/source/gui/views/inv_cisco_flash.py b/source/gui/views/inv_cisco_flash.py deleted file mode 100644 index fad000b22a949fc3fb20fa2e037ce0ae14824740..0000000000000000000000000000000000000000 --- a/source/gui/views/inv_cisco_flash.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - - -from cmk.gui.plugins.views.utils import ( - inventory_displayhints, -) -from cmk.gui.i18n import _ -from cmk.gui.plugins.views.inventory import declare_invtable_view - -inventory_displayhints.update({ - '.hardware.components.flash.devices:': { - 'title': _('Flash devices'), - 'keyorder': ['index', 'name', 'description', 'size', ], - 'view': 'invflashdevices_of_host', - }, - - '.hardware.components.flash.devices:*.index': {'title': _('Index'), }, - '.hardware.components.flash.devices:*.size': {'title': _('Size (MB)'), }, - '.hardware.components.flash.devices:*.minpartitionsize': {'title': _('min. partition size (MB)'), }, - '.hardware.components.flash.devices:*.maxprtitions': {'title': _('max. partitions'), }, - '.hardware.components.flash.devices:*.chipcount': {'title': _('Chip count'), }, - '.hardware.components.flash.devices:*.name': {'title': _('Name'), }, - '.hardware.components.flash.devices:*.description': {'title': _('Description'), }, - '.hardware.components.flash.devices:*.controller': {'title': _('Controller'), }, - '.hardware.components.flash.devices:*.programmingjumper': {'title': _('Programming jumper'), }, - '.hardware.components.flash.devices:*.inittime': {'title': _('Init time'), }, - '.hardware.components.flash.devices:*.removable': {'title': _('Removable'), }, - '.hardware.components.flash.devices:*.physentindex': {'title': _('Phys entity index'), }, - '.hardware.components.flash.devices:*.nameextended': {'title': _('Name extended'), }, - - '.hardware.components.flash.chips:': { - 'title': _('Flash chips'), - 'keyorder': ['flashindex', 'index', 'description', ], - 'view': 'invflashchips_of_host', - }, - - '.hardware.components.flash.chips:*.index': {'title': _('Chip index'), }, - '.hardware.components.flash.chips:*.flashindex': {'title': _('Device index'), }, - '.hardware.components.flash.chips:*.code': {'title': _('Code'), }, - '.hardware.components.flash.chips:*.description': {'title': _('Description'), }, - '.hardware.components.flash.chips:*.writeretries': {'title': _('Write retries'), }, - '.hardware.components.flash.chips:*.eraseretries': {'title': _('Erase retries'), }, - '.hardware.components.flash.chips:*.maxwriteretries': {'title': _('max. write retries'), }, - '.hardware.components.flash.chips:*.maxeraseretries': {'title': _('max. erasure retries'), }, - - '.hardware.components.flash.partitions:': { - 'title': _('Flash partitions'), - 'keyorder': ['flashindex', 'index', 'name', 'size', 'freespace', 'filecount', ], - 'view': 'invflashpartitions_of_host', - }, - - '.hardware.components.flash.partitions:*.index': {'title': _('Partition index'), }, - '.hardware.components.flash.partitions:*.flashindex': {'title': _('Device index'), }, - '.hardware.components.flash.partitions:*.startchip': {'title': _('Start chip'), }, - '.hardware.components.flash.partitions:*.endchip': {'title': _('End chip'), }, - '.hardware.components.flash.partitions:*.size': {'title': _('Size (MB)'), }, - '.hardware.components.flash.partitions:*.freespace': {'title': _('Free space (MB)'), }, - '.hardware.components.flash.partitions:*.filecount': {'title': _('File count'), }, - '.hardware.components.flash.partitions:*.crcsumalgo': {'title': _('Checksumm algorithm'), }, - '.hardware.components.flash.partitions:*.status': {'title': _('Status'), }, - '.hardware.components.flash.partitions:*.upgrademethod': {'title': _('Upgrade method'), }, - '.hardware.components.flash.partitions:*.name': {'title': _('Name'), }, - '.hardware.components.flash.partitions:*.neederasure': {'title': _('Need erasure'), }, - '.hardware.components.flash.partitions:*.filenamelength': {'title': _('File name length'), }, - '.hardware.components.flash.partitions:*.lowspacenotifythreshold': {'title': _('Low space notify threshold (%)'), }, -}) - -declare_invtable_view('invflashdevices', '.hardware.components.flash.devices:', _('Flash devices'), _('Flash devices')) -declare_invtable_view('invflashchips', '.hardware.components.flash.chips:', _('Flash chips'), _('Flash chips')) -declare_invtable_view('invflashpartitions', '.hardware.components.flash.partitions:', _('Flash partitions'), - _('Flash partitions')) diff --git a/source/gui/wato/cisco_flash.py b/source/gui/wato/check_parameters/cisco_flash.py similarity index 100% rename from source/gui/wato/cisco_flash.py rename to source/gui/wato/check_parameters/cisco_flash.py index d34daffd5465e537ed1dca14f6bb3d8c06975764..8d5eb8d6b014bf88ecffdf57b182c0f9e2aa22fc 100644 --- a/source/gui/wato/cisco_flash.py +++ b/source/gui/wato/check_parameters/cisco_flash.py @@ -24,8 +24,8 @@ from cmk.gui.valuespec import ( from cmk.gui.plugins.wato.utils import ( CheckParameterRulespecWithItem, - rulespec_registry, RulespecGroupCheckParametersNetworking, + rulespec_registry, ) diff --git a/source/gui/wato/inv_cisco_flash.py b/source/gui/wato/check_parameters/inv_cisco_flash.py similarity index 91% rename from source/gui/wato/inv_cisco_flash.py rename to source/gui/wato/check_parameters/inv_cisco_flash.py index 7cf40a5284baae72dfbfc73db030ddbebff25fee..ef44cd03baaea70f191a30af5afe24ecbf06b603 100644 --- a/source/gui/wato/inv_cisco_flash.py +++ b/source/gui/wato/check_parameters/inv_cisco_flash.py @@ -29,7 +29,7 @@ from cmk.gui.plugins.wato.inventory import ( RulespecGroupInventory, ) -_inv_cisco_flash_cflDeviceRemovecolumns = [ +_inv_cisco_flash_cfl_device_remove_columns = [ ('minpartitionsize', 'min. partition size (MB)'), ('maxprtitions', 'max. partitions'), ('chipcount', 'Chip count'), @@ -41,7 +41,7 @@ _inv_cisco_flash_cflDeviceRemovecolumns = [ ('nameextended', 'Name extended'), ] -_inv_cisco_flash_cflPartitionRemovecolumns = [ +_inv_cisco_flash_cfl_partition_remove_columns = [ ('startchip', 'Start chip'), ('endchip', 'End chip'), ('crcsumalgo', 'Checksumm algorithm'), @@ -52,7 +52,7 @@ _inv_cisco_flash_cflPartitionRemovecolumns = [ ('lowspacenotifythreshold', 'Low space notify threshold (%)'), ] -_inv_cisco_flash_cflChipRemovecolumns = [ +_inv_cisco_flash_cfl_chip_remove_columns = [ ('code', 'Code'), ('writeretries', 'Write retries'), ('eraseretries', 'Erase retries'), @@ -84,7 +84,7 @@ def _valuespec_inv_cisco_flash(): ListChoice( title=_('list of columns to remove from flash devices'), help=_('information to remove from inventory'), - choices=_inv_cisco_flash_cflDeviceRemovecolumns, + choices=_inv_cisco_flash_cfl_device_remove_columns, default_value=[ 'chipcount', 'controller', @@ -98,7 +98,7 @@ def _valuespec_inv_cisco_flash(): ListChoice( title=_('list of columns to remove from flash partitions'), help=_('information to remove from inventory'), - choices=_inv_cisco_flash_cflPartitionRemovecolumns, + choices=_inv_cisco_flash_cfl_partition_remove_columns, default_value=[ 'startchip', 'endchip', @@ -108,7 +108,7 @@ def _valuespec_inv_cisco_flash(): ListChoice( title=_('list of columns to remove from flash chips'), help=_('information to remove from inventory'), - choices=_inv_cisco_flash_cflChipRemovecolumns, + choices=_inv_cisco_flash_cfl_chip_remove_columns, default_value=[ 'code', 'writeretries', diff --git a/source/packages/cisco_flash b/source/packages/cisco_flash index a732186a634c7962c487cc0eb08bc331ba103832..95765345401519338cb9b329c7fdd46e204d6fcb 100644 --- a/source/packages/cisco_flash +++ b/source/packages/cisco_flash @@ -4,16 +4,17 @@ ' - cisco_flash: check for Cisco partitions\n' '\n' '- 2020-05-13: added support for CMK1.6x\n' - '- 2021-07-31: rewritten for CMK 2.0\n', + '- 2021-07-31: rewritten for CMK 2.0\n' + '- 2024-04-07: refactoring for CMK 2.2\n', 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['cisco_flash.py', 'inv_cisco_flash.py'], 'gui': ['metrics/cisco_flash.py', - 'views/inv_cisco_flash.py', - 'wato/cisco_flash.py', - 'wato/inv_cisco_flash.py']}, + 'wato/check_parameters/cisco_flash.py', + 'wato/check_parameters/inv_cisco_flash.py'], + 'web': ['plugins/views/inv_cisco_flash.py']}, 'name': 'cisco_flash', 'title': 'Cisco flash plugins', - 'version': '0.3.0-20230607', - 'version.min_required': '2.1.0b1', + 'version': '0.4.0-20240407', + 'version.min_required': '2.2.0b1', 'version.packaged': '2.2.0p24', 'version.usable_until': None} diff --git a/source/web/plugins/views/inv_cisco_flash.py b/source/web/plugins/views/inv_cisco_flash.py new file mode 100644 index 0000000000000000000000000000000000000000..69a1bba330d2c9627e135fd6b808a38f8cec691f --- /dev/null +++ b/source/web/plugins/views/inv_cisco_flash.py @@ -0,0 +1,77 @@ +#!/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 : 2019-10-28 +# + +# 2024-04-07: modified for CMK 2.2.x (ThX bitwiz@forum.checkmk.com) +# fixed some typos (ThX bitwiz@forum.checkmk.com) +# moved the Flash inventory from 'hardware.components.flash' to 'hardware.flash' + +from cmk.gui.i18n import _ +from cmk.gui.views.inventory.registry import inventory_displayhints + +inventory_displayhints.update({ + '.hardware.flash.': { + 'title': _('Flash'), + }, + '.hardware.flash.devices:': { + 'title': _('Flash Devices'), + 'keyorder': ['index', 'name', 'description', 'size', ], + 'view': 'invflashdevices_of_host', + }, + + '.hardware.flash.devices:*.index': {'title': _('Index'), }, + '.hardware.flash.devices:*.size': {'title': _('Size (MB)'), }, + '.hardware.flash.devices:*.minpartitionsize': {'title': _('Min. Partition Size (MB)'), }, + '.hardware.flash.devices:*.maxprtitions': {'title': _('Max. Partitions'), }, + '.hardware.flash.devices:*.chipcount': {'title': _('Chip Count'), }, + '.hardware.flash.devices:*.name': {'title': _('Name'), }, + '.hardware.flash.devices:*.description': {'title': _('Description'), }, + '.hardware.flash.devices:*.controller': {'title': _('Controller'), }, + '.hardware.flash.devices:*.programmingjumper': {'title': _('Programming Jumper'), }, + '.hardware.flash.devices:*.inittime': {'title': _('Init Time'), }, + '.hardware.flash.devices:*.removable': {'title': _('Removable'), }, + '.hardware.flash.devices:*.physentindex': {'title': _('Phys Entity Index'), }, + '.hardware.flash.devices:*.nameextended': {'title': _('Name Extended'), }, + + '.hardware.flash.chips:': { + 'title': _('Flash Chips'), + 'keyorder': ['flashindex', 'index', 'description', ], + 'view': 'invflashchips_of_host', + }, + + '.hardware.flash.chips:*.index': {'title': _('Chip Index'), }, + '.hardware.flash.chips:*.flashindex': {'title': _('Device Index'), }, + '.hardware.flash.chips:*.code': {'title': _('Code'), }, + '.hardware.flash.chips:*.description': {'title': _('Description'), }, + '.hardware.flash.chips:*.writeretries': {'title': _('Write Retries'), }, + '.hardware.flash.chips:*.eraseretries': {'title': _('Erase Retries'), }, + '.hardware.flash.chips:*.maxwriteretries': {'title': _('Max. Write Retries'), }, + '.hardware.flash.chips:*.maxeraseretries': {'title': _('Max. Erasure Retries'), }, + + '.hardware.flash.partitions:': { + 'title': _('Flash Partitions'), + 'keyorder': ['flashindex', 'index', 'name', 'size', 'freespace', 'filecount', ], + 'view': 'invflashpartitions_of_host', + }, + + '.hardware.flash.partitions:*.index': {'title': _('Partition Index'), }, + '.hardware.flash.partitions:*.flashindex': {'title': _('Device Index'), }, + '.hardware.flash.partitions:*.startchip': {'title': _('Start Chip'), }, + '.hardware.flash.partitions:*.endchip': {'title': _('End Chip'), }, + '.hardware.flash.partitions:*.size': {'title': _('Size (MB)'), }, + '.hardware.flash.partitions:*.freespace': {'title': _('Free Space (MB)'), }, + '.hardware.flash.partitions:*.filecount': {'title': _('File Count'), }, + '.hardware.flash.partitions:*.crcsumalgo': {'title': _('Checksum Algorithm'), }, + '.hardware.flash.partitions:*.status': {'title': _('Status'), }, + '.hardware.flash.partitions:*.upgrademethod': {'title': _('Upgrade Method'), }, + '.hardware.flash.partitions:*.name': {'title': _('Name'), }, + '.hardware.flash.partitions:*.neederasure': {'title': _('Need Erasure'), }, + '.hardware.flash.partitions:*.filenamelength': {'title': _('File Name Length'), }, + '.hardware.flash.partitions:*.lowspacenotifythreshold': {'title': _('Low Space Notify Threshold (%)'), }, +})