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

Feature contacts groups #168

Merged
merged 15 commits into from
Nov 18, 2022
Merged

Feature contacts groups #168

merged 15 commits into from
Nov 18, 2022

Conversation

msekania
Copy link
Contributor

@msekania msekania commented Sep 29, 2022

Additional plugin that manages contact groups. In essence host_group.py with 'host' exchanges with 'contact'.
Rest API of both host and contact groups are "almost" identical.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: e.g. #1

What is the new behavior?

  • manage contact groups in Checkmk (create/modify/delete)
  • bulk and single mode for contact group management

Other information

- name: "Create a single contact group."
  tribe29.checkmk.contact_group:
    server_url: "http://localhost/"
    site: "my_site"
    automation_user: "automation"
    automation_secret: "$SECRET"
    contact_group_name: "my_contact_group"
    title: "My Contact Group"
    state: "present"
  delegate_to: localhost

- name: "Create contact groups."
  tribe29.checkmk.contact_group:
    server_url: "http://localhost/"
    site: "my_site"
    automation_user: "automation"
    automation_secret: "$SECRET"
    contact_groups: "my_contact_groups"
    title: "My Contact Group"
    state: "present"
  vars:
    my_contact_groups:
      - name: "contact_one"
        title: "Contact One"
      - name: "OnCall"
        title: "Not on Sundays"
  delegate_to: localhost

- name: "Check_MK: create/register rules, which assign all servers in the given folder to the given contact group"
  tribe29.checkmk.rule:
    server_url: "http://localhost/"
    site: "my_site"
    automation_user: "automation"
    automation_secret: "$SECRET"
    ruleset: "host_contactgroups"
    rule:
        folder: "/My/Host_Groups"
        conditions: {
            "host_labels": [],
            "host_tags": [],
            "service_labels": []
        }
        properties: {
            "disabled": false,
        }
        value_raw: "'my_contact_group'"
    state: "present"
  run_once: 'true'
  delegate_to: localhost

@msekania
Copy link
Contributor Author

msekania commented Sep 29, 2022

Since rest API is almost identical, in essence

sed 's/host\([ _g]\)/contact\1/g' host_group.py > contact_group.py
sed -i 's/Host/Contact/g' contact_group.py

similarly test suite

@robin-checkmk robin-checkmk self-assigned this Sep 29, 2022
@robin-checkmk robin-checkmk added the enhancement New feature or request label Sep 29, 2022
@robin-checkmk
Copy link
Member

Hi @msekania and thanks for the continuous contributions!
We are a little swamped right now, but I would target this feature for 0.12.0, pending review of course.

@msekania
Copy link
Contributor Author

Hi @robin-tribe29,

somehow this close similarity of contact and host groups does not give me a rest.
I have also checked and service group rest API interface is also quite similar.
I do not know, whether this similarity will also stay in the future, but in case, I have a group module written that combines all this three group management in one (including test suite).

https://github.com/msekania/ansible-collection-tribe29.checkmk/tree/feature-groups

In current version, there is a group_type field which takes one of ["contact", "host", "service"] values, and the rest is provided either by group_name (instead of host_group_name, contact_group_name) and title or list of dict-s named 'groups' (instead of host_group, contact_group) with name and title entries.
I can also add a backward compatibility features.

Alternatively, I can rewrite the module so that group_type field is removed and choice is made by providing:

  • host_group_name or host_groups;
  • contact_group_name or contact_groups;
  • service_group_name or service_groups;

Should I make an another pull request?
We can decide then how to proceed.

Best,
Michael

@robin-checkmk
Copy link
Member

Hi @msekania, we are already discussing this internally, but have not reached a definite conclusion. We lean towards dedicated modules but shared code base. But that is quite its own topic. How do you feel about merging this feature for now, as it is ready. I created a dedicated issue, where we can discuss the matter in depth.

Copy link
Contributor

@lgetwan lgetwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have successfully tested the code!

@robin-checkmk robin-checkmk changed the base branch from main to devel November 18, 2022 13:05
@robin-checkmk robin-checkmk merged commit 33b00fe into Checkmk:devel Nov 18, 2022
@robin-checkmk robin-checkmk mentioned this pull request Nov 18, 2022
7 tasks
robin-checkmk added a commit that referenced this pull request May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants