Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmk/plugins/vsphere/rulesets/special_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ def parameter_form() -> Dictionary:
),
),
),
"ignore_templates": DictElement(
required=True,
parameter_form=BooleanChoice(
title=Title("Templates"),
label=Label("Do not monitor VM templates"),
prefill=DefaultValue(False),
help_text=Help(
"A template is created by converting a stopped VM. It cannot be started or modified "
"without converting or cloning it back to a VM. This option tells the vSphere agent "
"to exclude template VMs in its output."
),
),
),
"host_pwr_display": DictElement(
required=False,
parameter_form=SingleChoice(
Expand Down
4 changes: 4 additions & 0 deletions cmk/plugins/vsphere/server_side_calls/special_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Params(BaseModel):
timeout: int | None = None
infos: Sequence[str]
skip_placeholder_vms: bool
ignore_templates: bool
host_pwr_display: str | None = None
vm_pwr_display: str | None = None
snapshots_on_host: bool
Expand All @@ -55,6 +56,9 @@ def commands_function( # pylint: disable=too-many-branches

if params.skip_placeholder_vms:
command_arguments.append("-P")

if params.ignore_templates:
command_arguments.append("-T")

if params.spaces:
command_arguments += ["--spaces", params.spaces]
Expand Down
12 changes: 12 additions & 0 deletions cmk/special_agents/agent_vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,15 @@ def parse_arguments(argv: Sequence[str]) -> argparse.Namespace:
help="""Skip placeholder virtualmachines. These backup vms are created by the Site
Recovery Manager (SRM) and are identified by not having any assigned virtual disks.""",
)
parser.add_argument(
"-T",
"--ignore-templates",
action="store_true",
help="""Ignore Template VMs. A Template is created by converting a stopped VM.
It cannot be started or modified without converting or cloning it back to a VM.

This option suppresses all agent output of Template VMs.""",
)

# optional arguments
parser.add_argument(
Expand Down Expand Up @@ -1880,6 +1889,9 @@ def fetch_virtual_machines(
if vm_data.get("summary.config.ftInfo.role") == "2":
continue # This response coming from the passive fault-tolerance node

if opt.ignore_templates and vm_data.get("config.template") == "true":
continue

if "runtime.host" in vm_data:
vm_data["runtime.host"] = hostsystems.get(
vm_data["runtime.host"], vm_data["runtime.host"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tcp_port": 443,
"direct": "host_system",
"skip_placeholder_vms": True,
"ignore_templates": True,
"ssl": False,
"secret": Secret(23),
"spaces": "cut",
Expand All @@ -45,6 +46,7 @@
"--hostname",
"host",
"-P",
"-T",
"--spaces",
"cut",
"--no-cert-check",
Expand All @@ -61,6 +63,7 @@
"direct": "host_system",
"vm_piggyname": "alias",
"skip_placeholder_vms": True,
"ignore_templates": True,
"ssl": False,
"secret": Secret(id=1, pass_safely=True),
"spaces": "cut",
Expand All @@ -81,6 +84,7 @@
"--hostname",
"host",
"-P",
"-T",
"--spaces",
"cut",
"--vm_piggyname",
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/cmk/special_agents/test_sa_vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"port": 443,
"hostname": None,
"skip_placeholder_vm": False,
"ignore_templates": False,
"host_pwr_display": None,
"vm_pwr_display": None,
"snapshots_on_host": False,
Expand Down Expand Up @@ -45,6 +46,7 @@
(["--hostname", "myHost"], {"hostname": "myHost"}),
(["-H", "myHost"], {"hostname": "myHost"}),
(["-P"], {"skip_placeholder_vm": True}),
(["-T"], {"ignore_templates": True}),
(["--host_pwr_display", "vm"], {"host_pwr_display": "vm"}),
(["--vm_pwr_display", "esxhost"], {"vm_pwr_display": "esxhost"}),
(["--snapshots-on-host"], {"snapshots_on_host": True}),
Expand Down