Skip to content

Commit

Permalink
Merge pull request #204 from tribe29/devel
Browse files Browse the repository at this point in the history
Release 0.14.0
  • Loading branch information
robin-checkmk authored Dec 9, 2022
2 parents 8db342f + 2518769 commit 17038da
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 69 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Major Changes
Minor Changes
-------------

- Agent role - Now supports new password hashing according to L(Werk 14391,https://checkmk.com/werk/14391)
- Agent role - Now supports new password hashing according to Werk 14391: https://checkmk.com/werk/14391

v0.12.0
=======
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ Name | Description
Name | Description | Tests
--- | --- | ---
[tribe29.checkmk.activation](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/activation.py)|Activate changes.|[![Integration Tests for Activation Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-activation.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-activation.yaml)
[tribe29.checkmk.contact_group](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/contact_group.py)|Manage contact groups.|[![Integration Tests for Contact Group Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-contact_group.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-contact_group.yaml)
[tribe29.checkmk.discovery](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/discovery.py)|Discover services on hosts.|[![Integration Tests for Discovery Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-discovery.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-discovery.yaml)
[tribe29.checkmk.downtime](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/downtime.py)|Schedule downtimes on hosts and services.|[![Integration Tests for Downtime Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-downtime.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-downtime.yaml)
[tribe29.checkmk.folder](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/folder.py)|Manage folders.|[![Integration Tests for Folder Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-folder.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-folder.yaml)
[tribe29.checkmk.host_group](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/host_group.py)|Manage host groups.|[![Integration Tests for Host Group Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-host_group.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-host_group.yaml)
[tribe29.checkmk.host](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/host.py)|Manage hosts.|[![Integration Tests for Host Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-host.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-host.yaml)
[tribe29.checkmk.rule](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/rule.py)|Manage rules.|[![Integration Tests for Rule Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-rule.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-rule.yaml)
[tribe29.checkmk.service_group](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/service_group.py)|Manage service groups.|[![Integration Tests for Service Group Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-service_group.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-service_group.yaml)
[tribe29.checkmk.tag_group](https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/plugins/modules/tag_group.py)|Manage tag groups.|[![Integration Tests for Tag Group Module](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-tag_group.yaml/badge.svg)](https://github.com/tribe29/ansible-collection-tribe29.checkmk/actions/workflows/ans-int-test-tag_group.yaml)

### Roles
Name | Description | Tests
Expand Down
5 changes: 4 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Security Policy

## Disambiguation
This policy solely applies to the Checkmk Ansible Collection, not Checkmk itself!
For Checkmk itself, please refer to [this Vulnerability disclosure policy](https://checkmk.com/responsible-disclosure-policy)
## Supported Versions

Please always use the latest available version!
Versions in here are used solely for stability, so your Ansible configuration
Versions in this repository are used solely for stability, so your Ansible configuration
does not break.
However, we cannot and will not support older versions, especially security-wise.
If you find a vulnerability, please report it as stated below,
Expand Down
1 change: 1 addition & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Collection Version | Checkmk Versions | Remarks
--- | --- | ---
0.12.0 | 2.1.0p11, 2.0.0p28 | None
0.13.0 | 2.1.0p17, 2.0.0p31 | None
0.14.0 | 2.1.0p17, 2.0.0p31 | None
2 changes: 1 addition & 1 deletion changelogs/archive/0.13.0/new-passwd-hashing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to

minor_changes:
- Agent role - Now supports new password hashing according to L(Werk 14391,https://checkmk.com/werk/14391)
- Agent role - Now supports new password hashing according to Werk 14391: https://checkmk.com/werk/14391

## Line Format

Expand Down
2 changes: 1 addition & 1 deletion changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ releases:
major_changes:
- Add service_group module.
minor_changes:
- Agent role - Now supports new password hashing according to L(Werk 14391,https://checkmk.com/werk/14391)
- Agent role - Now supports new password hashing according to Werk 14391: https://checkmk.com/werk/14391
fragments:
- new-passwd-hashing.yml
- service_group_module.yml
Expand Down
4 changes: 2 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: checkmk

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

version: 0.13.0
version: 0.14.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand All @@ -37,7 +37,7 @@ license_file: LICENSE

# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
# requirements as 'namespace' and 'name'
tags: [tribe29, checkmk, monitoring]
tags: [tribe29, checkmk, monitoring, check_mk, check, discovery]

# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
Expand Down
111 changes: 65 additions & 46 deletions plugins/modules/host_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
extends_documentation_fragment: [tribe29.checkmk.common]
options:
host_group_name:
name:
description: The name of the host group to be created/modified/deleted.
type: str
aliases: [host_group_name]
title:
description: The title (alias) of your host group. If omitted defaults to the host_group_name.
description: The title (alias) of your host group. If omitted defaults to the name.
type: str
host_groups:
groups:
description:
- instead of 'host_group_name', 'title' a list of dicts with elements of host group name and title (alias) to be created/modified/deleted.
- instead of 'name', 'title' a list of dicts with elements of host group name and title (alias) to be created/modified/deleted.
If title is omitted in entry, it defaults to the host group name.
default: []
type: raw
aliases: [host_groups]
state:
description: The state of your host group.
type: str
Expand All @@ -54,7 +56,7 @@
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
host_group_name: "my_host_group"
name: "my_host_group"
title: "My Host Group"
state: "present"
Expand All @@ -65,7 +67,7 @@
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
host_groups:
groups:
- name: "my_host_group_one"
title: "My Host Group One"
- name: "my_host_group_two"
Expand All @@ -81,7 +83,7 @@
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
host_groups:
groups:
- name: "my_host_group_one"
title: "My Host Group One"
- name: "my_host_group_two"
Expand All @@ -95,7 +97,7 @@
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
host_group_name: "my_host_group"
name: "my_host_group"
state: "absent"
# Delete several host groups.
Expand All @@ -105,7 +107,7 @@
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
host_groups:
groups:
- name: "my_host_group_one"
- name: "my_host_group_two"
state: "absent"
Expand Down Expand Up @@ -145,9 +147,9 @@ def get_current_single_host_group(module, base_url, headers):
current_state = "unknown"
current_title = ""
etag = ""
host_group_name = module.params["host_group_name"]
name = module.params["name"]

api_endpoint = "/objects/host_group_config/" + host_group_name
api_endpoint = "/objects/host_group_config/" + name
url = base_url + api_endpoint

response, info = fetch_url(module, url, data=None, headers=headers, method="GET")
Expand All @@ -156,7 +158,7 @@ def get_current_single_host_group(module, base_url, headers):
body = json.loads(response.read())
current_state = "present"
etag = info.get("etag", "")
current_title = body.get("title", host_group_name)
current_title = body.get("title", name)

elif info["status"] == 404:
current_state = "absent"
Expand Down Expand Up @@ -200,11 +202,11 @@ def get_current_host_groups(module, base_url, headers):


def update_single_host_group(module, base_url, headers):
host_group_name = module.params["host_group_name"]
name = module.params["name"]

api_endpoint = "/objects/host_group_config/" + host_group_name
api_endpoint = "/objects/host_group_config/" + name
params = {
"alias": module.params.get("title", host_group_name),
"alias": module.params.get("title", name),
}
url = base_url + api_endpoint

Expand All @@ -220,7 +222,7 @@ def update_single_host_group(module, base_url, headers):
)


def update_host_groups(module, base_url, host_groups, headers):
def update_host_groups(module, base_url, groups, headers):
api_endpoint = "/domain-types/host_group_config/actions/bulk-update/invoke"
params = {
"entries": [
Expand All @@ -230,7 +232,7 @@ def update_host_groups(module, base_url, host_groups, headers):
"alias": el.get("title", el.get("name")),
},
}
for el in host_groups
for el in groups
],
}
url = base_url + api_endpoint
Expand All @@ -248,12 +250,12 @@ def update_host_groups(module, base_url, host_groups, headers):


def create_single_host_group(module, base_url, headers):
host_group_name = module.params["host_group_name"]
name = module.params["name"]

api_endpoint = "/domain-types/host_group_config/collections/all"
params = {
"name": host_group_name,
"alias": module.params.get("title", host_group_name),
"name": name,
"alias": module.params.get("title", name),
}
url = base_url + api_endpoint

Expand All @@ -269,15 +271,15 @@ def create_single_host_group(module, base_url, headers):
)


def create_host_groups(module, base_url, host_groups, headers):
def create_host_groups(module, base_url, groups, headers):
api_endpoint = "/domain-types/host_group_config/actions/bulk-create/invoke"
params = {
"entries": [
{
"name": el.get("name"),
"alias": el.get("title", el.get("name")),
}
for el in host_groups
for el in groups
],
}
url = base_url + api_endpoint
Expand All @@ -295,7 +297,7 @@ def create_host_groups(module, base_url, host_groups, headers):


def delete_single_host_group(module, base_url, headers):
api_endpoint = "/objects/host_group_config/" + module.params["host_group_name"]
api_endpoint = "/objects/host_group_config/" + module.params["name"]
url = base_url + api_endpoint

response, info = fetch_url(module, url, data=None, headers=headers, method="DELETE")
Expand All @@ -308,10 +310,10 @@ def delete_single_host_group(module, base_url, headers):
)


def delete_host_groups(module, base_url, host_groups, headers):
def delete_host_groups(module, base_url, groups, headers):
api_endpoint = "/domain-types/host_group_config/actions/bulk-delete/invoke"
params = {
"entries": [el["name"] for el in host_groups],
"entries": [el["name"] for el in groups],
}
url = base_url + api_endpoint

Expand All @@ -334,19 +336,42 @@ def run_module():
validate_certs=dict(type="bool", required=False, default=True),
automation_user=dict(type="str", required=True),
automation_secret=dict(type="str", required=True, no_log=True),
host_group_name=dict(type="str", required=False),
name=dict(
type="str",
required=False,
aliases=["host_group_name"],
deprecated_aliases=[
{
"name": "host_group_name",
"date": "2023-03-01",
"collection_name": "tribe29.checkmk",
}
],
),
title=dict(type="str", required=False),
host_groups=dict(type="raw", required=False, default=[]),
groups=dict(
type="raw",
required=False,
default=[],
aliases=["host_groups"],
deprecated_aliases=[
{
"name": "host_groups",
"date": "2023-03-01",
"collection_name": "tribe29.checkmk",
}
],
),
state=dict(type="str", default="present", choices=["present", "absent"]),
)

module = AnsibleModule(
argument_spec=module_args,
mutually_exclusive=[
("host_groups", "host_group_name"),
("groups", "name"),
],
required_one_of=[
("host_groups", "host_group_name"),
("groups", "name"),
],
supports_check_mode=False,
)
Expand All @@ -371,31 +396,29 @@ def run_module():
state = module.params.get("state", "present")

if (
"host_groups" in module.params
and module.params.get("host_groups")
and len(module.params.get("host_groups", [])) > 0
"groups" in module.params
and module.params.get("groups")
and len(module.params.get("groups", [])) > 0
):
if "title" in module.params and module.params.get("title", ""):
exit_failed(
module,
"'title' has only effect when 'host_group_name' is defined and not 'host_groups'",
"'title' has only effect when 'name' (deprecated alias 'host_group_name') is defined and not 'groups' (deprecated alias 'host_groups')",
)

host_groups = module.params.get("host_groups")
groups = module.params.get("groups")

# Determine which host groups do already exest
# Determine which host groups do already exist
current_groups = get_current_host_groups(module, base_url, headers)

# Determine intersection and difference with input, according to 'name' only
if len(set([el.get("name") for el in host_groups])) != len(host_groups):
if len(set([el.get("name") for el in groups])) != len(groups):
exit_failed(module, "two or more entries with the same name!")

listofnames = set([el.get("name") for el in current_groups])

intersection_list = [el for el in host_groups if el.get("name") in listofnames]
difference_list = [
el for el in host_groups if not el.get("name") in listofnames
]
intersection_list = [el for el in groups if el.get("name") in listofnames]
difference_list = [el for el in groups if not el.get("name") in listofnames]

# Handle the host group accordingly to above findings and desired state
if state == "present":
Expand Down Expand Up @@ -452,9 +475,7 @@ def run_module():

else:
exit_failed(module, "Unknown error")
elif "host_group_name" in module.params and module.params.get(
"host_group_name", ""
):
elif "name" in module.params and module.params.get("name", ""):
# Determine the current state of this particular host group
(
current_state,
Expand Down Expand Up @@ -490,9 +511,7 @@ def run_module():
else:
exit_failed(module, "Unknown error")
else:
exit_failed(
module, "One shoudl define either 'host_groups' or 'host_group_name'"
)
exit_failed(module, "One should define either 'groups' or 'name'")


def main():
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/service_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def run_module():
automation_secret=dict(type="str", required=True, no_log=True),
name=dict(type="str", required=False),
title=dict(type="str", required=False),
groups=dict(type="raw", required=False),
groups=dict(type="raw", required=False, default=[]),
state=dict(type="str", default="present", choices=["present", "absent"]),
)

Expand Down
2 changes: 1 addition & 1 deletion requirements.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
collections:
- name: tribe29.checkmk
version: 0.13.0
version: 0.14.0
Loading

0 comments on commit 17038da

Please sign in to comment.