Skip to content

Commit d8bb9d4

Browse files
committed
make the 'needs_checks' flags explicit
Change-Id: I0a7ea6133d9ffc3c7835424bbfea6774e2114cfd
1 parent e393e73 commit d8bb9d4

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

cmk/base/automations/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def _extract_timeout_from_args(self, args: list[str]) -> tuple[list[str], int |
157157

158158
class Automation(abc.ABC):
159159
cmd: str | None = None
160-
needs_checks = False
161-
needs_config = False
160+
needs_checks: bool
161+
needs_config: bool
162162

163163
@abc.abstractmethod
164164
def execute(

cmk/base/automations/check_mk.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,8 @@ def _delete_robotmk_html_log_dir(self, hostname: HostName) -> None:
17351735

17361736
class AutomationDeleteHosts(ABCDeleteHosts, Automation):
17371737
cmd = "delete-hosts"
1738+
needs_checks = False
1739+
needs_config = False
17381740

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

17841786
cmd = "delete-hosts-known-remote"
1787+
needs_config = False
1788+
needs_checks = False
17851789

17861790
def execute(
17871791
self,

cmk/base/modes/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ def __init__(
356356
argument_conv: ConvertFunction | None = None,
357357
argument_optional: bool = False,
358358
long_help: list[str] | None = None,
359-
needs_config: bool = True,
360-
needs_checks: bool = True,
359+
needs_config: bool,
360+
needs_checks: bool,
361361
sub_options: list[Option] | None = None,
362362
) -> None:
363363
super().__init__(

cmk/base/modes/check_mk.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ def _list_all_hosts(
408408
short_help="Include offline hosts",
409409
),
410410
],
411+
needs_config=True,
412+
needs_checks=True,
411413
)
412414
)
413415

@@ -460,6 +462,8 @@ def _list_all_hosts_with_tags(tags: Sequence[TagID]) -> Sequence[HostName]:
460462
argument_optional=True,
461463
short_help="List hosts having certain tags",
462464
long_help=["Prints all hosts that have all of the specified tags at once."],
465+
needs_config=True,
466+
needs_checks=True,
463467
)
464468
)
465469

@@ -576,6 +580,7 @@ def _get_title(plugin_name: str) -> str:
576580
long_option="list-checks",
577581
short_option="L",
578582
handler_function=mode_list_checks,
583+
needs_checks=True,
579584
needs_config=False,
580585
short_help="List all available Check_MK checks",
581586
)
@@ -745,6 +750,8 @@ def mode_dump_agent(options: Mapping[str, object], hostname: HostName) -> None:
745750
"Does not work on clusters but only on real hosts. "
746751
],
747752
sub_options=[*_FETCHER_OPTIONS[:3], _SNMP_BACKEND_OPTION],
753+
needs_config=True,
754+
needs_checks=True,
748755
)
749756
)
750757

@@ -795,6 +802,8 @@ def mode_dump_hosts(hostlist: Iterable[HostName]) -> None:
795802
"about one, several or all hosts. It shows all services, hostgroups, "
796803
"contacts and other information about that host.",
797804
],
805+
needs_config=True,
806+
needs_checks=True,
798807
)
799808
)
800809

@@ -898,6 +907,8 @@ def mode_update_dns_cache() -> None:
898907
long_option="update-dns-cache",
899908
handler_function=mode_update_dns_cache,
900909
short_help="Update IP address lookup cache",
910+
needs_config=True, # really?
911+
needs_checks=True, # really?
901912
)
902913
)
903914

@@ -924,6 +935,8 @@ def mode_cleanup_piggyback() -> None:
924935
long_option="cleanup-piggyback",
925936
handler_function=mode_cleanup_piggyback,
926937
short_help="Cleanup outdated piggyback files",
938+
needs_config=True,
939+
needs_checks=True,
927940
)
928941
)
929942

@@ -1140,6 +1153,8 @@ def mode_snmpwalk(options: dict, hostnames: list[str]) -> None:
11401153
"You can specify this option multiple times.",
11411154
),
11421155
],
1156+
needs_config=True,
1157+
needs_checks=True,
11431158
)
11441159
)
11451160

