ansible-collection-checkmk.general
ansible-collection-checkmk.general copied to clipboard
[BUG] rule module does not respect parameter folder
rule module does not respect parameter folder
module rule does not respect the parameter folder, only the parameters conditions, properties, value_raw.
It does not take into account that folder might be also different.
As a result one cannot assign the rule with the same conditions, properties, value_raw to two different folders.
With REST API it is possible!
snippet from the rule module
def get_existing_rule(module, base_url, headers, ruleset, rule):
# Get rules in ruleset
rules = get_rules_in_ruleset(module, base_url, headers, ruleset)
if rules is not None:
# Loop through all rules
for r in rules.get("value"):
# Check if conditions, properties and values are the same
if (
sorted(r["extensions"]["conditions"]) == sorted(rule["conditions"])
and sorted(r["extensions"]["properties"]) == sorted(rule["properties"])
and sorted(r["extensions"]["value_raw"]) == sorted(rule["value_raw"])
):
# If they are the same, return the ID
return r["id"]
return None
There is no check for r["extensions"]["folder"]
Component Name
rule
Ansible Version
any
Checkmk Version
any
Collection Version
any with rule module
Environment
To Reproduce
Example, only folder is different
- name: "Create a rule in checkgroup_parameters:memory_percentage_used for production/proxies"
tribe29.checkmk.rule:
server_url: "http://localhost/"
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
ruleset: "checkgroup_parameters:memory_percentage_used"
rule:
folder: "/production/proxies"
conditions: {
"host_labels": [],
"host_tags": [],
"service_labels": []
}
properties: {
"comment": "Warning at 80%\nCritical at 90%\n",
"description": "Allow higher memory usage",
"disabled": false,
"documentation_url": ""
}
value_raw: "{'levels': (80.0, 90.0)}"
state: "present"
- name: "Create a rule in checkgroup_parameters:memory_percentage_used for stging/proxies"
tribe29.checkmk.rule:
server_url: "http://localhost/"
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
ruleset: "checkgroup_parameters:memory_percentage_used"
rule:
folder: "/staging/proxies"
conditions: {
"host_labels": [],
"host_tags": [],
"service_labels": []
}
properties: {
"comment": "Warning at 80%\nCritical at 90%\n",
"description": "Allow higher memory usage",
"disabled": false,
"documentation_url": ""
}
value_raw: "{'levels': (80.0, 90.0)}"
state: "present"
Expected behavior
Both should be created.
Actual behavior
The second one is skipped
Screenshots
Additional context