Skip to content

Commit

Permalink
make the 'needs_checks' flags explicit
Browse files Browse the repository at this point in the history
Change-Id: I0a7ea6133d9ffc3c7835424bbfea6774e2114cfd
  • Loading branch information
mo-ki committed Feb 12, 2025
1 parent e393e73 commit d8bb9d4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmk/base/automations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def _extract_timeout_from_args(self, args: list[str]) -> tuple[list[str], int |

class Automation(abc.ABC):
cmd: str | None = None
needs_checks = False
needs_config = False
needs_checks: bool
needs_config: bool

@abc.abstractmethod
def execute(
Expand Down
4 changes: 4 additions & 0 deletions cmk/base/automations/check_mk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,8 @@ def _delete_robotmk_html_log_dir(self, hostname: HostName) -> None:

class AutomationDeleteHosts(ABCDeleteHosts, Automation):
cmd = "delete-hosts"
needs_checks = False
needs_config = False

def execute(
self,
Expand Down Expand Up @@ -1782,6 +1784,8 @@ class AutomationDeleteHostsKnownRemote(ABCDeleteHosts, Automation):
local site and are now handled by a remote site"""

cmd = "delete-hosts-known-remote"
needs_config = False
needs_checks = False

def execute(
self,
Expand Down
4 changes: 2 additions & 2 deletions cmk/base/modes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def __init__(
argument_conv: ConvertFunction | None = None,
argument_optional: bool = False,
long_help: list[str] | None = None,
needs_config: bool = True,
needs_checks: bool = True,
needs_config: bool,
needs_checks: bool,
sub_options: list[Option] | None = None,
) -> None:
super().__init__(
Expand Down
39 changes: 38 additions & 1 deletion cmk/base/modes/check_mk.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def _list_all_hosts(
short_help="Include offline hosts",
),
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -460,6 +462,8 @@ def _list_all_hosts_with_tags(tags: Sequence[TagID]) -> Sequence[HostName]:
argument_optional=True,
short_help="List hosts having certain tags",
long_help=["Prints all hosts that have all of the specified tags at once."],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -576,6 +580,7 @@ def _get_title(plugin_name: str) -> str:
long_option="list-checks",
short_option="L",
handler_function=mode_list_checks,
needs_checks=True,
needs_config=False,
short_help="List all available Check_MK checks",
)
Expand Down Expand Up @@ -745,6 +750,8 @@ def mode_dump_agent(options: Mapping[str, object], hostname: HostName) -> None:
"Does not work on clusters but only on real hosts. "
],
sub_options=[*_FETCHER_OPTIONS[:3], _SNMP_BACKEND_OPTION],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -795,6 +802,8 @@ def mode_dump_hosts(hostlist: Iterable[HostName]) -> None:
"about one, several or all hosts. It shows all services, hostgroups, "
"contacts and other information about that host.",
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -898,6 +907,8 @@ def mode_update_dns_cache() -> None:
long_option="update-dns-cache",
handler_function=mode_update_dns_cache,
short_help="Update IP address lookup cache",
needs_config=True, # really?
needs_checks=True, # really?
)
)

Expand All @@ -924,6 +935,8 @@ def mode_cleanup_piggyback() -> None:
long_option="cleanup-piggyback",
handler_function=mode_cleanup_piggyback,
short_help="Cleanup outdated piggyback files",
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1140,6 +1153,8 @@ def mode_snmpwalk(options: dict, hostnames: list[str]) -> None:
"You can specify this option multiple times.",
),
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1210,6 +1225,8 @@ def mode_snmpget(options: Mapping[str, object], args: Sequence[str]) -> None:
"no host is given, all known SNMP hosts are queried."
],
sub_options=[_SNMP_BACKEND_OPTION],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1322,14 +1339,15 @@ def mode_flush(hosts: list[HostName]) -> None:
argument=True,
argument_descr="HOST1 HOST2...",
argument_optional=True,
needs_config=True,
short_help="Flush all data of some or all hosts",
long_help=[
"Deletes all runtime data belonging to a host. This includes "
"the inventorized checks, the state of performance counters, "
"cached agent output, and logfiles. Precompiled host checks "
"are not deleted.",
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1414,6 +1432,8 @@ def mode_dump_nagios_config(args: Sequence[HostName]) -> None:
"of hosts. In that case the configuration is generated only for "
"that hosts (useful for debugging).",
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1475,6 +1495,8 @@ def mode_update() -> None:
"and the configuration for the Core helper processes is being created.",
"The Agent Bakery is updating the agents.",
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1526,6 +1548,8 @@ def mode_restart(args: Sequence[HostName]) -> None:
],
handler_function=mode_restart,
short_help="Create core config + core restart",
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1577,6 +1601,8 @@ def mode_reload(args: Sequence[HostName]) -> None:
],
handler_function=mode_reload,
short_help="Create core config + core reload",
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -1977,6 +2003,8 @@ def register_mode_check_discovery(
"autodiscovery"
],
sub_options=[*_FETCHER_OPTIONS, _SNMP_BACKEND_OPTION],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -2297,6 +2325,8 @@ def section_error_handling(
short_help="Restrict discovery to host labels only",
),
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -2543,6 +2573,8 @@ def register_mode_check(
_get_plugins_option(CheckPluginName),
_option_detect_plugins,
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -2731,6 +2763,8 @@ def section_error_handling(
_get_plugins_option(InventoryPluginName),
_option_detect_plugins,
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -3001,6 +3035,8 @@ def register_mode_inventory_as_check(
short_help="Use monitoring state S for NW changes",
),
],
needs_config=True,
needs_checks=True,
)
)

Expand Down Expand Up @@ -3135,6 +3171,7 @@ def summarizer(host_name: HostName) -> CMKSummarizer:
"in the previous run",
],
sub_options=[*_FETCHER_OPTIONS, _SNMP_BACKEND_OPTION],
needs_checks=True,
needs_config=False,
)
)
Expand Down

0 comments on commit d8bb9d4

Please sign in to comment.