feat: add dependencies
This commit is contained in:
parent
32911bac43
commit
e2ed6fb9b5
8 changed files with 65 additions and 12 deletions
|
@ -5,6 +5,10 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- add dependencies
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- bug in user template
|
- bug in user template
|
||||||
|
|
13
README.md
13
README.md
|
@ -148,6 +148,19 @@ Install and configure Icinga2
|
||||||
monday: 00:05-00:10
|
monday: 00:05-00:10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- `icinga2_dependencies` - hash with dependencies configuration ([view all options](https://icinga.com/docs/icinga-2/latest/doc/09-object-types/#dependency))
|
||||||
|
|
||||||
|
```
|
||||||
|
postgresql-port:
|
||||||
|
parent_host_name: host.name
|
||||||
|
parent_service_name: postgresql-service
|
||||||
|
child_service_name: postgresql-port
|
||||||
|
disable_notifications: true
|
||||||
|
states:
|
||||||
|
- DOWN
|
||||||
|
assign: '"postgresql" in host.groups'
|
||||||
|
```
|
||||||
|
|
||||||
- `icinga2_notifications` - hash with notifications configuration
|
- `icinga2_notifications` - hash with notifications configuration
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -107,4 +107,5 @@ icinga2_users: {}
|
||||||
icinga2_api_users: {}
|
icinga2_api_users: {}
|
||||||
icinga2_check_commands: {}
|
icinga2_check_commands: {}
|
||||||
icinga2_event_commands: {}
|
icinga2_event_commands: {}
|
||||||
|
icinga2_dependencies: {}
|
||||||
icinga2_scripts: {}
|
icinga2_scripts: {}
|
||||||
|
|
|
@ -50,3 +50,8 @@
|
||||||
icinga2_event_commands:
|
icinga2_event_commands:
|
||||||
ping_event:
|
ping_event:
|
||||||
command: '"/usr/bin/ping -c 1 -t 1 127.0.0.1"'
|
command: '"/usr/bin/ping -c 1 -t 1 127.0.0.1"'
|
||||||
|
icinga2_dependencies:
|
||||||
|
test:
|
||||||
|
parent_host_name: host.name
|
||||||
|
disable_notifications: false
|
||||||
|
assign: "true"
|
||||||
|
|
|
@ -2,14 +2,6 @@
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
platforms:
|
platforms:
|
||||||
- name: debian10
|
|
||||||
image: nishiki/debian10:molecule
|
|
||||||
privileged: true
|
|
||||||
volumes:
|
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
|
||||||
command: /bin/systemd
|
|
||||||
capabilities:
|
|
||||||
- SYS_ADMIN
|
|
||||||
- name: debian11
|
- name: debian11
|
||||||
image: nishiki/debian11:molecule
|
image: nishiki/debian11:molecule
|
||||||
privileged: true
|
privileged: true
|
||||||
|
|
|
@ -77,6 +77,15 @@ def test_config_notifications(host):
|
||||||
assert config.mode == 0o640
|
assert config.mode == 0o640
|
||||||
assert config.contains('user_groups = host.vars.notification.mail.groups')
|
assert config.contains('user_groups = host.vars.notification.mail.groups')
|
||||||
|
|
||||||
|
def test_config_dependencies(host):
|
||||||
|
config = host.file('/etc/icinga2/conf.d/dependencies.conf')
|
||||||
|
assert config.exists
|
||||||
|
assert config.is_file
|
||||||
|
assert config.user == 'root'
|
||||||
|
assert config.group == 'nagios'
|
||||||
|
assert config.mode == 0o640
|
||||||
|
assert config.contains('parent_host_name = host.name')
|
||||||
|
|
||||||
def test_script(host):
|
def test_script(host):
|
||||||
path = host.file('/etc/icinga2/scripts/test-notification.sh')
|
path = host.file('/etc/icinga2/scripts/test-notification.sh')
|
||||||
assert path.exists
|
assert path.exists
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0750
|
mode: 0750
|
||||||
loop: '{{ icinga2_scripts|dict2items }}'
|
loop: '{{ icinga2_scripts | dict2items }}'
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.key }}'
|
label: '{{ item.key }}'
|
||||||
tags: icinga2
|
tags: icinga2
|
||||||
|
@ -28,6 +28,7 @@
|
||||||
loop:
|
loop:
|
||||||
- check_commands
|
- check_commands
|
||||||
- commands
|
- commands
|
||||||
|
- dependencies
|
||||||
- groups
|
- groups
|
||||||
- hosts
|
- hosts
|
||||||
- notifications
|
- notifications
|
||||||
|
@ -112,7 +113,7 @@
|
||||||
owner: root
|
owner: root
|
||||||
group: nagios
|
group: nagios
|
||||||
mode: 0640
|
mode: 0640
|
||||||
loop: '{{ icinga2_features|dict2items }}'
|
loop: '{{ icinga2_features | dict2items }}'
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.key }}'
|
label: '{{ item.key }}'
|
||||||
notify: restart icinga2
|
notify: restart icinga2
|
||||||
|
@ -121,8 +122,8 @@
|
||||||
- name: manage features
|
- name: manage features
|
||||||
community.general.icinga2_feature:
|
community.general.icinga2_feature:
|
||||||
name: '{{ item.key }}'
|
name: '{{ item.key }}'
|
||||||
state: '{{ item.state|default("present") }}'
|
state: '{{ item.state | default("present") }}'
|
||||||
loop: '{{ icinga2_features|dict2items }}'
|
loop: '{{ icinga2_features | dict2items }}'
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.key }}'
|
label: '{{ item.key }}'
|
||||||
notify: restart icinga2
|
notify: restart icinga2
|
||||||
|
|
28
templates/dependencies.conf.j2
Normal file
28
templates/dependencies.conf.j2
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
{% for name, dependency in icinga2_dependencies.items() %}
|
||||||
|
|
||||||
|
apply Dependency "{{ name }}" to Service {
|
||||||
|
{% if dependency.parent_host_name is defined %}
|
||||||
|
{% if dependency.parent_host_name == "host.name" %}
|
||||||
|
parent_host_name = host.name
|
||||||
|
{% else %}
|
||||||
|
parent_host_name = {{ dependency.parent_host_name }}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
{% for option in ['parent_service_name', 'child_host_name', 'child_service_name' 'period'] %}
|
||||||
|
{% if dependency[option] is defined %}
|
||||||
|
{{ option }} = "{{ dependency[option] }}"
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% for option in ['disable_checks', 'disable_notifications', 'ignore_soft_states'] %}
|
||||||
|
{% if dependency[option] is defined %}
|
||||||
|
{{ option }} = {{ dependency[option] | ternary("true", "false") }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if dependency.states is defined %}
|
||||||
|
states = [ {{ value | join(', ') }} ]
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
assign where {{ dependency.assign }}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
Loading…
Reference in a new issue