diff --git a/handlers/main.yml b/handlers/main.yml index 78cd12d8e1288b976b70c6b682d345824440b757..2da84be19d267a444349b923b4ae4b170da68552 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,44 +2,5 @@ - name: restart nrpe service: - name: nrpe + name: nagios-nrpe-server state: restarted - -- name: Initial configuration Nagios NRPE - command: ./configure --enable-command-args --with-nagios-user=nagios --with-nagios-group=nagios --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu --enable-ssl - args: - chdir: /root/nrpe-{{ nrpe_version }} - async: 500 - poll: 10 - -- name: Make nagios NRPE - make: - chdir: /root/nrpe-{{ nrpe_version }} - target: "{{ item }}" - with_items: - - all - - install - - install-config - - install-init - async: 120 - poll: 10 - -- name: Systemd daemon reload - systemd: daemon-reload=yes - -- name: Initial configuration Nagios Plugins - command: ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-openssl - args: - chdir: /root/nagios-plugins-{{ nagios_plugins_version }} - async: 500 - poll: 10 - -- name: Make nagios-plugins - make: - chdir: /root/nagios-plugins-{{ nagios_plugins_version }} - target: "{{ item }}" - with_items: - - all - - install - async: 120 - poll: 10 diff --git a/tasks/main.yml b/tasks/main.yml index 5a5796e3cefea0dd8ff2cdb5cb48d9577f44fb60..16211652fd1e6a5d6b4d2a79f53628450bedaa59 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,82 +2,28 @@ - name: Include OS-specific variables. include_vars: "{{ ansible_os_family }}.yml" -- name: Install NRPE dependencies +- name: Install NRPE and basic plugins package: - name: "{{ packages_to_install }}" + name: + - nagios-nrpe-server + - monitoring-plugins-basic state: present -# -------------------------------------------------- -# CREATE NAGIOS USERS -# -------------------------------------------------- -- name: Create nagios system group - group: - name: "{{ item }}" - with_items: - - nagios - - nagcmd - tags: nagios_install - -- name: Create nagios system user - user: - system: true - name: nagios - group: nagios - groups: nagcmd - tags: nagios_install - -# -------------------------------------------------- -# INSTALLATION NAGIOS NRPE -# -------------------------------------------------- -- name: Retrieve and Uncompress Nagios NRPE - unarchive: - src: https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-{{ nrpe_version }}/nrpe-{{ nrpe_version }}.tar.gz - remote_src: true - dest: /root/ - creates: /root/nrpe-{{ nrpe_version }} - notify: - - Initial configuration Nagios NRPE - - Make nagios NRPE - - Systemd daemon reload - -# Flush handlers in order to run make NRPE if necessary -- name: Flush handlers - meta: flush_handlers - - name: Make NRPE start with system service: - name: nrpe + name: nagios-nrpe-server state: started enabled: true -- name: Check that nrpe is defined in services - lineinfile: - name: /etc/services - regexp: '^nrpe' - line: "nrpe 5666/tcp # Nagios Remote Plugin Executor" - -# -------------------------------------------------- -# INSTALLATION NAGIOS PLUGINS -# -------------------------------------------------- -- name: Retrieve and Uncompress Nagios Plugins - unarchive: - src: https://github.com/nagios-plugins/nagios-plugins/releases/download/release-{{ nagios_plugins_version }}/nagios-plugins-{{ nagios_plugins_version }}.tar.gz - remote_src: true - dest: /root/ - creates: /root/nagios-plugins-{{ nagios_plugins_version }} - notify: - - Initial configuration Nagios Plugins - - Make nagios-plugins - # -------------------------------------------------- # CONFIGURATION NRPE # -------------------------------------------------- - name: Push NRPE configuration file template: src: nrpe.cfg.j2 - dest: /usr/local/nagios/etc/nrpe.cfg - owner: nagios - group: nagios + dest: /etc/nagios/nrpe.cfg + owner: root + group: root mode: '0644' notify: restart nrpe tags: nrpe_config @@ -85,40 +31,40 @@ # -------------------------------------------------- # AJOUT CUSTOM SCRIPTs # -------------------------------------------------- +- name: create custom-plugin repo if not created from previous tasks + file: + name: /usr/lib/nagios/custom-plugins + state: directory + owner: root + group: root + mode: '0755' + - name: get custom scripts from gitlab git: repo: "https://sources.le-filament.com/lefilament/nagios-plugin.git" - dest: "/usr/local/nagios/libexec/custom-plugin" + dest: "/usr/lib/nagios/custom-plugins" version: "master" when: inventory_hostname in groups.backup_server - name: set file rights on custom plugins file: name={{ item }} mode=0555 with_items: - - /usr/local/nagios/libexec/custom-plugin/check_cloud_storage.sh - - /usr/local/nagios/libexec/custom-plugin/check_odoo_storage.sh - - /usr/local/nagios/libexec/custom-plugin/check_odoo2_storage.sh + - /usr/lib/nagios/custom-plugins/check_cloud_storage.sh + - /usr/lib/nagios/custom-plugins/check_odoo_storage.sh + - /usr/lib/nagios/custom-plugins/check_odoo2_storage.sh when: inventory_hostname in groups.backup_server -- name: create custom-plugin repo if not created from previous tasks - file: - name: /usr/local/nagios/libexec/custom-plugin - state: directory - owner: root - group: root - mode: '0755' - - name: add check_mdstat script get_url: url: https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=5423&cf_id=24 - dest: /usr/local/nagios/libexec/custom-plugin/check_mdstat.sh + dest: /usr/lib/nagios/custom-plugins/check_mdstat.sh mode: '0555' when: raid_config is defined - name: add extra scripts get_url: url: "{{ item.url }}" - dest: /usr/local/nagios/libexec/custom-plugin/{{ item.name }} + dest: /usr/lib/nagios/custom-plugins/{{ item.name }} mode: '0555' with_items: "{{ plugins_to_download }}" loop_control: diff --git a/templates/nrpe.cfg.j2 b/templates/nrpe.cfg.j2 index bb89c1397a401c1c05d36d6d086dc4d5da327fbf..11aca8a8159dd7a730a6b6932f7779cdff8b641c 100644 --- a/templates/nrpe.cfg.j2 +++ b/templates/nrpe.cfg.j2 @@ -1,8 +1,8 @@ allow_bash_command_substitution=0 -{% if inventory_hostname in groups.docker_nagios %} -allowed_hosts={{ groups.docker_nagios | map('extract', hostvars, ['ansible_host']) | join(',') }},192.168.239.2,127.0.0.1 +{% if inventory_hostname in groups.docker_nagios | default([]) %} +allowed_hosts={{ groups.docker_nagios | default([]) | map('extract', hostvars, ['ansible_host']) | join(',') }},192.168.239.2,127.0.0.1 {% else %} -allowed_hosts={{ groups.docker_nagios | map('extract', hostvars, ['ansible_host']) | join(',') }},127.0.0.1 +allowed_hosts={{ groups.docker_nagios | default([]) | map('extract', hostvars, ['ansible_host']) | join(',') }},127.0.0.1 {% endif %} command_timeout=60 connection_timeout=300 @@ -11,115 +11,115 @@ dont_blame_nrpe=0 log_facility=daemon nrpe_user=nagios nrpe_group=nagios -pid_file=/usr/local/nagios/var/nrpe.pid +pid_file=/run/nagios/nrpe.pid server_port=5666 # Generic checks -command[check_hda1]=/usr/local/nagios/libexec/check_disk -u GB -w 20% -c 10% -p / +command[check_hda1]=/usr/lib/nagios/plugins/check_disk -u GB -w 20% -c 10% -p / {% if raid_config is defined %} {% for device in raid_config.devices %} -command[check_raid_{{ device }}]=/usr/local/nagios/libexec/custom-plugin/check_mdstat.sh {{ device }} {{ raid_config.disks }} +command[check_raid_{{ device }}]=/usr/lib/nagios/custom-plugins/check_mdstat.sh {{ device }} {{ raid_config.disks }} {% endfor %} {% endif %} -command[check_load]=/usr/local/nagios/libexec/check_load -r -w .85,.80,.75 -c .99,.95,.90 -command[check_mem]=/usr/local/nagios/libexec/custom-plugin/check_mem.pl -f -C -w 20 -c 5 -{% if inventory_hostname in groups.docker %} -command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w {{ ((group_names | length - 7) * 20 + 370) | int | abs }} -c {{ ((group_names | length - 7) * 20 + 410) | int | abs }} +command[check_load]=/usr/lib/nagios/plugins/check_load -r -w .85,.80,.75 -c .99,.95,.90 +command[check_mem]=/usr/lib/nagios/custom-plugins/check_mem.pl -f -C -w 20 -c 5 +{% if inventory_hostname in groups.docker | default([]) %} +command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w {{ ((group_names | length - 7) * 20 + 370) | int | abs }} -c {{ ((group_names | length - 7) * 20 + 410) | int | abs }} {% else %} -command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 290 -c 350 +command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 290 -c 350 {% endif %} -command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 -command[check_version]=/usr/local/nagios/libexec/custom-plugin/check_version.sh +command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10 +command[check_version]=/usr/lib/nagios/custom-plugins/check_version.sh # Check specific processes -command[check_fail2ban]=/usr/local/nagios/libexec/custom-plugin/check_fail2ban -w 350 -c 500 -{% if inventory_hostname in groups.docker_gitlab %} -command[check_procs_sshd]=/usr/local/nagios/libexec/check_procs -w 4 -c 2: -C sshd -a -D +command[check_fail2ban]=/usr/lib/nagios/custom-plugins/check_fail2ban -w 350 -c 500 +{% if inventory_hostname in groups.docker_gitlab | default([]) %} +command[check_procs_sshd]=/usr/lib/nagios/plugins/check_procs -w 4 -c 2: -C sshd -a -D {% else %} -command[check_procs_sshd]=/usr/local/nagios/libexec/check_procs -w 2 -c 1: -C sshd -a -D +command[check_procs_sshd]=/usr/lib/nagios/plugins/check_procs -w 2 -c 1: -C sshd -a -D {% endif %} -{% if inventory_hostname in groups.odoo_server | union(groups.owncloud_server) %} -command[check_procs_nginx]=/usr/local/nagios/libexec/check_procs -w 5 -c 2: -C nginx +{% if inventory_hostname in groups.odoo_server | default([]) | union(groups.owncloud_server | default([])) %} +command[check_procs_nginx]=/usr/lib/nagios/plugins/check_procs -w 5 -c 2: -C nginx {% endif %} -{% if inventory_hostname in groups.full_maintenance %} -command[check_procs_filebeat]=/usr/local/nagios/libexec/check_procs -w 2 -c 1: -C filebeat -command[check_apt]=/usr/local/nagios/libexec/check_apt +{% if inventory_hostname in groups.full_maintenance | default([]) %} +command[check_procs_filebeat]=/usr/lib/nagios/plugins/check_procs -w 2 -c 1: -C filebeat +command[check_apt]=/usr/lib/nagios/plugins/check_apt {% endif %} -{% if inventory_hostname in groups.odoo_server %} -command[check_procs_odoo]=/usr/local/nagios/libexec/check_procs -w 2 -c 1: -C python -a odoo-bin +{% if inventory_hostname in groups.odoo_server | default([]) %} +command[check_procs_odoo]=/usr/lib/nagios/plugins/check_procs -w 2 -c 1: -C python -a odoo-bin {% endif %} -{% if inventory_hostname in groups.owncloud_server %} -command[check_procs_owncloud]=/usr/local/nagios/libexec/check_procs -w 10 -c 2: -C php-fpm{{ php_version | default('7.2') }} +{% if inventory_hostname in groups.owncloud_server | default([]) %} +command[check_procs_owncloud]=/usr/lib/nagios/plugins/check_procs -w 10 -c 2: -C php-fpm{{ php_version | default('7.2') }} {% endif %} -{% if inventory_hostname in groups.backup_server %} +{% if inventory_hostname in groups.backup_server | default([]) %} # Backup Server -command[check_cloud_storage]=/usr/local/nagios/libexec/custom-plugin/check_cloud_storage.sh -command[check_odoo_storage]=/usr/local/nagios/libexec/custom-plugin/check_odoo_storage.sh -command[check_odoo2_storage]=/usr/local/nagios/libexec/custom-plugin/check_odoo2_storage.sh +command[check_cloud_storage]=/usr/lib/nagios/custom-plugins/check_cloud_storage.sh +command[check_odoo_storage]=/usr/lib/nagios/custom-plugins/check_odoo_storage.sh +command[check_odoo2_storage]=/usr/lib/nagios/custom-plugins/check_odoo2_storage.sh {% endif %} -{% if inventory_hostname in groups.docker %} +{% if inventory_hostname in groups.docker | default([]) %} # Docker Containers -command[check_docker_proxy]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^inverseproxy.*' --cpu 10:15 --memory 10:15 +command[check_docker_proxy]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^inverseproxy.*' --cpu 10:15 --memory 10:15 {% endif %} -{% if inventory_hostname in groups.docker_auth %} -command[check_docker_ldap]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '.*ldap.*' --cpu 5:10 --memory 12:17 -command[check_docker_sso]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^sso' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_auth | default([]) %} +command[check_docker_ldap]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '.*ldap.*' --cpu 5:10 --memory 12:17 +command[check_docker_sso]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^sso' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_drawio %} -command[check_docker_drawio]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^drawio.*' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_drawio | default([]) %} +command[check_docker_drawio]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^drawio.*' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_etherpad %} -command[check_docker_etherpad]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^etherpad.*' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_etherpad | default([]) %} +command[check_docker_etherpad]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^etherpad.*' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_framadate %} -command[check_docker_framadate]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^framadate.*' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_framadate | default([]) %} +command[check_docker_framadate]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^framadate.*' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_gitlab %} -command[check_docker_gitlab]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^gitlab.*' --cpu 5:10 --memory 40:60 +{% if inventory_hostname in groups.docker_gitlab | default([]) %} +command[check_docker_gitlab]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^gitlab.*' --cpu 5:10 --memory 40:60 {% endif %} -{% if inventory_hostname in groups.docker_jitsi %} -command[check_docker_jitsi]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^jitsi.*' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_jitsi | default([]) %} +command[check_docker_jitsi]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^jitsi.*' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_mattermost %} -command[check_docker_mattermost]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^mattermost.*' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_mattermost | default([]) %} +command[check_docker_mattermost]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^mattermost.*' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_nagios %} -command[check_docker_nagios]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^nagios.*' --cpu 5:15 --memory 10:15 +{% if inventory_hostname in groups.docker_nagios | default([]) %} +command[check_docker_nagios]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^nagios.*' --cpu 5:15 --memory 10:15 {% endif %} -{% if inventory_hostname in groups.docker_nextcloud %} -{% if inventory_hostname in groups.docker_odoo %} -command[check_docker_cloud]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^nextcloud.*' --cpu 70:80 --memory 15:25 +{% if inventory_hostname in groups.docker_nextcloud | default([]) %} +{% if inventory_hostname in groups.docker_odoo | default([]) %} +command[check_docker_cloud]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^nextcloud.*' --cpu 70:80 --memory 15:25 {% else %} -command[check_docker_cloud]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^nextcloud.*' --cpu 70:80 --memory 65:85 +command[check_docker_cloud]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^nextcloud.*' --cpu 70:80 --memory 65:85 {% endif %} {% endif %} -{% if inventory_hostname in groups.docker_odoo %} +{% if inventory_hostname in groups.docker_odoo | default([]) %} {% if odoo_prod is defined %} -command[check_docker_odoo]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^odoo($|_.*)' --cpu 10:15 --memory 35:45 +command[check_docker_odoo]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^odoo($|_.*)' --cpu 10:15 --memory 35:45 {% endif %} {% for instance in odoo_nonprod_instances | default([]) %} -command[check_docker_{{ instance.name }}]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^{{ instance.dir }}.*' --cpu 10:15 --memory 20:25 +command[check_docker_{{ instance.name }}]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^{{ instance.dir }}.*' --cpu 10:15 --memory 20:25 {% endfor %} {% if restrict_internet_access and whitelisted_urls is defined %} -command[check_docker_whitelists]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^whitelists.*' --cpu 10:10 --memory 5:7 +command[check_docker_whitelists]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^whitelists.*' --cpu 10:10 --memory 5:7 {% endif %} {% endif %} -{% if inventory_hostname in groups.docker_owncloud %} -{% if inventory_hostname in groups.docker_odoo %} -command[check_docker_cloud]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^owncloud.*' --cpu 70:80 --memory 15:25 +{% if inventory_hostname in groups.docker_owncloud | default([]) %} +{% if inventory_hostname in groups.docker_odoo | default([]) %} +command[check_docker_cloud]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^owncloud.*' --cpu 70:80 --memory 15:25 {% else %} -command[check_docker_cloud]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^owncloud.*' --cpu 70:80 --memory 65:55 +command[check_docker_cloud]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^owncloud.*' --cpu 70:80 --memory 65:55 {% endif %} {% endif %} -{% if inventory_hostname in groups.docker_privatebin %} -command[check_docker_privatebin]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^privatebin' --cpu 5:10 --memory 7:12 +{% if inventory_hostname in groups.docker_privatebin | default([]) %} +command[check_docker_privatebin]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^privatebin' --cpu 5:10 --memory 7:12 {% endif %} -{% if inventory_hostname in groups.docker_tuleap %} -command[check_docker_tuleap]=/usr/local/nagios/libexec/custom-plugin/check_docker.sh --filter '^tuleap.*' --cpu 5:10 --memory 9:14 +{% if inventory_hostname in groups.docker_tuleap | default([]) %} +command[check_docker_tuleap]=/usr/lib/nagios/custom-plugins/check_docker.sh --filter '^tuleap.*' --cpu 5:10 --memory 9:14 {% endif %} -{% if inventory_hostname in groups.gitlab %} -command[check_gitlab_services]=/usr/local/nagios/libexec/custom-plugin/check_gitlab.rb -m services -command[check_gitlab_health]=/usr/local/nagios/libexec/custom-plugin/check_gitlab.rb -m health -k -H https://localhost +{% if inventory_hostname in groups.gitlab | default([]) %} +command[check_gitlab_services]=/usr/lib/nagios/custom-plugins/check_gitlab.rb -m services +command[check_gitlab_health]=/usr/lib/nagios/custom-plugins/check_gitlab.rb -m health -k -H https://localhost {% endif %} diff --git a/vars/main.yml b/vars/main.yml index c28622a5b7f38f7066ad2543e3c0373808253cf1..c74c42d506eb3c0b17bbd4c95accc6c6afd9dc61 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -6,8 +6,6 @@ plugins_to_download: url: https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl - name: check_version.sh url: https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=1785&cf_id=24 - - name: check_fail2ban - url: https://raw.githubusercontent.com/n1tr0-5urf3r/icinga2-scripts/master/plugins/check_fail2ban - name: check_gitlab.rb url: https://sources.le-filament.com/lefilament/nagios-plugin/-/raw/master/check_gitlab.rb - name: check_docker.sh