Skip to content

Commit

Permalink
Add vars parameter to notification templates, task icinga_serviceset …
Browse files Browse the repository at this point in the history
…swap (#271)

* done

* fix version

* removed version added from vars
  • Loading branch information
gianmarco-mameli authored Nov 29, 2024
1 parent 5e2cb8f commit 848d368
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 6 deletions.
8 changes: 7 additions & 1 deletion docs/icinga_notification_template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Parameters
user_groups (optional, list, None)
User Groups that should be notified by this notification.

vars (optional, dict, {})
Custom properties of the notification.

append (optional, bool, None)
Do not overwrite the whole object but instead append the defined properties.
Expand Down Expand Up @@ -169,7 +171,7 @@ Examples

.. code-block:: yaml+jinja


- name: Create notification template
telekom_mms.icinga_director.icinga_notification_template:
state: present
Expand All @@ -191,6 +193,8 @@ Examples
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"

- name: Update notification template
Expand All @@ -201,6 +205,8 @@ Examples
url_password: "{{ icinga_pass }}"
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true


Expand Down
4 changes: 4 additions & 0 deletions examples/icinga_notification_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"
- name: Update notification template
telekom_mms.icinga_director.icinga_notification_template:
Expand All @@ -29,4 +31,6 @@
url_password: "{{ icinga_pass }}"
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true
11 changes: 11 additions & 0 deletions plugins/modules/icinga_notification_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
- Required if I(state) is C(present).
type: "list"
elements: str
vars:
description:
- Custom properties of the notification.
type: "dict"
default: {}
"""

EXAMPLES = """
Expand All @@ -139,6 +144,8 @@
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"
- name: Update notification template
Expand All @@ -149,6 +156,8 @@
url_password: "{{ icinga_pass }}"
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true
"""

Expand Down Expand Up @@ -185,6 +194,7 @@ def main():
command=dict(required=False, aliases=["notification_command"]),
users=dict(type="list", elements="str", required=False),
user_groups=dict(type="list", elements="str", required=False),
vars=dict(type="dict", default={}, required=False),
)

# Define the main module
Expand All @@ -206,6 +216,7 @@ def main():
"command",
"users",
"user_groups",
"vars"
]

data = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
user_groups: "{{ notification_template.user_groups | default(omit) }}"
notification_command: "{{ notification_template.notification_command | default(omit) }}"
imports: "{{ notification_template.imports | default(omit) }}"
vars: "{{ notification_template.vars | default(omit) }}"
zone: "{{ notification_template.zone | default(omit) }}"
retries: 3
delay: 3
Expand Down
10 changes: 5 additions & 5 deletions roles/ansible_icinga/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@
when: icinga_servicegroups is defined
tags: servicegroup

- name: Icinga service configuration
ansible.builtin.include_tasks: icinga_service.yml
when: icinga_services is defined
tags: service

- name: Icinga serviceset configuration
ansible.builtin.include_tasks: icinga_serviceset.yml
when: icinga_servicesets is defined
tags: serviceset

- name: Icinga service configuration
ansible.builtin.include_tasks: icinga_service.yml
when: icinga_services is defined
tags: service

- name: Icinga notification template configuration
ansible.builtin.include_tasks: icinga_notification_template.yml
when: icinga_notification_templates is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"
- name: Update notification template
telekom_mms.icinga_director.icinga_notification_template:
Expand All @@ -29,4 +31,6 @@
url_password: "{{ icinga_pass }}"
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"
- name: Update notification template
telekom_mms.icinga_director.icinga_notification_template:
Expand All @@ -29,4 +31,6 @@
url_password: "{{ icinga_pass }}"
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"
ignore_errors: true
register: result
Expand All @@ -36,6 +38,8 @@
url_password: "{{ icinga_pass }}"
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true
ignore_errors: true
register: result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- "rb"
user_groups:
- "OnCall"
vars:
foo: bar
zone: "foozone"
ignore_errors: true
register: result
Expand All @@ -36,6 +38,8 @@
url_password: iamwrong
object_name: foonotificationtemplate
notification_interval: '0'
vars:
foo: bar
append: true
ignore_errors: true
register: result
Expand Down

0 comments on commit 848d368

Please sign in to comment.