Skip to content

Commit d8a4d03

Browse files
Merge pull request #360 from Checkmk/devel
Release 2.1.0
2 parents cfae083 + 9df36e4 commit d8a4d03

File tree

46 files changed

+448
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+448
-264
lines changed

SUPPORT.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Collection Version | Checkmk Versions | Ansible Versions | Remarks
2929
0.22.0 | 2.1.0p27, 2.0.0p35, 2.2.0b6 | 2.12, 2.13, 2.14 | None
3030
0.23.0 | 2.1.0p28, 2.0.0p36, 2.2.0b8 | 2.13, 2.14, 2.15 | None
3131
1.0.0 | 2.1.0p28, 2.0.0p36, 2.2.0b8 | 2.13, 2.14, 2.15 | None
32-
2.0.0 | 2.0.0p36, 2.1.0p28, 2.2.0p1 | 2.13, 2.14, 2.15 | None
32+
2.0.0 | 2.0.0p36, 2.1.0p28, 2.2.0p1 | 2.13, 2.14, 2.15 | None
33+
2.1.0 | 2.0.0p36, 2.1.0p29, 2.2.0p3 | 2.13, 2.14, 2.15 | None

Vagrantfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ Vagrant.configure("2") do |config|
1919
end
2020
$script = <<-SCRIPT
2121
apt-get -y update --quiet
22-
apt-get -y install python3.9 python3-pip ca-certificates curl gnupg lsb-release
23-
wget "https://download.checkmk.com/checkmk/2.1.0p24/check-mk-raw-2.1.0p24_0.focal_amd64.deb" -O /tmp/checkmk-stable.deb
24-
wget "https://download.checkmk.com/checkmk/2.2.0-$(date +%Y.%m.%d)/check-mk-raw-2.2.0-$(date +%Y.%m.%d)_0.focal_amd64.deb" -O /tmp/checkmk-beta.deb
25-
apt-get install -y /tmp/checkmk-stable.deb
22+
apt-get -y install python3-pip ca-certificates curl gnupg lsb-release
23+
wget "https://download.checkmk.com/checkmk/2.1.0p29/check-mk-raw-2.1.0p29_0.focal_amd64.deb" -O /tmp/checkmk-oldstable.deb
24+
wget "https://download.checkmk.com/checkmk/2.2.0p3/check-mk-raw-2.2.0p3_0.focal_amd64.deb" -O /tmp/checkmk-stable.deb
25+
apt-get install -y /tmp/checkmk-oldstable.deb
2626
omd create --admin-password 'd7589df1-01db-4eda-9858-dbcff8d0c361' stable
27-
apt-get install -y /tmp/checkmk-beta.deb
27+
apt-get install -y /tmp/checkmk-stable.deb
2828
omd create --admin-password 'd7589df1-01db-4eda-9858-dbcff8d0c361' beta
2929
omd status -b stable || omd start stable
3030
omd status -b beta || omd start beta
31-
python3.9 -m pip install -r /vagrant/requirements.txt
31+
python3 -m pip install -r /vagrant/requirements.txt
3232
sudo -u vagrant ansible-galaxy collection install -f -r /vagrant/requirements.yml
3333
mkdir -p /home/vagrant/ansible_collections/checkmk/general
3434
mkdir -p /etc/apt/keyrings
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bugfixes:
2+
- Utils - With Checkmk 2.2.0p3 the activation introduces a breaking change, which we need to handle. As a workaround we added the 'If-Match' header to all API requests.
3+
4+
known_issues:
5+
- Utils - All API calls send the 'If-Match' header. This is a workaround and will be fixed in a future release.

changelogs/fragments/discovery.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- Discovery module - Properly handle redirects to wait for completion of background jobs.

changelogs/fragments/downtime.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- Downtime module - The module handles timezones properly now.

changelogs/fragments/modules.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
major_changes:
2+
- Bakery module - Migrated to use module_utils.
3+
- Discovery module - Migrated to use module_utils.
4+
- contact_group module - The module was not compatible with Checkmk 2.2. This is fixed now.
5+
- host_group module - The module was not compatible with Checkmk 2.2. This is fixed now.
6+
- service_group module - The module was not compatible with Checkmk 2.2. This is fixed now.

changelogs/fragments/tests.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
###########################################################
2+
# #
3+
# Please use this template when writing changelogs. #
4+
# Remove all comment lines, once you added your changes. #
5+
# Refer to the archive, if you need examples. #
6+
# #
7+
###########################################################
8+
9+
bugfixes:
10+
- Integration tests - A bug was fixed, where the integration tests did not use the correct Checkmk version.
11+
12+
#
13+
## Line Format:
14+
#
15+
16+
# When writing a changelog entry, use the following format:
17+
18+
# - scope - description starting with a uppercase letter and ending with a period at the very end. Multiple sentences are allowed.
19+
20+
# The scope is usually a module or plugin name or group of modules or plugins, for example, lookup plugins. While module names can (and should) be mentioned directly (foo_module), plugin names should always be followed by the type (foo inventory plugin).
21+
22+
# For changes that are not really scoped (for example, which affect a whole collection), use the following format:
23+
24+
# - Description starting with an uppercase letter and ending with a dot at the very end. Multiple sentences are allowed.
25+
26+
27+
#
28+
## Possible keys:
29+
#
30+
# release_summary
31+
# Adds a single line release summary to the changelog.
32+
33+
# breaking_changes
34+
# Changes that break existing playbooks or roles. This includes any change to existing behavior that forces users to update tasks. Displayed in both the changelogs and the Porting Guides.
35+
36+
# major_changes
37+
# Major changes to Ansible itself. Generally does not include module or plugin changes. Displayed in both the changelogs and the Porting Guides.
38+
39+
# minor_changes
40+
# Minor changes to Ansible, modules, or plugins. This includes new features, new parameters added to modules, or behavior changes to existing parameters.
41+
42+
# deprecated_features
43+
# Features that have been deprecated and are scheduled for removal in a future release. Displayed in both the changelogs and the Porting Guides.
44+
45+
# removed_features
46+
# Features that were previously deprecated and are now removed. Displayed in both the changelogs and the Porting Guides.
47+
48+
# security_fixes
49+
# Fixes that address CVEs or resolve security concerns. Include links to CVE information.
50+
51+
# bugfixes
52+
# Fixes that resolve issues.
53+
54+
# known_issues
55+
# Known issues that are currently not fixed or will not be fixed.
56+
57+
# Reference: https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: general
1010

1111
# The version of the collection. Must be compatible with semantic versioning
1212

13-
version: 2.0.0
13+
version: 2.1.0
1414

1515
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1616
readme: README.md

plugins/module_utils/api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
__metaclass__ = type
1212

13+
import json
14+
1315
from ansible.module_utils.urls import fetch_url
1416
from ansible_collections.checkmk.general.plugins.module_utils.types import RESULT
1517
from ansible_collections.checkmk.general.plugins.module_utils.utils import (
@@ -33,6 +35,7 @@ def __init__(self, module):
3335
"Accept": "application/json",
3436
"Content-Type": "application/json",
3537
"Authorization": "Bearer %s %s" % (user, secret),
38+
"If-Match": "*",
3639
}
3740
self.current = {}
3841
self.required = {}
@@ -62,6 +65,9 @@ def _fetch(self, code_mapping, endpoint="", data=None, method="GET"):
6265
# Better translate to json later and keep the original response here.
6366
content = response.read() if response else ""
6467
msg = "%s - %s" % (str(http_code), http_readable)
68+
if failed:
69+
details = info.get("body", info.get("msg", "N/A"))
70+
msg += " Details: %s" % details
6571

6672
result = RESULT(
6773
http_code=http_code,
@@ -75,3 +81,20 @@ def _fetch(self, code_mapping, endpoint="", data=None, method="GET"):
7581
if failed:
7682
self.module.fail_json(**result_as_dict(result))
7783
return result
84+
85+
def getversion(self):
86+
data = {}
87+
88+
result = self._fetch(
89+
code_mapping={
90+
200: (True, False, "Discovery successful."),
91+
406: (False, True, "Not Acceptable."),
92+
},
93+
endpoint="version",
94+
data=data,
95+
method="GET",
96+
)
97+
98+
content = result.content
99+
checkmkinfo = json.loads(content)
100+
return (checkmkinfo.get("versions").get("checkmk")).split(".")

plugins/modules/bakery.py

Lines changed: 60 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
3636
state:
3737
description: State - Baked, signed or baked and signed
38+
required: true
3839
choices: ["baked", "signed", "baked_signed"]
39-
default: "baked"
4040
type: str
4141
4242
author:
@@ -87,8 +87,61 @@
8787
sample: 'Done.'
8888
"""
8989

90+
import time
91+
9092
from ansible.module_utils.basic import AnsibleModule
91-
from ansible.module_utils.urls import fetch_url
93+
from ansible_collections.checkmk.general.plugins.module_utils.api import CheckmkAPI
94+
from ansible_collections.checkmk.general.plugins.module_utils.utils import (
95+
result_as_dict,
96+
)
97+
98+
HTTP_CODES = {
99+
# http_code: (changed, failed, "Message")
100+
200: (True, False, "The operation was done successfully."),
101+
204: (
102+
True,
103+
False,
104+
"No Content: Operation done successfully. No further output.",
105+
),
106+
400: (False, True, "Bad Request: Parameter or validation failure."),
107+
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
108+
406: (
109+
False,
110+
True,
111+
"Not Acceptable: The requests accept headers can not be satisfied.",
112+
),
113+
415: (
114+
False,
115+
True,
116+
"Unsupported Media Type: The submitted content-type is not supported.",
117+
),
118+
500: (False, True, "General Server Error."),
119+
}
120+
121+
122+
class BakeryAPI(CheckmkAPI):
123+
def post(self):
124+
if self.params.get("state", "") != "baked":
125+
data = {
126+
"key_id": self.params.get("signature_key_id", ""),
127+
"passphrase": self.params.get("signature_key_passphrase", ""),
128+
}
129+
else:
130+
data = ""
131+
132+
if self.params.get("state", "") == "baked":
133+
action = "bake"
134+
if self.params.get("state", "") == "signed":
135+
action = "sign"
136+
if self.params.get("state", "") == "baked_signed":
137+
action = "bake_and_sign"
138+
139+
return self._fetch(
140+
code_mapping=HTTP_CODES,
141+
endpoint="/domain-types/agent/actions/%s/invoke" % action,
142+
data=data,
143+
method="POST",
144+
)
92145

93146

94147
def run_module():
@@ -102,109 +155,18 @@ def run_module():
102155
signature_key_passphrase=dict(type="str", required=False, no_log=True),
103156
state=dict(
104157
type="str",
105-
default="baked",
106158
choices=["baked", "signed", "baked_signed"],
107-
required=False,
159+
required=True,
108160
),
109161
)
110-
111-
result = dict(changed=False, failed=False, http_code="", msg="")
112-
113162
module = AnsibleModule(argument_spec=module_args, supports_check_mode=False)
114163

115-
changed = False
116-
failed = False
117-
http_code = ""
118-
119-
http_code_mapping = {
120-
# http_code: (changed, failed, "Message")
121-
200: (True, False, "The operation was done successfully."),
122-
204: (
123-
True,
124-
False,
125-
"No Content: Operation done successfully. No further output.",
126-
),
127-
400: (False, True, "Bad Request: Parameter or validation failure."),
128-
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
129-
406: (
130-
False,
131-
True,
132-
"Not Acceptable: The requests accept headers can not be satisfied.",
133-
),
134-
415: (
135-
False,
136-
True,
137-
"Unsupported Media Type: The submitted content-type is not supported.",
138-
),
139-
500: (False, True, "General Server Error."),
140-
}
141-
142-
# Declare headers including authentication to send to the Checkmk API
143-
headers = {
144-
"Accept": "application/json",
145-
"Content-Type": "application/json",
146-
"Authorization": "Bearer %s %s"
147-
% (
148-
module.params.get("automation_user", ""),
149-
module.params.get("automation_secret", ""),
150-
),
151-
}
152-
153-
base_url = "%s/%s/check_mk/api/1.0" % (
154-
module.params.get("server_url", ""),
155-
module.params.get("site", ""),
156-
)
157-
158-
action = module.params.get("state", "")
159-
160-
if action == "baked":
161-
api_endpoint = "/domain-types/agent/actions/bake/invoke"
162-
params = ()
163-
164-
elif action == "signed":
165-
api_endpoint = "/domain-types/agent/actions/sign/invoke"
166-
params = {
167-
"key_id": module.params.get("signature_key_id", ""),
168-
"passphrase": module.params.get("signature_key_passphrase", ""),
169-
}
170-
171-
elif action == "baked_signed":
172-
api_endpoint = "/domain-types/agent/actions/bake_and_sign/invoke"
173-
params = {
174-
"key_id": module.params.get("signature_key_id", ""),
175-
"passphrase": module.params.get("signature_key_passphrase", ""),
176-
}
177-
178-
url = base_url + api_endpoint
179-
response, info = fetch_url(
180-
module, url, module.jsonify(params), headers=headers, method="POST", timeout=60
181-
)
182-
183-
http_code = info["status"]
184-
185-
# Kudos to Lars G.!
186-
if http_code in http_code_mapping.keys():
187-
changed, failed, msg = http_code_mapping[http_code]
188-
else:
189-
changed, failed, msg = (
190-
False,
191-
True,
192-
"Error calling API. HTTP Return Code is %d" % http_code,
193-
)
194-
195-
if failed:
196-
details = info.get("body", info.get("msg", "N/A"))
197-
msg += " Details: %s" % details
198-
199-
result["msg"] = msg
200-
result["changed"] = changed
201-
result["failed"] = failed
202-
result["http_code"] = http_code
164+
bakery = BakeryAPI(module)
165+
result = bakery.post()
203166

204-
if result["failed"]:
205-
module.fail_json(**result)
167+
time.sleep(3)
206168

207-
module.exit_json(**result)
169+
module.exit_json(**result_as_dict(result))
208170

209171

210172
def main():

0 commit comments

Comments
 (0)