Browse Source

monitoring: new host template

python3
Zolfa 4 years ago
parent
commit
6db052e8a7
Signed by: zolfa GPG Key ID: E1A43B038C4D6616
7 changed files with 47 additions and 12 deletions
  1. +2
    -2
      roles/gitlab/tasks/main.yaml
  2. +12
    -6
      roles/icinga2-monitoring/templates/host.conf.j2
  3. +21
    -0
      roles/icinga2/tasks/main.yaml
  4. +4
    -3
      roles/lxc_guest/tasks/main.yaml
  5. +1
    -0
      roles/monitoring-agent/defaults/main.yaml
  6. +6
    -0
      roles/monitoring-agent/tasks/main.yaml
  7. +1
    -1
      roles/nextcloud/tasks/main.yaml

+ 2
- 2
roles/gitlab/tasks/main.yaml View File

@ -109,8 +109,8 @@
monitoring_entry: >
{{ monitoring_entry | default({}) | combine({
'address': ansible_host,
'vhosts_uri': { gitlab_nginx_main_fqdn: {'/': 'Sign in · GitLab'},
gitlab_nginx_mattermost_fqdn: { '/': '<title>Mattermost</title>' } },
'vhosts_uri': { gitlab_nginx_main_fqdn: {'/': { 'content': 'Sign in · GitLab'} },
gitlab_nginx_mattermost_fqdn: { '/': { 'content': '<title>Mattermost</title>' } } },
}, recursive=true) }}
- name: 'MONITORING | update monitoring facts'
set_fact:


+ 12
- 6
roles/icinga2-monitoring/templates/host.conf.j2 View File

@ -10,8 +10,14 @@ object Host "{{ item.key }}" {
vars.agent_type = "ssh"
{% endif %}
vars.host_type = "{{ item.value.host_type | d('physical') }}"
{% for var in item.value.vars|d({})|dict2items %}
vars.{{ var.key }} = "{{ var.value }}"
{% endfor %}
{% if 'vhosts' in item.value %}
{% for vhost in item.value.vhosts %}
{% for vhost in item.value.vhosts %}
vars.http_vhosts["https cert: {{ vhost }}"] = {
http_ssl = true
http_vhost = "{{ vhost }}"
@ -20,17 +26,17 @@ object Host "{{ item.key }}" {
/* Check remaining days before cert expiration */
http_certificate = "30,20"
}
{% for uri, content in (item.value.vhosts_uri[vhost]|d({'/': ''})).items() %}
{% for uri, prop in (item.value.vhosts_uri[vhost]|d({'/': {}})).items() %}
vars.http_vhosts["https service: {{ vhost }}{{ uri }}"] = {
http_ssl = true
http_vhost = "{{ vhost }}"
http_onredirect = "sticky"
http_onredirect = "{{ prop.onredirect|d('sticky') }}"
http_sni = true
http_uri = "{{ uri }}"
{% if content != '' %}http_string = "{{ content|replace('"','\\"') }}"{% endif %}
{% if prop.content|d('') != '' %}http_string = "{{ prop.content|replace('"','\\"') }}"{% endif %}
}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
}


+ 21
- 0
roles/icinga2/tasks/main.yaml View File

@ -253,4 +253,25 @@
dest: "/etc/nginx/locations/{{ icingaweb2_nginx_fqdn }}/service.conf"
notify:
- 'reload nginx'
- name: 'MONITORING | add HTTP service'
block:
- name: 'MONITORING | add service to monitoring entry'
set_fact:
monitoring_entry: >
{{ monitoring_entry | default({}) | combine({
'address': ansible_host,
'vhosts_uri': { icingaweb2_nginx_fqdn: {'/icingaweb2': { 'onredirect': 'ok' }} },
}, recursive=true) }}
- name: 'MONITORING | update monitoring facts'
set_fact:
monitoring_facts: >
{{ hostvars[monitoring_host]['monitoring_facts']
| default({})
| combine({host_fqdn: monitoring_entry}) }}
delegate_facts: true
delegate_to: '{{ monitoring_host }}'
tags:
- 'monitoring'
...

+ 4
- 3
roles/lxc_guest/tasks/main.yaml View File

@ -162,14 +162,15 @@
block:
- name: 'MONITORING | add to monitored hosts'
set_fact:
lxc_monitoring_entry: >
{{ { host_fqdn: { 'address': ansible_host } } }}
monitoring_entry: >
{{ { 'address': ansible_host,
'host_type': 'lxc_vm' } }}
- name: 'MONITORING | update monitoring facts'
set_fact:
monitoring_facts: >
{{ hostvars[monitoring_host]['monitoring_facts']
| default({})
| combine(lxc_monitoring_entry) }}
| combine({host_fqdn: monitoring_entry}) }}
delegate_facts: true
delegate_to: '{{ monitoring_host }}'
tags:


+ 1
- 0
roles/monitoring-agent/defaults/main.yaml View File

@ -1,3 +1,4 @@
---
host_fqdn: '{{ ansible_hostname }}.dmz.{{ domain }}'
monitoring_agent_ssh_mode: true
...

+ 6
- 0
roles/monitoring-agent/tasks/main.yaml View File

@ -8,6 +8,12 @@
tags:
- 'packages'
- name: 'add monitoring plugin - check_mem.pl'
copy:
src: 'check_mem.pl'
dest: '/usr/lib/nagios/plugins/check_mem.pl'
mode: '0755'
- name: 'create monitoring user'
user:
name: 'icinga'


+ 1
- 1
roles/nextcloud/tasks/main.yaml View File

@ -257,7 +257,7 @@
monitoring_entry: >
{{ monitoring_entry | default({}) | combine({
'address': ansible_host,
'vhosts_uri': { nextcloud_nginx_fqdn: {'/': 'nextcloud.com'} },
'vhosts_uri': { nextcloud_nginx_fqdn: {'/': { 'content': 'nextcloud.com'}} },
}, recursive=true) }}
- name: 'MONITORING | update monitoring facts'
set_fact:


Loading…
Cancel
Save