Skip to content

Commit

Permalink
notification interval is an int (#254)
Browse files Browse the repository at this point in the history
also add another example without user groups to test idempotency issues with empty groups
  • Loading branch information
rndmh3ro authored Apr 19, 2024
1 parent 4111837 commit 2e3f2a9
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 12 deletions.
23 changes: 22 additions & 1 deletion examples/icinga_notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: '0'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
Expand All @@ -25,6 +25,27 @@
time_period: "24/7"
times_begin: 20
times_end: 120
- name: Create another notification
telekom_mms.icinga_director.icinga_notification:
state: present
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
apply_to: host
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: 0
object_name: E-Mail_host
states:
- Up
- Down
types:
- Problem
- Recovery
users:
- rb
time_period: "24/7"
- name: Update notification
telekom_mms.icinga_director.icinga_notification:
state: present
Expand Down
36 changes: 29 additions & 7 deletions plugins/modules/icinga_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
- Apply feature state.
choices: [ "present", "absent" ]
default: present
type: str
type: "str"
object_name:
description:
- Name of the notification.
aliases: ['name']
required: true
type: str
type: "str"
notification_interval:
description:
- The notification interval (in seconds). This interval is used for active notifications.
- Defaults to 30 minutes. If set to 0, re-notifications are disabled.
type: str
type: "int"
types:
description:
- The state transition types you want to get notifications for.
Expand All @@ -72,7 +72,7 @@
description:
- Whether this notification should affect hosts or services.
- Required if I(state) is C(present).
type: str
type: "str"
choices: ["host", "service"]
assign_filter:
description:
Expand Down Expand Up @@ -127,7 +127,7 @@
- Do not overwrite the whole object but instead append the defined properties.
- Note - Appending to existing vars, imports or any other list/dict is not possible. You have to overwrite the complete list/dict.
- Note - Variables that are set by default will also be applied, even if not set.
type: bool
type: "bool"
choices: [true, false]
version_added: '1.25.0'
"""
Expand All @@ -143,7 +143,7 @@
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: '0'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
Expand All @@ -160,6 +160,28 @@
times_begin: 20
times_end: 120
- name: Create another notification
telekom_mms.icinga_director.icinga_notification:
state: present
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
apply_to: host
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: 0
object_name: E-Mail_host
states:
- Up
- Down
types:
- Problem
- Recovery
users:
- rb
time_period: "24/7"
- name: Update notification
telekom_mms.icinga_director.icinga_notification:
state: present
Expand Down Expand Up @@ -200,7 +222,7 @@ def main():
disabled=dict(
type="bool", required=False, default=False, choices=[True, False]
),
notification_interval=dict(required=False),
notification_interval=dict(type="int", required=False),
states=dict(type="list", elements="str", required=False),
users=dict(type="list", elements="str", required=False),
user_groups=dict(type="list", elements="str", required=False),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
url_password: "{{ icinga_pass }}"
apply_to: host
assign_filter: 'host.name="foohost"'
notification_interval: '0'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
Expand All @@ -23,6 +23,25 @@
time_period: "24/7"
times_begin: 20
times_end: 120
- name: Create another notification
telekom_mms.icinga_director.icinga_notification:
state: absent
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
apply_to: host
assign_filter: 'host.name="foohost"'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
- Down
types:
- Problem
- Recovery
users:
- rb
time_period: "24/7"
- name: Update notification
telekom_mms.icinga_director.icinga_notification:
state: absent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: '0'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
Expand All @@ -25,6 +25,27 @@
time_period: "24/7"
times_begin: 20
times_end: 120
- name: Create another notification
telekom_mms.icinga_director.icinga_notification:
state: present
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
apply_to: host
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: 0
object_name: E-Mail_host
states:
- Up
- Down
types:
- Problem
- Recovery
users:
- rb
time_period: "24/7"
- name: Update notification
telekom_mms.icinga_director.icinga_notification:
state: present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: '0'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
Expand All @@ -32,6 +32,34 @@
- result.failed
# yamllint disable-line rule:line-length
- 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'
- name: Create another notification
telekom_mms.icinga_director.icinga_notification:
state: present
url: http://nonexistent
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
apply_to: host
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: 0
object_name: E-Mail_host
states:
- Up
- Down
types:
- Problem
- Recovery
users:
- rb
time_period: "24/7"
ignore_errors: true
register: result
- assert:
that:
- result.failed
# yamllint disable-line rule:line-length
- 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'
- name: Update notification
telekom_mms.icinga_director.icinga_notification:
state: present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: '0'
notification_interval: 0
object_name: E-Mail_host
states:
- Up
Expand All @@ -32,6 +32,34 @@
- result.failed
# yamllint disable-line rule:line-length
- 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'
- name: Create another notification
telekom_mms.icinga_director.icinga_notification:
state: present
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: iamwrong
apply_to: host
assign_filter: 'host.name="foohost"'
imports:
- foonotificationtemplate
notification_interval: 0
object_name: E-Mail_host
states:
- Up
- Down
types:
- Problem
- Recovery
users:
- rb
time_period: "24/7"
ignore_errors: true
register: result
- assert:
that:
- result.failed
# yamllint disable-line rule:line-length
- 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'
- name: Update notification
telekom_mms.icinga_director.icinga_notification:
state: present
Expand Down

0 comments on commit 2e3f2a9

Please sign in to comment.