Skip to content

Commit be60f6d

Browse files
xFuture603Daniel Uhlmannrndmh3ro
authored
Add event commands to modules that support this feature (#101)
* added event command for host_template and service_template * added event commands to icinga_service_template.yml and icinga_host_template.yml * added examples for event_command * deleted "groups" from icinga_host_template * Update plugins/modules/icinga_service_template.py Co-authored-by: Sebastian Gumprich <rndmh3ro@users.noreply.github.com> * removing ':' from description * added output after executing update_examples_and_tests.sh * executed update_examples_and_tests.sh and updated files * executed update_examples_and_tests.sh and updated assert_info_found.yml * added yamllint to assert_info_found.yml * deleted yamllint comment in test folder and added tests/ to the ignore section in .yamllint * moved tests/ to line-length ignore Co-authored-by: Daniel Uhlmann <Daniel.Uhlmann@telekom.de> Co-authored-by: Sebastian Gumprich <rndmh3ro@users.noreply.github.com>
1 parent 4418f5e commit be60f6d

93 files changed

Lines changed: 242 additions & 85 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.yamllint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ rules:
1717
ignore: |
1818
hacking/
1919
roles/ansible_icinga/tasks
20+
tests/

examples/icinga_command.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,19 @@
6565
url_password: "{{ icinga_pass }}"
6666
command: "/opt/centreon-plugins/centreon_plugins_2.pl"
6767
object_name: centreon-plugins_2
68+
- name: Create event command
69+
t_systems_mms.icinga_director.icinga_command:
70+
state: present
71+
url: "{{ icinga_url }}"
72+
url_username: "{{ icinga_user }}"
73+
url_password: "{{ icinga_pass }}"
74+
command: "/opt/scripts/restart_httpd"
75+
object_name: "restart_httpd"
76+
arguments:
77+
'-s':
78+
value: $service.state$
79+
'-t':
80+
value: $service.state_type$
81+
'-a':
82+
set_if: $service.check_attempt$
83+
value: $restart_service$

examples/icinga_service_template.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@
1313
procs_warning: '1:'
1414
notes: "example note"
1515
notes_url: "'http://url1' 'http://url2'"
16+
- name: Create servicetemplate with event command
17+
t_systems_mms.icinga_director.icinga_service_template:
18+
state: present
19+
url: "{{ icinga_url }}"
20+
url_username: "{{ icinga_user }}"
21+
url_password: "{{ icinga_pass }}"
22+
object_name: apache_check_servicetemplate
23+
use_agent: false
24+
event_command: restart_httpd
25+
notes: "example note"
26+
notes_url: "'http://url1' 'http://url2'"

hacking/assert_info_found.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
- assert:
33
that:
4-
- '(result.objects | length) == 1 or (result.objects | length) == 2'
4+
# yamllint disable-line rule:line-length
5+
- '(result.objects | length) == 1 or (result.objects | length) == 2 or (result.objects | length) == 3'

plugins/modules/icinga_command.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@
161161
url_password: "{{ icinga_pass }}"
162162
command: "/opt/centreon-plugins/centreon_plugins_2.pl"
163163
object_name: centreon-plugins_2
164+
165+
- name: Create event command
166+
t_systems_mms.icinga_director.icinga_command:
167+
state: present
168+
url: "{{ icinga_url }}"
169+
url_username: "{{ icinga_user }}"
170+
url_password: "{{ icinga_pass }}"
171+
command: "/opt/scripts/restart_httpd"
172+
object_name: "restart_httpd"
173+
arguments:
174+
'-s':
175+
value: $service.state$
176+
'-t':
177+
value: $service.state_type$
178+
'-a':
179+
set_if: $service.check_attempt$
180+
value: $restart_service$
164181
"""
165182

166183
RETURN = r""" # """

plugins/modules/icinga_host_template.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777
- The name of the check command.
7878
- Though this is not required to be defined in the director, you still have to supply a check_command in a host or host-template.
7979
type: str
80+
event_command:
81+
description:
82+
- Event command for host which gets called on every check execution if one of these conditions matches
83+
- The host is in a soft state
84+
- The host state changes into a hard state
85+
- The host state recovers from a soft or hard state to OK/Up
86+
type: str
8087
check_interval:
8188
description:
8289
- Your regular check interval.
@@ -190,6 +197,7 @@ def main():
190197
has_agent=dict(type="bool", choices=[True, False]),
191198
master_should_connect=dict(type="bool", choices=[True, False]),
192199
accept_config=dict(type="bool", choices=[True, False]),
200+
event_command=dict(type="str", required=False),
193201
)
194202

