Skip to content

Commit

Permalink
Merge branch 'build/checkmk-24-support' of github.com:Checkmk/ansible…
Browse files Browse the repository at this point in the history
…-collection-checkmk.general into build/checkmk-24-support
  • Loading branch information
robin-checkmk committed Feb 13, 2025
2 parents c597a2e + 41d04e3 commit 551ba2f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ans-int-test-discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
ports:
- 5323:5000
env:
CMK_SITE_ID: "stable_cme"
CMK_SITE_ID: "old_cme"
CMK_PASSWORD: "Sup3rSec4et!"
stable_cre:
image: checkmk/check-mk-raw:2.4.0-daily
Expand Down
4 changes: 4 additions & 0 deletions plugins/doc_fragments/site_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ class ModuleDocFragment(object):
- files below C($OMD_ROOT/local/) on the remote site will be removed.
type: bool
default: true
message_broker_port:
description:
- The port used by the message broker to exchange messages.
type: int
basic_settings:
description:
- A site's basic settings.
Expand Down
3 changes: 3 additions & 0 deletions plugins/module_utils/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ def get_api_data(self, target_api):
default=True,
type="bool",
),
message_broker_port=dict(
type="int",
),
),
),
basic_settings=dict(
Expand Down
51 changes: 27 additions & 24 deletions plugins/modules/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
elements: str
default: []
state:
description: The action to perform during discovery.
description:
- The action to perform during discovery.
- Not all choices are available with all Checkmk versions.
- Check the ReDoc documentation in your site for details.
- In versions 2.4.0 and newer, the modes tabula_rasa and refresh are no longer available,
- in that case, we perform a add/remove all services and labels, instead.
type: str
default: new
choices: [new, remove, fix_all, refresh, tabula_rasa, only_host_labels, only_service_labels, monitor_undecided_services]
Expand Down Expand Up @@ -235,31 +240,32 @@ def post(self):
"update_host_labels": False,
}

if self.params.get("state") in ["new", "fix_all", "monitor_undecided_services"]:
if self.params.get("state") in [
"new",
"fix_all",
"monitor_undecided_services",
"refresh",
]:
options["monitor_undecided_services"] = True
if self.params.get("state") in ["remove", "fix_all"]:
if self.params.get("state") in ["remove", "fix_all", "refresh"]:
options["remove_vanished_services"] = True
if self.params.get("state") in ["only_service_labels"]:
if self.params.get("state") in ["only_service_labels", "refresh"]:
options["update_service_labels"] = True
if self.params.get("state") in ["new", "fix_all", "only_host_labels"]:
if self.params.get("state") in [
"new",
"fix_all",
"only_host_labels",
"refresh",
]:
options["update_host_labels"] = True

if self.params.get("state") == "refresh":
data = {
"hostnames": self.params.get("hosts", []),
"mode": self.params.get("state"),
"do_full_scan": self.params.get("do_full_scan", True),
"bulk_size": self.params.get("bulk_size", 1),
"ignore_errors": self.params.get("ignore_errors", True),
}
else:
data = {
"hostnames": self.params.get("hosts", []),
"options": options,
"do_full_scan": self.params.get("do_full_scan", True),
"bulk_size": self.params.get("bulk_size", 1),
"ignore_errors": self.params.get("ignore_errors", True),
}
data = {
"hostnames": self.params.get("hosts", []),
"options": options,
"do_full_scan": self.params.get("do_full_scan", True),
"bulk_size": self.params.get("bulk_size", 1),
"ignore_errors": self.params.get("ignore_errors", True),
}

return self._fetch(
code_mapping=HTTP_CODES_BULK,
Expand Down Expand Up @@ -366,9 +372,6 @@ def run_module():

ver = discovery.getversion()

if single_mode and ver < CheckmkVersion("2.1.0"):
discovery = oldDiscoveryAPI(module)

if ver < CheckmkVersion("2.2.0") and module.params.get("state") == "tabula_rasa":
result = RESULT(
http_code=0,
Expand Down
19 changes: 18 additions & 1 deletion plugins/modules/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,24 @@ def delete(self, site_connection):
def _verify_compatibility(self):
if self.getversion() <= CheckmkVersion("2.2.0"):
exit_module(
msg="Site management is only available for Checkmk versions starting with 2.2.0.",
self.module,
msg="Site management is only available for Checkmk versions starting with 2.2.0. Version found: %s"
% self.getversion(),
failed=True,
)

message_broker_port = (
self.params.get("site_connection", {})
.get("site_config", {})
.get("configuration_connection", {})
.get("message_broker_port")
)

if self.getversion() < CheckmkVersion("2.4.0i1") and message_broker_port:
exit_module(
self.module,
msg="The parameter message_broker_port is only available for Checkmk versions starting with 2.4.0. Version found: %s"
% self.getversion(),
failed=True,
)

Expand Down

0 comments on commit 551ba2f

Please sign in to comment.