Skip to content

Commit e96b4e0

Browse files
authored
add new options to notification and notification template (#110)
* add new options to notification and notification template * add aliases to new options in notification and notification template
1 parent b4cd469 commit e96b4e0

12 files changed

Lines changed: 90 additions & 0 deletions

examples/icinga_notification.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
disabled: false
2323
vars:
2424
foo: bar
25+
time_period: "24/7"
26+
times_begin: 20
27+
times_end: 120

examples/icinga_notification_template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
- Recovery
1616
times_begin: 20
1717
times_end: 120
18+
time_period: "24/7"
19+
notification_command: "mail-host-notification"
20+
users:
21+
- "rb"

plugins/modules/icinga_notification.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@
9696
- Custom properties of the notification.
9797
type: "dict"
9898
version_added: "1.9.0"
99+
time_period:
100+
description:
101+
- The name of a time period which determines when this notification should be triggered.
102+
type: "str"
103+
aliases: ['period']
104+
version_added: "1.15.0"
105+
times_begin:
106+
description:
107+
- First notification delay.
108+
- Delay unless the first notification should be sent.
109+
type: "int"
110+
version_added: "1.15.0"
111+
times_end:
112+
description:
113+
- Last notification.
114+
- When the last notification should be sent.
115+
type: "int"
116+
version_added: "1.15.0"
99117
"""
100118

101119
EXAMPLES = """
@@ -122,6 +140,9 @@
122140
disabled: false
123141
vars:
124142
foo: bar
143+
time_period: "24/7"
144+
times_begin: 20
145+
times_end: 120
125146
"""
126147

127148
RETURN = r""" # """
@@ -156,6 +177,9 @@ def main():
156177
users=dict(type="list", elements="str", required=False),
157178
types=dict(type="list", elements="str", required=False),
158179
vars=dict(type="dict", default={}, required=False),
180+
time_period=dict(required=False, aliases=["period"]),
181+
times_begin=dict(type="int", required=False),
182+
times_end=dict(type="int", required=False),
159183
)
160184

161185
# When deleting objects, only the name is necessary, so we cannot use
@@ -182,6 +206,9 @@ def main():
182206
"users": module.params["users"],
183207
"types": module.params["types"],
184208
"vars": module.params["vars"],
209+
"period": module.params["time_period"],
210+
"times_begin": module.params["times_begin"],
211+
"times_end": module.params["times_end"],
185212
}
186213

187214
icinga_object = Icinga2APIObject(

plugins/modules/icinga_notification_template.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@
7676
description:
7777
- Set the zone.
7878
type: str
79+
time_period:
80+
description:
81+
- The name of a time period which determines when this notification should be triggered.
82+
type: "str"
83+
aliases: ['period']
84+
version_added: "1.15.0"
85+
notification_command:
86+
description:
87+
- Check command definition
88+
type: "str"
89+
aliases: ['command']
90+
version_added: "1.15.0"
91+
users:
92+
description:
93+
- Users that should be notified by this notification
94+
type: "list"
95+
elements: str
96+
version_added: "1.15.0"
7997
"""
8098

8199
EXAMPLES = """
@@ -95,6 +113,10 @@
95113
- Recovery
96114
times_begin: 20
97115
times_end: 120
116+
time_period: "24/7"
117+
notification_command: "mail-host-notification"
118+
users:
119+
- "rb"
98120
"""
99121

100122
RETURN = r""" # """
@@ -124,6 +146,9 @@ def main():
124146
times_end=dict(type="int", required=False),
125147
types=dict(type="list", elements="str", required=False),
126148
zone=dict(required=False, default=None),
149+
time_period=dict(required=False, aliases=["period"]),
150+
notification_command=dict(required=False, aliases=["command"]),
151+
users=dict(type="list", elements="str", required=False),
127152
)
128153

129154
# Define the main module
@@ -141,6 +166,9 @@ def main():
141166
"times_end": module.params["times_end"],
142167
"types": module.params["types"],
143168
"zone": module.params["zone"],
169+
"period": module.params["time_period"],
170+
"command": module.params["notification_command"],
171+
"users": module.params["users"],
144172
}
145173

146174
icinga_object = Icinga2APIObject(

tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_notification.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020
disabled: false
2121
vars:
2222
foo: bar
23+
time_period: "24/7"
24+
times_begin: 20
25+
times_end: 120

tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_notification_template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
- Recovery
1616
times_begin: 20
1717
times_end: 120
18+
time_period: "24/7"
19+
notification_command: "mail-host-notification"
20+
users:
21+
- "rb"

tests/integration/targets/icinga/roles/icinga/tasks/icinga_notification.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
disabled: false
2323
vars:
2424
foo: bar
25+
time_period: "24/7"
26+
times_begin: 20
27+
times_end: 120

tests/integration/targets/icinga/roles/icinga/tasks/icinga_notification_template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
- Recovery
1616
times_begin: 20
1717
times_end: 120
18+
time_period: "24/7"
19+
notification_command: "mail-host-notification"
20+
users:
21+
- "rb"

tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_notification.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
disabled: false
2323
vars:
2424
foo: bar
25+
time_period: "24/7"
26+
times_begin: 20
27+
times_end: 120
2528
ignore_errors: true
2629
register: result
2730
- assert:

tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_notification_template.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- Recovery
1616
times_begin: 20
1717
times_end: 120
18+
time_period: "24/7"
19+
notification_command: "mail-host-notification"
20+
users:
21+
- "rb"
1822
ignore_errors: true
1923
register: result
2024
- assert:

0 commit comments

Comments
 (0)