195203
# Define the main module
@@ -215,6 +223,7 @@ def main():
215223
"has_agent": module.params["has_agent"],
216224
"master_should_connect": module.params["master_should_connect"],
217225
"accept_config": module.params["accept_config"],
226+
"event_command": module.params["event_command"],
218227
}
219228

220229
icinga_object = Icinga2APIObject(module=module, path="/host", data=data)

plugins/modules/icinga_service_template.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@
8383
description:
8484
- Whether to process performance data provided by this object.
8585
type: "bool"
86+
event_command:
87+
description:
88+
- Event command for service which gets called on every check execution if one of these conditions matches
89+
- The service is in a soft state
90+
- The service state changes into a hard state
91+
- The service state recovers from a soft or hard state to OK/Up
92+
type: "str"
8693
groups:
8794
description:
8895
- Service groups that should be directly assigned to this service.
@@ -155,6 +162,18 @@
155162
procs_warning: '1:'
156163
notes: "example note"
157164
notes_url: "'http://url1' 'http://url2'"
165+
166+
- name: Create servicetemplate with event command
167+
t_systems_mms.icinga_director.icinga_service_template:
168+
state: present
169+
url: "{{ icinga_url }}"
170+
url_username: "{{ icinga_user }}"
171+
url_password: "{{ icinga_pass }}"
172+
object_name: apache_check_servicetemplate
173+
use_agent: false
174+
event_command: restart_httpd
175+
notes: "example note"
176+
notes_url: "'http://url1' 'http://url2'"
158177
"""
159178

160179
RETURN = r""" # """
@@ -187,6 +206,7 @@ def main():
187206
enable_notifications=dict(type="bool", required=False),
188207
enable_passive_checks=dict(type="bool", required=False),
189208
enable_perfdata=dict(type="bool", required=False),
209+
event_command=dict(type="str", required=False),
190210
groups=dict(type="list", elements="str", default=[], required=False),
191211
imports=dict(type="list", elements="str", default=[], required=False),
192212
max_check_attempts=dict(required=False),
@@ -216,6 +236,7 @@ def main():
216236
"enable_notifications": module.params["enable_notifications"],
217237
"enable_passive_checks": module.params["enable_passive_checks"],
218238
"enable_perfdata": module.params["enable_perfdata"],
239+
"event_command": module.params["event_command"],
219240
"groups": module.params["groups"],
220241
"imports": module.params["imports"],
221242
"max_check_attempts": module.params["max_check_attempts"],

roles/ansible_icinga/tasks/icinga_host_template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
has_agent: "{{ host_template.0.has_agent | default(omit) }}"
2929
master_should_connect: "{{ host_template.0.master_should_connect | default(omit) }}"
3030
accept_config: "{{ host_template.0.accept_config | default(omit) }}"
31+
event_command: "{{ host_template.0.event_command | default(omit) }}"
3132
loop: "{{ icinga_host_templates|subelements('host_template_object') }}"
3233
loop_control:
3334
loop_var: host_template

roles/ansible_icinga/tasks/icinga_service_template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use_agent: "{{ service_template.0.use_agent | default(omit) }}"
3434
vars: "{{ service_template.0.vars | default(omit) }}"
3535
volatile: "{{ service_template.0.volatile | default(omit) }}"
36+
event_command: "{{ service_template.0.event_command | default(omit) }}"
3637
loop: "{{ icinga_service_templates|subelements('service_template_object') }}"
3738
loop_control:
3839
loop_var: service_template

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,18 @@
6161
url_username: "{{ icinga_user }}"
6262
url_password: "{{ icinga_pass }}"
6363
object_name: centreon-plugins_2
64+
- name: Create event command
65+
t_systems_mms.icinga_director.icinga_command:
66+
state: absent
67+
url: "{{ icinga_url }}"
68+
url_username: "{{ icinga_user }}"
69+
url_password: "{{ icinga_pass }}"
70+
object_name: "restart_httpd"
71+
arguments:
72+
'-s':
73+
value: $service.state$
74+
'-t':
75+
value: $service.state_type$
76+
'-a':
77+
set_if: $service.check_attempt$
78+
value: $restart_service$

0 commit comments

Comments
 (0)