Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] rule module does not respect parameter folder #195

Closed
msekania opened this issue Nov 22, 2022 · 4 comments
Closed

[BUG] rule module does not respect parameter folder #195

msekania opened this issue Nov 22, 2022 · 4 comments
Assignees
Labels
bug Something isn't working module:rule This affects the rule module

Comments

@msekania
Copy link
Contributor

msekania commented Nov 22, 2022

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

@msekania msekania added the bug Something isn't working label Nov 22, 2022
@msekania msekania changed the title [BUG] [BUG] rule module does not respect parameter folder Nov 22, 2022
@robin-checkmk
Copy link
Member

@diademiemi may I ping you here and ask that you take a look? Thanks!

@diademiemi
Copy link
Contributor

Yeah I'll have a look when I can

@lgetwan
Copy link
Contributor

lgetwan commented Jan 16, 2023

Fixed with #224.
@diademiemi & @msekania: Can you confirm?

@robin-checkmk
Copy link
Member

As this issue was fixed two weeks ago, I am closing this issue as done.
If anything else comes up, please open a new issue. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:rule This affects the rule module
Projects
None yet
Development

No branches or pull requests

4 participants