ansible-collection-checkmk.general icon indicating copy to clipboard operation
ansible-collection-checkmk.general copied to clipboard

[FEED] Support CME

Open lgetwan opened this issue 3 years ago • 6 comments

In many API endpoints, the CME has "customer" as a mandatory field. We have to take care of this.

lgetwan avatar Jun 29 '22 09:06 lgetwan

Note: CME support can affect the agent role too (See #121 for reference). We should keep an eye on that.

robin-checkmk avatar Aug 26 '22 11:08 robin-checkmk

I assume CME refers to the CheckMK Enterprise edition? If yes, How is the agent deployment support going? I'd like to avoid having to install the agent on all my systems by hand.

edermi avatar Sep 26 '22 16:09 edermi

Hi @edermi, no CME is the Checkmk Managed Service Edition. This issue focuses on modules, as they need to be able to handle an additional attribute. Regarding your question about the Agent rollout: If you are using the CEE (Enterprise Edition) you are good to go. If you are actually using the CME, I would need to check a thing or two.

robin-checkmk avatar Sep 27 '22 06:09 robin-checkmk

Thanks, understood. The agent README states that CheckMK Enterprise Edition is not supported, hence I was reluctant to try it. I'd like to avoid this issue going off-topic, is there any further documentation? I'm especially interested in how this plays with the bakery and auto-updates.

edermi avatar Sep 27 '22 08:09 edermi

Let's continue in the referenced issue, so we don't clutter this issue. :)

robin-checkmk avatar Sep 27 '22 09:09 robin-checkmk

#165 adds CME support for the agent role.

robin-checkmk avatar Sep 28 '22 07:09 robin-checkmk

This issue has been stale for 60 days. It will close in 7 days.

github-actions[bot] avatar Jan 04 '23 03:01 github-actions[bot]

This issue has been stale for 60 days. It will close in 7 days.

github-actions[bot] avatar Mar 06 '23 03:03 github-actions[bot]

This issue has been stale for 60 days. It will close in 7 days.

github-actions[bot] avatar May 06 '23 03:05 github-actions[bot]

This is still relevant, hence I marked it to never become stale.

robin-checkmk avatar May 15 '23 13:05 robin-checkmk

I had to patch two modules host_group.py and user.py yesterday for my transition from multiple scripts and manual doings to ansible. Is it correct that Checkmk expects the customer always as lowercase string ("provider" despite the fact it's written "Provider" in my backend)?

Here are my changes (just in case I do a silly update of my local collection):

host_group.py

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

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

    response, info = fetch_url(
        module, url, module.jsonify(params), headers=headers, method="POST"
    )

    if info["status"] != 200:
        exit_failed(
            module,
            "Error calling API. HTTP code %d. Details: %s, "
            % (info["status"], info["body"]),
        )


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")),
                "customer": el.get("customer", 'provider'),
            }
            for el in groups
        ],
    }
    url = base_url + api_endpoint

    response, info = fetch_url(
        module, url, module.jsonify(params), headers=headers, method="POST"
    )

    if info["status"] != 200:
        exit_failed(
            module,
            "Error calling API (bulk-create). HTTP code %d. Details: %s, "
            % (info["status"], info["body"]),
        )

user.py

def run_module():

    # define available arguments/parameters a user can pass to the module
    module_args = dict(
        server_url=dict(type="str", required=True),
        site=dict(type="str", required=True),
        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),
        name=dict(required=True, type="str"),
        fullname=dict(type="str"),
        customer=dict(type="str"),
        password=dict(type="str", no_log=True),
        enforce_password_change=dict(type="bool", no_log=False),

[...]

    @classmethod
    def from_module(cls, params):

        attributes = cls.default_attributes

        attributes["username"] = params["name"]

        def _exists(key):
            return key in params and params[key] is not None

        if _exists("fullname"):
            attributes["fullname"] = params["fullname"]

        if _exists("customer"):
            attributes["customer"] = params["customer"]

muehlings avatar Aug 22 '23 14:08 muehlings

I had to patch two modules host_group.py and user.py yesterday for my transition from multiple scripts and manual doings to ansible. Is it correct that Checkmk expects the customer always as lowercase string ("provider" despite the fact it's written "Provider" in my backend)?

If you look closely, you will see, that the ID of the customer attribute is actually lower case. Hence, the need for lower case. image

Thanks for sharing your changes @muehlings! I am certain it helps people get started adapting modules, once they get to it. You might even create your own PRs for the modules you touched, to get a piece of the fame? :wink:

robin-checkmk avatar Aug 22 '23 14:08 robin-checkmk

Hello Robin,

Thanks for sharing your changes @muehlings! I am certain it helps people get started adapting modules, once they get to it. You might even create your own PRs for the modules you touched, to get a piece of the fame? 😉

I still need a workshop for git. ;) In my last PR I lost about 2 hours for linting. That feels inefficient.

muehlings avatar Aug 22 '23 14:08 muehlings

I still need a workshop for git. ;) In my last PR I lost about 2 hours for linting. That feels inefficient.

We can do that together. :) You create the basic stuff and I figure out linting findings and so on. :)

robin-checkmk avatar Aug 22 '23 14:08 robin-checkmk

I forked from the wrong branch (:main instead of :devel), but my changes should be noticable. I have done only two modules. There are some more to go and the POST/PUT requests should not submit the parameter "customer". I think they will fail then.

muehlings avatar Aug 23 '23 13:08 muehlings

Second try: https://github.com/Checkmk/ansible-collection-checkmk.general/pull/427 I think I fixed most of the request logic against non-CME sites and the diff looks consistent.

muehlings avatar Aug 25 '23 09:08 muehlings

Hi, just a note to thank you guys to work on adding support for the CME, this will be very very useful to us ! As we are starting to deploy the CME.

meni2029 avatar Oct 04 '23 08:10 meni2029

This is implemented with #427 in release 3.4.0. If there are follow-up issues, please open a new ticket.

robin-checkmk avatar Nov 09 '23 13:11 robin-checkmk