From 053146ec675956358fbfbcab1e495600952eea2a Mon Sep 17 00:00:00 2001 From: Marius Rieder Date: Thu, 27 Jun 2024 07:37:16 +0200 Subject: [PATCH] Rework special agent for Checkmk 2.3.0 --- agent_based/dell_storage_center.py | 2 +- agent_based/dell_storage_controller.py | 2 +- agent_based/dell_storage_disk.py | 2 +- agent_based/dell_storage_enclosure.py | 2 +- agent_based/dell_storage_fan.py | 2 +- agent_based/dell_storage_port.py | 2 +- agent_based/dell_storage_psu.py | 2 +- agent_based/dell_storage_temp.py | 2 +- agent_based/dell_storage_volume.py | 2 +- agent_based/utils/diskstat.py | 452 ------------------ graphing/dell_storage.py | 121 +++++ .../agent_dell_storage => lib/agent.py | 107 +++-- {agent_based/utils => lib}/dell_storage.py | 0 {checks => libexec}/agent_dell_storage | 15 +- package | 75 ++- rulesets/datasource_dell_storage.py | 98 ++++ server_side_calls/agent_dell_storage.py | 55 +++ .../ApiConnection/0/StorageCenterList | 0 .../fixtures/ApiConnection/Login | 0 .../StorageCenter/ScChassis/123456/Enclosure | 0 .../ScChassis/123456/FanSensorList | 0 .../ScChassis/123456/PowerSupplyList | 0 .../ScChassis/123456/TemperatureSensorList | 0 .../ScController/123456.123456/FanSensorList | 0 .../123456.123456/PhysicalControllerPortList | 0 .../123456.123456/PowerSupplyList | 0 .../123456.123456/TemperatureSensorList | 0 .../ScController/123456.123457/FanSensorList | 0 .../123456.123457/PhysicalControllerPortList | 0 .../123456.123457/PowerSupplyList | 0 .../123456.123457/TemperatureSensorList | 0 .../GetHistoricalIoUsage | 0 .../GetHistoricalIoUsage | 0 .../GetHistoricalIoUsage | 0 .../GetHistoricalIoUsage | 0 .../ScDisk/123456.1/GetHistoricalIoUsage | 0 .../ScDisk/123456.1/StorageUsage | 0 .../ScDisk/123456.10/GetHistoricalIoUsage | 0 .../ScDisk/123456.10/StorageUsage | 0 .../ScDisk/123456.22/GetHistoricalIoUsage | 0 .../ScDisk/123456.22/StorageUsage | 0 .../ScDisk/123456.23/GetHistoricalIoUsage | 0 .../ScDisk/123456.23/StorageUsage | 0 .../ScEnclosure/123456.1/CoolingFanSensorList | 0 .../ScEnclosure/123456.1/DiskList | 0 .../ScEnclosure/123456.1/PowerSupplyList | 0 .../123456.1/TemperatureSensorList | 0 .../ScEnclosure/123456.2/CoolingFanSensorList | 0 .../ScEnclosure/123456.2/DiskList | 0 .../ScEnclosure/123456.2/PowerSupplyList | 0 .../123456.2/TemperatureSensorList | 0 .../ScVolume/123456.11/GetHistoricalIoUsage | 0 .../ScVolume/123456.11/StorageUsage | 0 .../ScVolume/123456.12/GetHistoricalIoUsage | 0 .../ScVolume/123456.12/StorageUsage | 0 .../ScVolume/123456.13/GetHistoricalIoUsage | 0 .../ScVolume/123456.13/StorageUsage | 0 .../StorageCenter/123456/ActiveAlertList | 0 .../StorageCenter/123456/Chassis | 0 .../StorageCenter/123456/ControllerList | 0 .../StorageCenter/123456/EnclosureList | 0 .../StorageCenter/123456/ObjectCount | 0 .../StorageCenter/123456/VolumeList | 0 .../test_agent.py} | 23 +- .../test_agent.py} | 24 +- .../utils => lib}/test_dell_storage.py | 2 +- web/plugins/metrics/dell_storage.py | 114 ----- web/plugins/wato/datasource_dell_storage.py | 88 ---- 68 files changed, 400 insertions(+), 792 deletions(-) delete mode 100644 agent_based/utils/diskstat.py create mode 100644 graphing/dell_storage.py rename agents/special/agent_dell_storage => lib/agent.py (80%) rename {agent_based/utils => lib}/dell_storage.py (100%) rename {checks => libexec}/agent_dell_storage (70%) create mode 100644 rulesets/datasource_dell_storage.py create mode 100644 server_side_calls/agent_dell_storage.py rename tests/integration/{agents/special => lib}/fixtures/ApiConnection/ApiConnection/0/StorageCenterList (100%) rename tests/integration/{agents/special => lib}/fixtures/ApiConnection/Login (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScChassis/123456/Enclosure (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScChassis/123456/FanSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScChassis/123456/PowerSupplyList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScChassis/123456/TemperatureSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123456/FanSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123456/PhysicalControllerPortList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123456/PowerSupplyList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123456/TemperatureSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123457/FanSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123457/PhysicalControllerPortList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123457/PowerSupplyList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScController/123456.123457/TemperatureSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567802.45/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567804.49/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567818.36/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567824.57/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.1/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.1/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.10/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.10/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.22/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.22/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.23/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScDisk/123456.23/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.1/CoolingFanSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.1/DiskList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.1/PowerSupplyList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.1/TemperatureSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.2/CoolingFanSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.2/DiskList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.2/PowerSupplyList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScEnclosure/123456.2/TemperatureSensorList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScVolume/123456.11/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScVolume/123456.11/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScVolume/123456.12/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScVolume/123456.12/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScVolume/123456.13/GetHistoricalIoUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/ScVolume/123456.13/StorageUsage (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/StorageCenter/123456/ActiveAlertList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/StorageCenter/123456/Chassis (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/StorageCenter/123456/ControllerList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/StorageCenter/123456/EnclosureList (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/StorageCenter/123456/ObjectCount (100%) rename tests/integration/{agents/special => lib}/fixtures/StorageCenter/StorageCenter/123456/VolumeList (100%) rename tests/integration/{agents/special/test_int_agent_dell_storage.py => lib/test_agent.py} (90%) rename tests/unit/{agents/special/test_agent_dell_storag.py => lib/test_agent.py} (82%) rename tests/unit/{agent_based/utils => lib}/test_dell_storage.py (97%) delete mode 100644 web/plugins/metrics/dell_storage.py delete mode 100644 web/plugins/wato/datasource_dell_storage.py diff --git a/agent_based/dell_storage_center.py b/agent_based/dell_storage_center.py index e55a3a1..a0290a4 100644 --- a/agent_based/dell_storage_center.py +++ b/agent_based/dell_storage_center.py @@ -28,7 +28,7 @@ Service, State, ) -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_controller.py b/agent_based/dell_storage_controller.py index 43889ef..734ce4c 100644 --- a/agent_based/dell_storage_controller.py +++ b/agent_based/dell_storage_controller.py @@ -27,7 +27,7 @@ Service, State, ) -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_disk.py b/agent_based/dell_storage_disk.py index cc0e139..fd534b8 100644 --- a/agent_based/dell_storage_disk.py +++ b/agent_based/dell_storage_disk.py @@ -29,7 +29,7 @@ Service, ) from cmk.plugins.lib import diskstat -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_enclosure.py b/agent_based/dell_storage_enclosure.py index f5008cd..0a90ed5 100644 --- a/agent_based/dell_storage_enclosure.py +++ b/agent_based/dell_storage_enclosure.py @@ -27,7 +27,7 @@ Service, State, ) -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_fan.py b/agent_based/dell_storage_fan.py index 6b34e8f..4ba2061 100644 --- a/agent_based/dell_storage_fan.py +++ b/agent_based/dell_storage_fan.py @@ -28,7 +28,7 @@ Service, State, ) -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_port.py b/agent_based/dell_storage_port.py index 642c39a..49f0a89 100644 --- a/agent_based/dell_storage_port.py +++ b/agent_based/dell_storage_port.py @@ -30,7 +30,7 @@ State, ) from cmk.plugins.lib import diskstat -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_psu.py b/agent_based/dell_storage_psu.py index fb52bd8..202c6d0 100644 --- a/agent_based/dell_storage_psu.py +++ b/agent_based/dell_storage_psu.py @@ -27,7 +27,7 @@ Service, State, ) -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/dell_storage_temp.py b/agent_based/dell_storage_temp.py index e3480ef..7c6f359 100644 --- a/agent_based/dell_storage_temp.py +++ b/agent_based/dell_storage_temp.py @@ -29,7 +29,7 @@ State, ) from cmk.plugins.lib.temperature import check_temperature -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult, ) diff --git a/agent_based/dell_storage_volume.py b/agent_based/dell_storage_volume.py index a89d721..5bfbfea 100644 --- a/agent_based/dell_storage_volume.py +++ b/agent_based/dell_storage_volume.py @@ -29,7 +29,7 @@ Service, ) from cmk.plugins.lib import diskstat -from .utils.dell_storage import ( +from cmk_addons.plugins.dell_storage.lib.dell_storage import ( DSResult ) diff --git a/agent_based/utils/diskstat.py b/agent_based/utils/diskstat.py deleted file mode 100644 index ba7cc58..0000000 --- a/agent_based/utils/diskstat.py +++ /dev/null @@ -1,452 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2 -# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and -# conditions defined in the file COPYING, which is part of this source code package. - -import re -from collections import defaultdict -from collections.abc import Callable, Generator, Iterable, Mapping, MutableMapping, Sequence -from typing import Any, DefaultDict, TypedDict - -from cmk.agent_based.v1 import check_levels, check_levels_predictive -from cmk.agent_based.v2 import ( - CheckResult, - DiscoveryResult, - get_average, - get_rate, - IgnoreResultsError, - Metric, - render, - Result, - Service, - State, -) - -Disk = Mapping[str, float] -Section = Mapping[str, Disk] - -DISKSTAT_DISKLESS_PATTERN = re.compile("x?[shv]d[a-z]*[0-9]+") - - -def discovery_diskstat_generic( - params: Sequence[Mapping[str, Any]], - section: Iterable[str], -) -> DiscoveryResult: - item_candidates = list(section) - # Skip over on empty data - if not item_candidates: - return - - modes = params[0] - - if "summary" in modes: - yield Service(item="SUMMARY") - - for name in item_candidates: - if "physical" in modes and " " not in name and not DISKSTAT_DISKLESS_PATTERN.match(name): - yield Service(item=name) - - if "lvm" in modes and name.startswith("LVM "): - yield Service(item=name) - - if "vxvm" in modes and name.startswith("VxVM "): - yield Service(item=name) - - if "diskless" in modes and DISKSTAT_DISKLESS_PATTERN.match(name): - # Sort of partitions with disks - typical in XEN virtual setups. - # Eg. there are xvda1, xvda2, but no xvda... - yield Service(item=name) - - -def compute_rates_multiple_disks( - disks: Section, - value_store: MutableMapping[str, Any], - single_disk_rate_computer: Callable[[Disk, MutableMapping[str, Any], str], Disk], -) -> Section: - """Compute rates for multiple disks - - Args: - disks: Dictionary with multiple disks: {'sda': {'read_ios': 7}} - value_store: value store - single_disk_rate_computer: function that computes rates for a single disk. - 1. parameter: disk: dictionary with absolute disk stats: {'read_ios': 20} - 2. parameter: value_store - 3. parameter: suffix to use for the value_store key (this value is - needed because this function is normally called for the - 'SUMMARY' item. in order to distinguish the different - 'read_ios' of multiple disks, the key will be suffixed with the - disk name before asking get_rate for the values. - return value: dictionary with relative disk stats: {'read_ios': 1} - - Example: - >>> from contextlib import suppress - >>> VALUE_STORE = {} # normally obtained via get_value_store() - >>> THIS_TIME = 0 # either read from section or time.time() - >>> DISKS_ABSOLUTE = {'sda': {'read_ios': 11}, 'sdb': {'read_ios': 22}} - >>> def single_disk_rate_computer(disk_absolute, value_store, value_store_suffix): - ... return compute_rates( # or use your own function - ... disk=disk_absolute, - ... value_store=value_store, - ... disk_name=value_store_suffix, - ... this_time=THIS_TIME) - >>> with suppress(IgnoreResultsError): - ... # first computation will throw error as value_store is empty - ... compute_rates_multiple_disks(DISKS_ABSOLUTE, VALUE_STORE, single_disk_rate_computer) - >>> THIS_TIME = 10 - >>> DISKS_ABSOLUTE = {'sda': {'read_ios': 22}, 'sdb': {'read_ios': 44}} - >>> compute_rates_multiple_disks(DISKS_ABSOLUTE, VALUE_STORE, single_disk_rate_computer) - {'sda': {'read_ios': 1.1}, 'sdb': {'read_ios': 2.2}} - - This may be used as input for summarize_disks. - """ - disks_with_rates = {} - ignore_res_excpt = None - - for disk_name, disk in disks.items(): - try: - disks_with_rates[disk_name] = single_disk_rate_computer( - disk, - value_store, - ".%s" % disk_name, - ) - except IgnoreResultsError as excpt: - ignore_res_excpt = excpt - - if ignore_res_excpt: - raise ignore_res_excpt - - return disks_with_rates - - -_METRICS_TO_BE_AVERAGED = { - "utilization", - "latency", - "read_latency", - "write_latency", - "queue_length", -} - - -def combine_disks(disks: Iterable[Disk]) -> Disk: - # In summary mode we add up the throughput values, but - # we average the other values for disks that have a throughput - # > 0. Note: This is not very precise. Strictly spoken - # we would need to do the summarization directly in the - # parse function. But there we do not have information about - # the physical multipath devices and would add up the traffic - # of the paths with the traffice of the device itself.... - - combined_disk: DefaultDict[str, float] = defaultdict(float) - # We do not set these settings explictly because some - # devices may not provide all of them. - # "read_ios" : 0.0, - # "write_ios" : 0.0, - # "read_throughput" : 0.0, - # "write_throughput" : 0.0, - # "utilization" : 0.0, - # "latency" : 0.0, - # "average_request_size" : 0.0, - # "average_wait" : 0.0, - # "average_read_wait" : 0.0, - # "average_read_request_size" : 0.0, - # "average_write_wait" : 0.0, - # "average_write_request_size" : 0.0, - # "queue_length" : 0.0, - # "read_ql" : 0.0, - # "write_ql" : 0.0, - n_contributions: DefaultDict[str, int] = defaultdict(int) - - for disk in disks: - for key, value in disk.items(): - combined_disk[key] += value - n_contributions[key] += 1 - - for key in combined_disk: - if key.startswith("ave") or key in _METRICS_TO_BE_AVERAGED: - combined_disk[key] /= n_contributions[key] - - return combined_disk - - -def summarize_disks(disks: Iterable[tuple[str, Disk]]) -> Disk: - # we do not use a dictionary as input because we want to be able to have the same disk name - # multiple times (cluster mode) - # skip LVM devices for summary - return combine_disks(disk for device, disk in disks if not device.startswith("LVM ")) - - -class MetricSpecs(TypedDict, total=False): - value_scale: float - levels_key: str - levels_scale: float - render_func: Callable[[float], str] - label: str - in_service_output: bool - - -_METRICS: tuple[tuple[str, MetricSpecs], ...] = ( - ( - "utilization", - { - "render_func": lambda x: render.percent(x * 100), - }, - ), - ( - "read_throughput", - { - "render_func": render.iobandwidth, - "label": "Read", - "in_service_output": True, - }, - ), - ( - "write_throughput", - { - "render_func": render.iobandwidth, - "label": "Write", - "in_service_output": True, - }, - ), - ( - "average_wait", - { - "render_func": render.timespan, - }, - ), - ( - "average_read_wait", - { - "render_func": render.timespan, - }, - ), - ( - "average_write_wait", - { - "render_func": render.timespan, - }, - ), - ( - "queue_length", - { - "render_func": lambda x: "%.2f" % x, - "label": "Average queue length", - }, - ), - ( - "read_ql", - { - "render_func": lambda x: "%.2f" % x, - "label": "Average read queue length", - }, - ), - ( - "write_ql", - { - "render_func": lambda x: "%.2f" % x, - "label": "Average write queue length", - }, - ), - ( - "read_ios", - { - "render_func": lambda x: "%.2f/s" % x, - "label": "Read operations", - }, - ), - ( - "write_ios", - { - "render_func": lambda x: "%.2f/s" % x, - "label": "Write operations", - }, - ), - ( - "latency", - { - "render_func": render.timespan, - "in_service_output": True, - }, - ), - ( - "read_latency", - { - "render_func": render.timespan, - }, - ), - ( - "write_latency", - { - "render_func": render.timespan, - }, - ), -) - - -def _get_averaged_disk( - averaging: int, - disk: Disk, - value_store: MutableMapping, - this_time: float, -) -> Generator[Result, None, Disk]: - """Yield a result indicating averaging and return averaged disk - - Note: this check uses a simple method of averaging: As soon as averaging - is turned on the actual metrics are *replaced* by the averaged ones. No - duplication of performance data or check output here. This is because we - have so many metrics... - here, a value in seconds must be provided (preferably from the ruleset "diskstat"); note that - the deprecated ruleset "disk_io" uses minutes for this field and is therefore incompatible - with this function - """ - yield Result( - state=State.OK, - notice="All values averaged over %s" % render.timespan(averaging), - ) - return { - key: get_average( - value_store=value_store, - # We add 'check_diskstat_dict' to the key to avoid possible overlap with keys - # used in check plug-ins. For example, for the SUMMARY-item, the check plug-in - # winperf_phydisk first computes all rates for all items using 'metric.item' as - # key and then summarizes the disks. Hence, for a disk called 'avg', these keys - # would be the same as the keys used here. - key="check_diskstat_dict.%s.avg" % key, - time=this_time, - value=value, - backlog_minutes=averaging / 60.0, - ) - for key, value in list(disk.items()) - if isinstance(value, (int, float)) - } - - -def compute_rates( - *, - disk: Disk, - value_store: MutableMapping[str, Any], - this_time: float, - disk_name: str = "", -) -> Disk: - """Compute rates for a single disk. - - Args: - disk: Dictionary holding various disk metrics - value_store: The value_store - this_time: Monotonic time in seconds - disk_name: Can be empty when used for a single disk item, if item == - 'SUMMARIZE' the disk_name must hold the item name of the disk. - - Example: - >>> from contextlib import suppress - >>> VALUE_STORE = {} # use the real value_store via get_value_store() - >>> DISK = {"read_throughput": 60000, "write_throughput": 0} - >>> with suppress(IgnoreResultsError): - ... # first computation will throw error as value_store is empty - ... compute_rates(disk=DISK, value_store=VALUE_STORE, this_time=0) - >>> DISK = {"read_throughput": 61024, "write_throughput": 1024*1024} - >>> compute_rates(disk=DISK, value_store=VALUE_STORE, this_time=10) - {'read_throughput': 102.4, 'write_throughput': 104857.6} - - """ - disk_with_rates = {} - initialized = [] - for key, value in disk.items(): - counter = f"{key}{disk_name}" - try: - disk_with_rates[key] = get_rate( - value_store, - counter, - this_time, - value, - raise_overflow=True, - ) - except IgnoreResultsError: - initialized.append(counter) - if initialized: - raise IgnoreResultsError(f"Initialized counters: {', '.join(initialized)}") - return disk_with_rates - - -# Example: -# disks = { "sda" : { -# 'average_read_request_size' : 0.0, -# 'average_read_wait' : 0.0, -# 'average_request_size' : 40569.90476190476, -# 'average_wait' : 0.761904761904762, -# 'average_write_request_size' : 40569.90476190476, -# 'average_write_wait' : 0.0007619047619047619, -# 'read_ios' : 0.0, -# 'read_throughput' : 0.0, -# 'latency' : 0.00038095238095238096, -# 'utilization' : 0.0006153846153846154, -# 'write_ios' : 1.6153846153846154, -# 'write_throughput' : 65536.0, -# 'queue_length' : 0.0, -# 'read_ql' : 0.0, -# 'write_ql' : 0.0, -# }} -def check_diskstat_dict( - *, - params: Mapping[str, Any], - disk: Disk, - value_store: MutableMapping, - this_time: float, - generate_latency_metric: bool = False, # SUP-17975 -) -> CheckResult: - if not disk: - return - - averaging = params.get("average") - if averaging: - disk = yield from _get_averaged_disk(averaging, disk, value_store, this_time) - - for key, specs in _METRICS: - metric_val = disk.get(key) - if metric_val is not None: - levels = params.get(key) - metric_name = "disk_" + key - render_func = specs.get("render_func") - label = specs.get("label") or key.replace("_", " ").capitalize() - notice_only = not specs.get("in_service_output") - - print(f"{key} {levels}") - - if isinstance(levels, dict): - yield from check_levels_predictive( - metric_val, - levels=levels, - metric_name=metric_name, - render_func=render_func, - label=label, - ) - else: - yield from check_levels( - metric_val, - levels_upper=levels, - metric_name=metric_name, - render_func=render_func, - label=label, - notice_only=notice_only, - ) - - # make sure we have a latency. - if "latency" not in disk and "average_write_wait" in disk and "average_read_wait" in disk: - latency = max(disk["average_write_wait"], disk["average_read_wait"]) - levels = params.get("latency") - yield from check_levels( - latency, - levels_upper=levels, - metric_name="disk_latency" if generate_latency_metric else None, - render_func=render.timespan, - label="Latency", - ) - - # All the other metrics are currently not output in the plug-in output - simply because - # of their amount. They are present as performance data and will shown in graphs. - - # Send everything as performance data now. Sort keys alphabetically - for key in sorted(set(disk) - {m for m, _ in _METRICS}): - value = disk[key] - if isinstance(value, (int, float)): - # Currently the levels are not shown in the perfdata - yield Metric("disk_" + key, value) diff --git a/graphing/dell_storage.py b/graphing/dell_storage.py new file mode 100644 index 0000000..7c3e29f --- /dev/null +++ b/graphing/dell_storage.py @@ -0,0 +1,121 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +# checkmk_dell_storage - Checkmk extension for Dell Storage API +# +# Copyright (C) 2021-2024 Marius Rieder +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +from cmk.graphing.v1 import graphs, metrics, perfometers, translations, Title + +translation_dell_storage_center = translations.Translation( + name='dell_storage_center', + check_commands=[translations.PassiveCheck('dell_storage_center')], + translations={ + 'disk': translations.RenameTo('dell_storage_center_disk'), + 'volume': translations.RenameTo('dell_storage_center_volume'), + 'live_volume': translations.RenameTo('dell_storage_center_live_volume'), + }, +) + +translation_dell_storage_disk = translations.Translation( + name='dell_storage_disk', + check_commands=[translations.PassiveCheck('dell_storage_disk')], + translations={ + 'usage': translations.RenameTo('dell_storage_disk_usage'), + }, +) + +translation_dell_storage_volume = translations.Translation( + name='dell_storage_volume', + check_commands=[translations.PassiveCheck('dell_storage_volume')], + translations={ + 'usage': translations.RenameTo('dell_storage_volume_usage'), + }, +) + +metric_dell_storage_center_disk = metrics.Metric( + name='dell_storage_center_disk', + title=Title('Disks'), + unit=metrics.Unit(metrics.DecimalNotation("")), + color=metrics.Color.GREEN, +) + +metric_dell_storage_center_volume = metrics.Metric( + name='dell_storage_center_volume', + title=Title('Volumes'), + unit=metrics.Unit(metrics.DecimalNotation("")), + color=metrics.Color.GREEN, +) + +metric_dell_storage_center_live_volume = metrics.Metric( + name='dell_storage_center_live_volume', + title=Title('Live Volumes'), + unit=metrics.Unit(metrics.DecimalNotation("")), + color=metrics.Color.GREEN, +) + +metric_dell_storage_disk_usage = metrics.Metric( + name='dell_storage_disk_usage', + title=Title('Disk Usage'), + unit=metrics.Unit(metrics.SINotation("bytes")), + color=metrics.Color.ORANGE, +) + +metric_dell_storage_volume_usage = metrics.Metric( + name='dell_storage_volume_usage', + title=Title('Volume Usage'), + unit=metrics.Unit(metrics.SINotation("bytes")), + color=metrics.Color.ORANGE, +) + +graph_dell_storage_center_disk = graphs.Graph( + name='dell_storage_center_disk', + title=Title('Storage Center Disks'), + simple_lines=[ + 'dell_storage_center_disk', + 'dell_storage_center_volume', + 'dell_storage_center_live_volume', + ], +) + +graph_dell_storage_disk_usage = graphs.Graph( + name='dell_storage_disk_usage', + title=Title('Disk usage'), + minimal_range=graphs.MinimalRange(0, 100), + compound_lines=['dell_storage_disk_usage'], +) + +graph_dell_storage_volume_usage = graphs.Graph( + name='dell_storage_volume_usage', + title=Title('Volume usage'), + minimal_range=graphs.MinimalRange(0, 100), + compound_lines=['dell_storage_volume_usage'], +) + +perfometer_dell_storage_center = perfometers.Stacked( + name='dell_storage_center', + upper=perfometers.Perfometer( + name='dell_storage_center_disk', + focus_range=perfometers.FocusRange(perfometers.Closed(0), perfometers.Open(10)), + segments=['dell_storage_center_disk'], + ), + lower=perfometers.Perfometer( + name='dell_storage_center_volume', + focus_range=perfometers.FocusRange(perfometers.Closed(0), perfometers.Open(10)), + segments=['dell_storage_center_volume'], + ), +) diff --git a/agents/special/agent_dell_storage b/lib/agent.py similarity index 80% rename from agents/special/agent_dell_storage rename to lib/agent.py index 395aaea..e279220 100644 --- a/agents/special/agent_dell_storage +++ b/lib/agent.py @@ -19,20 +19,22 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from typing import Optional, Sequence import re +from typing import Optional, Sequence import time import datetime import logging import requests from functools import cached_property -from cmk.special_agents.utils.agent_common import ( +from cmk.special_agents.v0_unstable.agent_common import ( + ConditionalPiggybackSection, + SectionWriter, special_agent_main, ) -from cmk.special_agents.utils.argument_parsing import ( +from cmk.special_agents.v0_unstable.argument_parsing import ( Args, - create_default_argument_parser, + create_default_argument_parser ) import urllib3 @@ -165,9 +167,13 @@ def _instanciate(self, obj): def _fields(self): return self.AGENT_DEFAULT_FIELDS + self.AGENT_FIELDS - def to_agent(self, separator=';'): + def __str__(self, separator=';'): return separator.join([str(getattr(self, field, '')) for field in self._fields()]) + @property + def safeInstanceName(self): + return re.sub(r"[^a-zA-Z0-9-_]", "", getattr(self, 'instanceName')) + class StorageCenter(ApiObject): AGENT_FIELDS = [ 'modelSeries', 'version', @@ -504,76 +510,73 @@ def main(self, args: Args): try: self._api = DellStorageApi(args.url, args.user, args.password, args.verify_cert) for storageCenter in self._api.storage_centers: - self.piggyback(storageCenter.instanceName) - self.section('center', [storageCenter]) - - self.section('controller', storageCenter.controllers) + with ConditionalPiggybackSection(storageCenter.safeInstanceName): + with SectionWriter('dell_storage_center', separator=';') as writer: + writer.append(storageCenter) - self.section('enclosure', storageCenter.enclosures) + with SectionWriter('dell_storage_controller', separator=';') as writer: + writer.append(c for c in storageCenter.controllers) - self.section('volume', storageCenter.volumes) + with SectionWriter('dell_storage_enclosure', separator=';') as writer: + writer.append(e for e in storageCenter.enclosures) - self.section('alert', storageCenter.activeAlerts, force=True) + with SectionWriter('dell_storage_volume', separator=';') as writer: + writer.append(v for v in storageCenter.volumes) - print('<<<<>>>>') + with SectionWriter('dell_storage_alert', separator=';') as writer: + writer.append(a for a in storageCenter.activeAlerts) if storageCenter.chassisPresent: - self.piggyback(f'{storageCenter.instanceName}-{storageCenter.chassi.enclosure.instanceName}') - self.section('fan', storageCenter.chassi.fans) + with ConditionalPiggybackSection(f'{storageCenter.safeInstanceName}-{storageCenter.chassi.enclosure.safeInstanceName}'): + with SectionWriter('dell_storage_fan', separator=';') as writer: + writer.append(f for f in storageCenter.chassi.fans) - self.section('psu', storageCenter.chassi.powersupplies) + with SectionWriter('dell_storage_psu', separator=';') as writer: + writer.append(p for p in storageCenter.chassi.powersupplies) - self.section('temp', storageCenter.chassi.temperatures) - print('<<<<>>>>') + with SectionWriter('dell_storage_temp', separator=';') as writer: + writer.append(t for t in storageCenter.chassi.temperatures) for controller in storageCenter.controllers: - self.piggyback(f'{storageCenter.instanceName}-{controller.instanceName}') - self.section('controller', [controller]) + with ConditionalPiggybackSection(f'{storageCenter.safeInstanceName}-{controller.safeInstanceName}'): + with SectionWriter('dell_storage_controller', separator=';') as writer: + writer.append(controller) - self.section('port', controller.ports) + with SectionWriter('dell_storage_port', separator=';') as writer: + writer.append(p for p in controller.ports) - self.section('fan', controller.fans) + with SectionWriter('dell_storage_fan', separator=';') as writer: + writer.append(f for f in controller.fans) - self.section('psu', controller.powersupplies) + with SectionWriter('dell_storage_psu', separator=';') as writer: + writer.append(p for p in controller.powersupplies) - self.section('temp', controller.temperatures) - else: - print('<<<<>>>>') + with SectionWriter('dell_storage_temp', separator=';') as writer: + writer.append(t for t in controller.temperatures) for enclosure in storageCenter.enclosures: - self.piggyback(f'{storageCenter.instanceName}-{enclosure.instanceName}') - self.section('enclosure', [enclosure]) + with ConditionalPiggybackSection(f'{storageCenter.safeInstanceName}-{enclosure.safeInstanceName}'): + with SectionWriter('dell_storage_enclosure', separator=';') as writer: + writer.append(enclosure) - self.section('fan', enclosure.fans) + with SectionWriter('dell_storage_fan', separator=';') as writer: + writer.append(f for f in enclosure.fans) - self.section('disk', enclosure.disks) + with SectionWriter('dell_storage_disk', separator=';') as writer: + writer.append(d for d in enclosure.disks) - self.section('psu', enclosure.powersupplies) + with SectionWriter('dell_storage_psu', separator=';') as writer: + writer.append(p for p in enclosure.powersupplies) - self.section('temp', enclosure.temperatures) - else: - print('<<<<>>>>') + with SectionWriter('dell_storage_temp', separator=';') as writer: + writer.append(t for t in enclosure.temperatures) except Exception as exc: if args.debug: raise end = time.time() - print('<<>>') - print(f'1;;;{end-start};;{exc}') + with SectionWriter('dell_storage_agent', separator=';') as writer: + writer.append(f'1;;;{end - start};;{exc}') else: end = time.time() - print('<<>>') - print(f'0;{self._api.provider};{self._api.providerVersion};{end-start};{self._api.reqcnt};') - - def piggyback(self, name=None): - print(f'<<<<{re.sub(r"[^a-zA-Z0-9-_]", "", name)}>>>>') - - def section(self, name, instances=[], separator=';', force=False): - if not instances and not force: - return - print('<<>>'.format(name=name, sep=ord(separator))) - for instance in instances: - print(instance.to_agent(separator)) - - -if __name__ == '__main__': - AgentDellStorage().run() + with SectionWriter('dell_storage_agent', separator=';') as writer: + writer.append(f'0;{self._api.provider};{self._api.providerVersion};{end - start};{self._api.reqcnt};') diff --git a/agent_based/utils/dell_storage.py b/lib/dell_storage.py similarity index 100% rename from agent_based/utils/dell_storage.py rename to lib/dell_storage.py diff --git a/checks/agent_dell_storage b/libexec/agent_dell_storage similarity index 70% rename from checks/agent_dell_storage rename to libexec/agent_dell_storage index a1c3482..fd064b9 100644 --- a/checks/agent_dell_storage +++ b/libexec/agent_dell_storage @@ -19,16 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import sys -def agent_dell_storage_arguments(params, hostname, ipaddress): - args = [ - '-u', params['user'], - '-p', passwordstore_get_cmdline('%s', params['password']), - '-U', params['url'], - ] - if 'ignore_cert' in params and params['ignore_cert'] != '': - args += ['--ignore-cert'] - return args +from cmk_addons.plugins.dell_storage.lib.agent import AgentDellStorage - -special_agent_info['dell_storage'] = agent_dell_storage_arguments +if __name__ == "__main__": + sys.exit(AgentDellStorage().run()) diff --git a/package b/package index 103dd96..29e2b9f 100644 --- a/package +++ b/package @@ -1,50 +1,43 @@ { - 'author': u'Marius Rieder ', + 'author': u'Marius Rieder ', 'description': u'Check Dell Storage Managed by the Dell Storage Manager with the Storage REST API.', 'download_url': 'https://github.com/jiuka/checkmk_dell_storage/releases', 'files': { - 'agent_based': [ - 'dell_storage_agent.py', - 'dell_storage_alert.py', - 'dell_storage_center.py', - 'dell_storage_controller.py', - 'dell_storage_disk.py', - 'dell_storage_enclosure.py', - 'dell_storage_fan.py', - 'dell_storage_port.py', - 'dell_storage_psu.py', - 'dell_storage_temp.py', - 'dell_storage_volume.py', - 'utils/dell_storage.py', + 'cmk_addons_plugins': [ + 'dell_storage/agent_based/dell_storage_agent.py', + 'dell_storage/agent_based/dell_storage_alert.py', + 'dell_storage/agent_based/dell_storage_center.py', + 'dell_storage/agent_based/dell_storage_controller.py', + 'dell_storage/agent_based/dell_storage_disk.py', + 'dell_storage/agent_based/dell_storage_enclosure.py', + 'dell_storage/agent_based/dell_storage_fan.py', + 'dell_storage/agent_based/dell_storage_port.py', + 'dell_storage/agent_based/dell_storage_psu.py', + 'dell_storage/agent_based/dell_storage_temp.py', + 'dell_storage/agent_based/dell_storage_volume.py', + 'dell_storage/checkman/dell_storage_agent', + 'dell_storage/checkman/dell_storage_alert', + 'dell_storage/checkman/dell_storage_center', + 'dell_storage/checkman/dell_storage_controller', + 'dell_storage/checkman/dell_storage_disk', + 'dell_storage/checkman/dell_storage_enclosure', + 'dell_storage/checkman/dell_storage_fan', + 'dell_storage/checkman/dell_storage_port', + 'dell_storage/checkman/dell_storage_psu', + 'dell_storage/checkman/dell_storage_temp', + 'dell_storage/checkman/dell_storage_volume', + 'dell_storage/graphing/dell_storage.py', + 'dell_storage/lib/agent.py', + 'dell_storage/lib/dell_storage.py', + 'dell_storage/libexec/agent_dell_storage', + 'dell_storage/rulesets/datasource_dell_storage.py', + 'dell_storage/server_side_calls/agent_dell_storage.py', ], - 'agents': ['special/agent_dell_storage'], - 'checkman': [ - 'dell_storage_agent', - 'dell_storage_alert', - 'dell_storage_center', - 'dell_storage_controller', - 'dell_storage_disk', - 'dell_storage_enclosure', - 'dell_storage_fan', - 'dell_storage_port', - 'dell_storage_psu', - 'dell_storage_temp', - 'dell_storage_volume', - ], - 'checks': ['agent_dell_storage'], - 'doc': [], - 'inventory': [], - 'notifications': [], - 'pnp-templates': [], - 'web': [ - 'plugins/metrics/dell_storage.py', - 'plugins/wato/datasource_dell_storage.py', - ] }, 'name': 'dell_storage', 'title': u'Checkmk Dell Storage API Special-Agent', - 'version': '0.6.2', - 'version.min_required': '2.1.0', - 'version.packaged': '2.2.0', - 'version.usable_until': '2.3.0' + 'version': '2.3.0-1', + 'version.min_required': '2.3.0p3', + 'version.packaged': '2.3.0', + 'version.usable_until': '2.4.0' } \ No newline at end of file diff --git a/rulesets/datasource_dell_storage.py b/rulesets/datasource_dell_storage.py new file mode 100644 index 0000000..43ab4f7 --- /dev/null +++ b/rulesets/datasource_dell_storage.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +# checkmk_dell_storage - Checkmk extension for Dell Storage API +# +# Copyright (C) 2021-2024 Marius Rieder +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +from cmk.rulesets.v1 import Title, Help +from cmk.rulesets.v1.form_specs import ( + DefaultValue, + DictElement, + Dictionary, + migrate_to_password, + Password, + SingleChoice, + SingleChoiceElement, + String, + validators, +) +from cmk.rulesets.v1.rule_specs import SpecialAgent, Topic + + +def migrate_bool_to_choice(model: object) -> str: + if isinstance(model, bool): + return 'ignore_cert' if model else 'check_cert' + return model + + +def _form_special_agents_dell_storage() -> Dictionary: + return Dictionary( + title=Title('Dell Storage via Dell Storage API'), + elements={ + 'url': DictElement( + parameter_form=String( + title=Title('URL of the Dell Storage API, e.g. https://host:3033/api/rest/'), + custom_validate=( + validators.Url( + [validators.UrlProtocol.HTTP, validators.UrlProtocol.HTTPS], + ), + ), + ), + required=True, + ), + 'user': DictElement( + parameter_form=String( + title=Title('Dell Storage API username.'), + ), + required=True, + ), + 'password': DictElement( + parameter_form=Password( + title=Title('Dell Storage API password'), + migrate=migrate_to_password + ), + required=True, + ), + 'ignore_cert': DictElement( + parameter_form=SingleChoice( + title=Title('SSL certificate checking'), + elements=[ + SingleChoiceElement(name='ignore_cert', title=Title('Ignore Cert')), + SingleChoiceElement(name='check_cert', title=Title('Check Cert')), + ], + prefill=DefaultValue('check_cert'), + migrate=migrate_bool_to_choice, + ), + required=True, + ), + } + ) + + +rule_spec_dell_storage_datasource = SpecialAgent( + name="dell_storage", + title=Title('Dell Storage via Dell Storage API'), + help_text=Help( + 'This rule selects the Dell Storage API agent instead of ' + 'the normal Check_MK Agent and allows monitoring of ' + 'Dell Storage Manager systems and volumes by REST. ' + 'You can configure your connection settings here.' + ), + topic=Topic.STORAGE, + parameter_form=_form_special_agents_dell_storage, +) diff --git a/server_side_calls/agent_dell_storage.py b/server_side_calls/agent_dell_storage.py new file mode 100644 index 0000000..dec3102 --- /dev/null +++ b/server_side_calls/agent_dell_storage.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +# checkmk_dell_storage - Checkmk extension for Dell Storage API +# +# Copyright (C) 2021-2024 Marius Rieder +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +from collections.abc import Iterator + +from pydantic import BaseModel + +from cmk.server_side_calls.v1 import HostConfig, Secret, SpecialAgentCommand, SpecialAgentConfig + + +class Params(BaseModel): + url: str + user: str + password: Secret | None = None + ignore_cert: str = 'check_cert' + + +def commands_function( + params: Params, + host_config: HostConfig, +) -> Iterator[SpecialAgentCommand]: + command_arguments: list[str | Secret] = [ + '-u', params.user, + '-p', params.password.unsafe(), + '-U', params.url, + ] + if params.ignore_cert != 'check_cert': + command_arguments += ['--ignore-cert'] + yield SpecialAgentCommand(command_arguments=command_arguments) + + +special_agent_dell_storage = SpecialAgentConfig( + name='dell_storage', + parameter_parser=Params.model_validate, + commands_function=commands_function, +) diff --git a/tests/integration/agents/special/fixtures/ApiConnection/ApiConnection/0/StorageCenterList b/tests/integration/lib/fixtures/ApiConnection/ApiConnection/0/StorageCenterList similarity index 100% rename from tests/integration/agents/special/fixtures/ApiConnection/ApiConnection/0/StorageCenterList rename to tests/integration/lib/fixtures/ApiConnection/ApiConnection/0/StorageCenterList diff --git a/tests/integration/agents/special/fixtures/ApiConnection/Login b/tests/integration/lib/fixtures/ApiConnection/Login similarity index 100% rename from tests/integration/agents/special/fixtures/ApiConnection/Login rename to tests/integration/lib/fixtures/ApiConnection/Login diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/Enclosure b/tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/Enclosure similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/Enclosure rename to tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/Enclosure diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/FanSensorList b/tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/FanSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/FanSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/FanSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/PowerSupplyList b/tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/PowerSupplyList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/PowerSupplyList rename to tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/PowerSupplyList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/TemperatureSensorList b/tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/TemperatureSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScChassis/123456/TemperatureSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScChassis/123456/TemperatureSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/FanSensorList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/FanSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/FanSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/FanSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/PhysicalControllerPortList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/PhysicalControllerPortList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/PhysicalControllerPortList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/PhysicalControllerPortList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/PowerSupplyList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/PowerSupplyList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/PowerSupplyList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/PowerSupplyList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/TemperatureSensorList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/TemperatureSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123456/TemperatureSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123456/TemperatureSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/FanSensorList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/FanSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/FanSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/FanSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/PhysicalControllerPortList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/PhysicalControllerPortList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/PhysicalControllerPortList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/PhysicalControllerPortList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/PowerSupplyList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/PowerSupplyList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/PowerSupplyList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/PowerSupplyList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/TemperatureSensorList b/tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/TemperatureSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScController/123456.123457/TemperatureSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScController/123456.123457/TemperatureSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567802.45/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567802.45/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567802.45/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567802.45/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567804.49/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567804.49/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567804.49/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567804.49/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567818.36/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567818.36/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567818.36/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567818.36/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567824.57/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567824.57/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567824.57/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScControllerPort/123456.1234567891234567824.57/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.1/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.1/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.1/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.1/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.1/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.1/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.1/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.1/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.10/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.10/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.10/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.10/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.10/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.10/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.10/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.10/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.22/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.22/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.22/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.22/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.22/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.22/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.22/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.22/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.23/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.23/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.23/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.23/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.23/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.23/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScDisk/123456.23/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScDisk/123456.23/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/CoolingFanSensorList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/CoolingFanSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/CoolingFanSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/CoolingFanSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/DiskList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/DiskList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/DiskList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/DiskList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/PowerSupplyList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/PowerSupplyList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/PowerSupplyList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/PowerSupplyList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/TemperatureSensorList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/TemperatureSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.1/TemperatureSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.1/TemperatureSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/CoolingFanSensorList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/CoolingFanSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/CoolingFanSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/CoolingFanSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/DiskList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/DiskList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/DiskList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/DiskList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/PowerSupplyList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/PowerSupplyList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/PowerSupplyList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/PowerSupplyList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/TemperatureSensorList b/tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/TemperatureSensorList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScEnclosure/123456.2/TemperatureSensorList rename to tests/integration/lib/fixtures/StorageCenter/ScEnclosure/123456.2/TemperatureSensorList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.11/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.11/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.11/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.11/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.11/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.11/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.11/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.11/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.12/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.12/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.12/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.12/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.12/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.12/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.12/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.12/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.13/GetHistoricalIoUsage b/tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.13/GetHistoricalIoUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.13/GetHistoricalIoUsage rename to tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.13/GetHistoricalIoUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.13/StorageUsage b/tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.13/StorageUsage similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/ScVolume/123456.13/StorageUsage rename to tests/integration/lib/fixtures/StorageCenter/ScVolume/123456.13/StorageUsage diff --git a/tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/ActiveAlertList b/tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/ActiveAlertList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/ActiveAlertList rename to tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/ActiveAlertList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/Chassis b/tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/Chassis similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/Chassis rename to tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/Chassis diff --git a/tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/ControllerList b/tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/ControllerList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/ControllerList rename to tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/ControllerList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/EnclosureList b/tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/EnclosureList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/EnclosureList rename to tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/EnclosureList diff --git a/tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/ObjectCount b/tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/ObjectCount similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/ObjectCount rename to tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/ObjectCount diff --git a/tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/VolumeList b/tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/VolumeList similarity index 100% rename from tests/integration/agents/special/fixtures/StorageCenter/StorageCenter/123456/VolumeList rename to tests/integration/lib/fixtures/StorageCenter/StorageCenter/123456/VolumeList diff --git a/tests/integration/agents/special/test_int_agent_dell_storage.py b/tests/integration/lib/test_agent.py similarity index 90% rename from tests/integration/agents/special/test_int_agent_dell_storage.py rename to tests/integration/lib/test_agent.py index 11e4573..5dffe59 100644 --- a/tests/integration/agents/special/test_int_agent_dell_storage.py +++ b/tests/integration/lib/test_agent.py @@ -24,12 +24,7 @@ import pytest # type: ignore[import] import requests # noqa: F401 -from importlib.util import spec_from_loader, module_from_spec -from importlib.machinery import SourceFileLoader - -spec = spec_from_loader("agent_dell_storage", SourceFileLoader("agent_dell_storage", "agents/special/agent_dell_storage")) -agent_dell_storage = module_from_spec(spec) -spec.loader.exec_module(agent_dell_storage) +from cmk_addons.plugins.dell_storage.lib.agent import AgentDellStorage, DellStorageApi def text_callback(request, context): @@ -48,7 +43,7 @@ def api(requests_mock): requests_mock.register_uri('GET', matcher, text=text_callback) requests_mock.register_uri('POST', matcher, text=text_callback) - return agent_dell_storage.DellStorageApi('http://dsa:3033/rest/api', 'user', 'pass', True) + return DellStorageApi('http://dsa:3033/rest/api', 'user', 'pass', True) class Args: @@ -60,16 +55,13 @@ class Args: def test_AgentDellStorage_main(capsys, api): - agent = agent_dell_storage.AgentDellStorage() + agent = AgentDellStorage() agent.main(Args()) captured = capsys.readouterr() assert captured.err == "" assert captured.out.splitlines()[:-1] == '''\ -<<>> -Version: 18.1.20.114 -AgentOS: EnterpriseManager <<<>>> <<>> SAN;Up;;Sc5000Series;7.3.20.19;ABCD123;123456;0;2;44;0;38;0;8;19 @@ -103,15 +95,20 @@ def test_AgentDellStorage_main(capsys, api): <<>> 5555555555555526;Up;;True;Sas;5555555555555526;619;26691584;0.000336;1360;126127104;0.000118 555555555555552C;Up;;True;Iscsi;555555555555552C;;;;;; +<<>> +<<>> <<>> BBU;Up;;None;25;-128;-7;10;55;65;127 CPU One;Up;;None;46;-128;3;8;92;97;127 +<<<<>>>> <<<>>> <<>> Top Controller;Up;;1970-01-01T01:00:00+01:00;True;Sc5020;7.3.20.19;ABCD123;123-456-789-00;123456 <<>> 5555555555555518;Up;;True;Iscsi;5555555555555518;13;657408;0.002293;148;2349056;0.000584 5555555555555516;Up;;True;Iscsi;5555555555555516;14;724992;0.002398;151;2310144;0.000549 +<<>> +<<>> <<>> CPU One;Up;;None;45;-128;3;8;92;97;127 BBU;Up;;None;27;-128;-7;10;55;65;127 @@ -119,9 +116,13 @@ def test_AgentDellStorage_main(capsys, api): <<<>>> <<>> Enclosure - 1;Up;;EN-SC5020;1.05;SasEbod12g;30;ABCD123;123-456-789-00 +<<>> <<>> 01-16;Up;;360081014784;1800360124416;2;74752;0.003753;0;0;0.0 01-08;Up;;1661088579584;1800360124416;;;;;; +<<>> +<<>> +<<<<>>>> <<<>>> <<>> Enclosure - 2;Up;;EN-SC420;1.09;SasEbod12g;24;JKSRF82;123-456-789-01 diff --git a/tests/unit/agents/special/test_agent_dell_storag.py b/tests/unit/lib/test_agent.py similarity index 82% rename from tests/unit/agents/special/test_agent_dell_storag.py rename to tests/unit/lib/test_agent.py index 374c1ff..41bba26 100644 --- a/tests/unit/agents/special/test_agent_dell_storag.py +++ b/tests/unit/lib/test_agent.py @@ -22,12 +22,10 @@ import pytest # type: ignore[import] import requests # noqa: F401 -from importlib.util import spec_from_loader, module_from_spec -from importlib.machinery import SourceFileLoader - -spec = spec_from_loader("agent_dell_storage", SourceFileLoader("agent_dell_storage", "agents/special/agent_dell_storage")) -agent_dell_storage = module_from_spec(spec) -spec.loader.exec_module(agent_dell_storage) +from cmk_addons.plugins.dell_storage.lib.agent import ( + DellStorageApi, + DellStorageApiParser +) class TestDellStorageApiParser: @@ -37,28 +35,28 @@ class TestDellStorageApiParser: ('100 °C / 212 °F', 100), ]) def test_DellStorageApiParser_temperature(self, value, result): - assert agent_dell_storage.DellStorageApiParser.temperature(value) == result + assert DellStorageApiParser.temperature(value) == result @pytest.mark.parametrize('value, result', [ ('10', 10240), ('1', 1024), ]) def test_DellStorageApiParser_kbps(self, value, result): - assert agent_dell_storage.DellStorageApiParser.kbps(value) == result + assert DellStorageApiParser.kbps(value) == result @pytest.mark.parametrize('value, result', [ ('1000000', 1), ('1', 0.000001), ]) def test_DellStorageApiParser_latency(self, value, result): - assert agent_dell_storage.DellStorageApiParser.latency(value) == result + assert DellStorageApiParser.latency(value) == result @pytest.mark.parametrize('value, result', [ ('10 Bit', 10), ('123 Bit', 123), ]) def test_DellStorageApiParser_space(self, value, result): - assert agent_dell_storage.DellStorageApiParser.space(value) == result + assert DellStorageApiParser.space(value) == result LOGIN_RESP = dict(provider='PRO', providerVersion='VERS', instanceId='123') @@ -71,7 +69,7 @@ def api(self, requests_mock): requests_mock.post('http://dsa:3033/rest/api/ApiConnection/Login', json=LOGIN_RESP) requests_mock.get('http://dsa:3033/rest/api/ApiConnection/ApiConnection/123/StorageCenterList', json=STORAGE_CENTERS) - return agent_dell_storage.DellStorageApi('http://dsa:3033/rest/api', 'user', 'pass', True) + return DellStorageApi('http://dsa:3033/rest/api', 'user', 'pass', True) def test_init(self, api): assert api._api['provider'] == 'PRO' @@ -84,7 +82,7 @@ def test_url(self, api, call, result): assert api.url(call) == result def test_storage_centers(self, api, requests_mock): - assert type(api.storage_centers[0]) == agent_dell_storage.DellStorageApi.StorageCenter + assert isinstance(api.storage_centers[0], DellStorageApi.StorageCenter) def test_storage_centers_cached(self, api, requests_mock): api.storage_centers @@ -110,7 +108,7 @@ def test_providerVersion(self, api): assert api.providerVersion == 'VERS' class TestApiObject: - class MockApiObject(agent_dell_storage.DellStorageApi.ApiObject): + class MockApiObject(DellStorageApi.ApiObject): AGENT_FIELDS = ['foo'] instanceId: str diff --git a/tests/unit/agent_based/utils/test_dell_storage.py b/tests/unit/lib/test_dell_storage.py similarity index 97% rename from tests/unit/agent_based/utils/test_dell_storage.py rename to tests/unit/lib/test_dell_storage.py index b941c73..cca728d 100644 --- a/tests/unit/agent_based/utils/test_dell_storage.py +++ b/tests/unit/lib/test_dell_storage.py @@ -25,7 +25,7 @@ Result, State, ) -from cmk.base.plugins.agent_based.utils import dell_storage +from cmk_addons.plugins.dell_storage.lib import dell_storage @pytest.mark.parametrize('value, result', [ diff --git a/web/plugins/metrics/dell_storage.py b/web/plugins/metrics/dell_storage.py deleted file mode 100644 index 23dc4e9..0000000 --- a/web/plugins/metrics/dell_storage.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# -# checkmk_dell_storage - Checkmk extension for Dell Storage API -# -# Copyright (C) 2021-2024 Marius Rieder -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -from cmk.gui.i18n import _ - -from cmk.gui.plugins.metrics import ( - check_metrics, - metric_info, - graph_info, - perfometer_info, -) - -check_metrics['check_mk-dell_storage_center'] = { - 'disk': {'name': 'dell_storage_center_disk'}, - 'volume': {'name': 'dell_storage_center_volume'}, - 'live_volume': {'name': 'dell_storage_center_live_volume'}, -} - -check_metrics['check_mk-dell_storage_disk'] = { - 'usage': {'name': 'dell_storage_disk_usage'}, -} - -check_metrics['check_mk-dell_storage_volume'] = { - 'usage': {'name': 'dell_storage_volume_usage'}, -} - -metric_info['dell_storage_center_disk'] = { - 'title': _('Disks'), - 'unit': 'count', - 'color': '#40c080', -} - -metric_info['dell_storage_center_volume'] = { - 'title': _('Volumes'), - 'unit': 'count', - 'color': '#4080c0', -} - -metric_info['dell_storage_center_live_volume'] = { - 'title': _('Live Volumes'), - 'unit': 'count', - 'color': '#c04080', -} - - -metric_info['dell_storage_disk_usage'] = { - 'title': _('Disk Usage'), - 'unit': 'bytes', - 'color': '#a05830', -} - -metric_info['dell_storage_volume_usage'] = { - 'title': _('Volume Usage'), - 'unit': 'bytes', - 'color': '#a05830', -} - -graph_info['dell_storage_center_disk'] = { - 'title': _('Storage Center Disks'), - 'metrics': [ - ('dell_storage_center_disk', 'line'), - ('dell_storage_center_volume', 'line'), - ('dell_storage_center_live_volume', 'line'), - ], -} - -graph_info['dell_storage_disk_usage'] = { - 'title': _('Disk usage'), - 'metrics': [ - ('dell_storage_disk_usage', 'area'), - ], - 'range': (0, 'dell_storage_disk_usage:max'), -} - -graph_info['dell_storage_volume_usage'] = { - 'title': _('Volume usage'), - 'metrics': [ - ('dell_storage_volume_usage', 'area'), - ], - 'range': (0, 'dell_storage_volume_usage:max'), -} - -perfometer_info.append({ - 'type': 'stacked', - 'perfometers': [{ - 'type': 'logarithmic', - 'metric': 'dell_storage_center_disk', - 'half_value': 10, - 'exponent': 2, - }, { - 'type': 'logarithmic', - 'metric': 'dell_storage_center_volume', - 'half_value': 10, - 'exponent': 2 - }], -}) diff --git a/web/plugins/wato/datasource_dell_storage.py b/web/plugins/wato/datasource_dell_storage.py deleted file mode 100644 index afd0c61..0000000 --- a/web/plugins/wato/datasource_dell_storage.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python3 -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# -# checkmk_dell_storage - Checkmk extension for Dell Storage API -# -# Copyright (C) 2021-2024 Marius Rieder -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -from cmk.gui.i18n import _ -from cmk.gui.plugins.wato import ( - HostRulespec, - IndividualOrStoredPassword, - rulespec_registry, -) -from cmk.gui.valuespec import ( - Alternative, - Dictionary, - FixedValue, - HTTPUrl, - TextAscii, -) -from cmk.gui.plugins.wato.datasource_programs import RulespecGroupDatasourceProgramsHardware - - -def _valuespec_special_agents_dell_storage(): - return Dictionary( - title = _('Dell Storage via Dell Storage API'), - help = _('This rule selects the Dell Storage API agent instead of ' - 'the normal Check_MK Agent and allows monitoring of ' - 'Dell Storage Manager systems and volumes by REST. ' - 'You can configure your connection settings here.' - ), - elements=[ - ( - 'url', - HTTPUrl( - title = _('URL of the Dell Storage API, e.g. https://host:3033/api/rest/'), - allow_empty = False, - ) - ), - ( - 'user', - TextAscii( - title = _('Dell Storage API username.'), - allow_empty = False, - ) - ), - ( - 'password', - IndividualOrStoredPassword( - title = _('Dell Storage API password'), - allow_empty = False, - ) - ), - ( - 'ignore_cert', - Alternative( - title = _('SSL certificate checking'), - elements = [ - FixedValue(True, title = _('Ignore Cert'), totext=''), - FixedValue(False, title = _('Check Cert'), totext=''), - ], - default_value = False - ) - ), - ] - ) - - -rulespec_registry.register( - HostRulespec( - group=RulespecGroupDatasourceProgramsHardware, - name='special_agents:dell_storage', - valuespec=_valuespec_special_agents_dell_storage, - ))