-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate agent_vnx_quotas to SSC and ruleset APIs
CMK-17408 Change-Id: Iffe69890d87b874113db0e5c112e2028b292dbc2
- Loading branch information
Showing
8 changed files
with
160 additions
and
129 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ | |
"random": False, # needs no secret | ||
"mqtt": True, | ||
"splunk": True, | ||
"vnx_quotas": True, | ||
} | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
tests/unit/cmk/plugins/vnx_quotas/server_side_calls/test_special_agent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,6 @@ | |
"salesforce", | ||
"smb_share", | ||
"ucs_bladecenter", | ||
"vnx_quotas", | ||
} | ||
|
||
|
||
|