@@ -1210,6 +1225,8 @@ def mode_snmpget(options: Mapping[str, object], args: Sequence[str]) -> None:
12101225
"no host is given, all known SNMP hosts are queried."
12111226
],
12121227
sub_options=[_SNMP_BACKEND_OPTION],
1228+
needs_config=True,
1229+
needs_checks=True,
12131230
)
12141231
)
12151232

@@ -1322,14 +1339,15 @@ def mode_flush(hosts: list[HostName]) -> None:
13221339
argument=True,
13231340
argument_descr="HOST1 HOST2...",
13241341
argument_optional=True,
1325-
needs_config=True,
13261342
short_help="Flush all data of some or all hosts",
13271343
long_help=[
13281344
"Deletes all runtime data belonging to a host. This includes "
13291345
"the inventorized checks, the state of performance counters, "
13301346
"cached agent output, and logfiles. Precompiled host checks "
13311347
"are not deleted.",
13321348
],
1349+
needs_config=True,
1350+
needs_checks=True,
13331351
)
13341352
)
13351353

@@ -1414,6 +1432,8 @@ def mode_dump_nagios_config(args: Sequence[HostName]) -> None:
14141432
"of hosts. In that case the configuration is generated only for "
14151433
"that hosts (useful for debugging).",
14161434
],
1435+
needs_config=True,
1436+
needs_checks=True,
14171437
)
14181438
)
14191439

@@ -1475,6 +1495,8 @@ def mode_update() -> None:
14751495
"and the configuration for the Core helper processes is being created.",
14761496
"The Agent Bakery is updating the agents.",
14771497
],
1498+
needs_config=True,
1499+
needs_checks=True,
14781500
)
14791501
)
14801502

@@ -1526,6 +1548,8 @@ def mode_restart(args: Sequence[HostName]) -> None:
15261548
],
15271549
handler_function=mode_restart,
15281550
short_help="Create core config + core restart",
1551+
needs_config=True,
1552+
needs_checks=True,
15291553
)
15301554
)
15311555

@@ -1577,6 +1601,8 @@ def mode_reload(args: Sequence[HostName]) -> None:
15771601
],
15781602
handler_function=mode_reload,
15791603
short_help="Create core config + core reload",
1604+
needs_config=True,
1605+
needs_checks=True,
15801606
)
15811607
)
15821608

@@ -1977,6 +2003,8 @@ def register_mode_check_discovery(
19772003
"autodiscovery"
19782004
],
19792005
sub_options=[*_FETCHER_OPTIONS, _SNMP_BACKEND_OPTION],
2006+
needs_config=True,
2007+
needs_checks=True,
19802008
)
19812009
)
19822010

@@ -2297,6 +2325,8 @@ def section_error_handling(
22972325
short_help="Restrict discovery to host labels only",
22982326
),
22992327
],
2328+
needs_config=True,
2329+
needs_checks=True,
23002330
)
23012331
)
23022332

@@ -2543,6 +2573,8 @@ def register_mode_check(
25432573
_get_plugins_option(CheckPluginName),
25442574
_option_detect_plugins,
25452575
],
2576+
needs_config=True,
2577+
needs_checks=True,
25462578
)
25472579
)
25482580

@@ -2731,6 +2763,8 @@ def section_error_handling(
27312763
_get_plugins_option(InventoryPluginName),
27322764
_option_detect_plugins,
27332765
],
2766+
needs_config=True,
2767+
needs_checks=True,
27342768
)
27352769
)
27362770

@@ -3001,6 +3035,8 @@ def register_mode_inventory_as_check(
30013035
short_help="Use monitoring state S for NW changes",
30023036
),
30033037
],
3038+
needs_config=True,
3039+
needs_checks=True,
30043040
)
30053041
)
30063042

@@ -3135,6 +3171,7 @@ def summarizer(host_name: HostName) -> CMKSummarizer:
31353171
"in the previous run",
31363172
],
31373173
sub_options=[*_FETCHER_OPTIONS, _SNMP_BACKEND_OPTION],
3174+
needs_checks=True,
31383175
needs_config=False,
31393176
)
31403177
)

0 commit comments

Comments
 (0)