Skip to content

Commit

Permalink
Migrate agent_vnx_quotas to SSC and ruleset APIs
Browse files Browse the repository at this point in the history
CMK-17408

Change-Id: Iffe69890d87b874113db0e5c112e2028b292dbc2
  • Loading branch information
racicLuka committed Oct 20, 2024
1 parent 66cb817 commit 2a56201
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 129 deletions.
35 changes: 0 additions & 35 deletions cmk/base/legacy_checks/agent_vnx_quotas.py

This file was deleted.

36 changes: 0 additions & 36 deletions cmk/gui/plugins/wato/special_agents/vnx_quotas.py

This file was deleted.

50 changes: 50 additions & 0 deletions cmk/plugins/vnx_quotas/rulesets/special_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# Copyright (C) 2024 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.


from cmk.rulesets.v1 import Title
from cmk.rulesets.v1.form_specs import (
DictElement,
Dictionary,
migrate_to_password,
Password,
String,
)
from cmk.rulesets.v1.rule_specs import SpecialAgent, Topic


def _paramater_form() -> Dictionary:
return Dictionary(
title=Title("VNX quotas and filesystems"),
elements={
"user": DictElement(
required=True,
parameter_form=String(
title=Title("NAS DB user name"),
),
),
"password": DictElement(
required=True,
parameter_form=Password(
title=Title("Password"),
migrate=migrate_to_password,
),
),
"nas_db": DictElement(
required=True,
parameter_form=String(
title=Title("NAS DB path"),
),
),
},
)


rule_spec_special_agent_vnx_quotas = SpecialAgent(
name="vnx_quotas",
title=Title("VNX quotas and filesystems"),
topic=Topic.STORAGE,
parameter_form=_paramater_form,
)
43 changes: 43 additions & 0 deletions cmk/plugins/vnx_quotas/server_side_calls/special_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# Copyright (C) 2024 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.


from collections.abc import Iterable

from pydantic import BaseModel

from cmk.server_side_calls.v1 import HostConfig, SpecialAgentCommand, SpecialAgentConfig
from cmk.server_side_calls.v1._utils import Secret


class Params(BaseModel):
user: str
password: Secret
nas_db: str


def command_function(
params: Params,
host_config: HostConfig,
) -> Iterable[SpecialAgentCommand]:
command_arguments: list[str | Secret] = [
"-u",
params.user,
"-p",
params.password.unsafe(),
"--nas-db",
params.nas_db,
]

command_arguments.append(host_config.primary_ip_config.address)

yield SpecialAgentCommand(command_arguments=command_arguments)


special_agent_vnx_quotas = SpecialAgentConfig(
name="vnx_quotas",
parameter_parser=Params.model_validate,
commands_function=command_function,
)
1 change: 1 addition & 0 deletions cmk/utils/password_store/hack.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"random": False, # needs no secret
"mqtt": True,
"splunk": True,
"vnx_quotas": True,
}


Expand Down
57 changes: 0 additions & 57 deletions tests/unit/checks/test_agent_vnx_quotas.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# Copyright (C) 2024 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.

from collections.abc import Mapping

import pytest

from cmk.plugins.vnx_quotas.server_side_calls.special_agent import special_agent_vnx_quotas
from cmk.server_side_calls.v1 import HostConfig, IPv4Config, Secret, SpecialAgentCommand

HOST_CONFIG = HostConfig(
name="hostname",
ipv4_config=IPv4Config(address="1.2.3.4"),
)


@pytest.mark.parametrize(
["raw_params", "expected_command"],
[
pytest.param(
{
"user": "username",
"password": Secret(23),
"nas_db": "",
},
SpecialAgentCommand(
command_arguments=[
"-u",
"username",
"-p",
Secret(23).unsafe(),
"--nas-db",
"",
"1.2.3.4",
]
),
id="with explicit password",
),
pytest.param(
{
"user": "username",
"password": Secret(id=1, pass_safely=True),
"nas_db": "",
},
SpecialAgentCommand(
command_arguments=[
"-u",
"username",
"-p",
Secret(id=1, format="%s", pass_safely=False),
"--nas-db",
"",
"1.2.3.4",
]
),
id="with password from store",
),
],
)
def test_special_agent_vnx_quotas_command_creation(
raw_params: Mapping[str, object],
expected_command: SpecialAgentCommand,
) -> None:
assert list(special_agent_vnx_quotas(raw_params, HOST_CONFIG)) == [expected_command]
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"salesforce",
"smb_share",
"ucs_bladecenter",
"vnx_quotas",
}


Expand Down

0 comments on commit 2a56201

Please sign in to comment.