From ac6245ddde662adeaa63d5286458818e444e7368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bompard?= Date: Mon, 12 Aug 2019 16:29:35 +0200 Subject: [PATCH] Delegate the nagios and nrpe handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aurélien Bompard --- roles/rabbit/queue/handlers/main.yml | 9 +++++++++ roles/rabbit/queue/tasks/main.yml | 12 +++++------- roles/rabbit/queue/templates/nrpe.cfg.j2 | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 roles/rabbit/queue/handlers/main.yml diff --git a/roles/rabbit/queue/handlers/main.yml b/roles/rabbit/queue/handlers/main.yml new file mode 100644 index 0000000000..55c71a083e --- /dev/null +++ b/roles/rabbit/queue/handlers/main.yml @@ -0,0 +1,9 @@ +- name: restart nagios on noc + shell: nagios -v /etc/nagios/nagios.cfg && systemctl restart nagios + delegate_to: "{{ nagios_server }}" + +- name: restart nrpe on rabbitmq + service: + name: nrpe + state: restarted + delegate_to: "{{ rabbitmq_server }}" \ No newline at end of file diff --git a/roles/rabbit/queue/tasks/main.yml b/roles/rabbit/queue/tasks/main.yml index 9c6eccb0b8..0ec927ab26 100644 --- a/roles/rabbit/queue/tasks/main.yml +++ b/roles/rabbit/queue/tasks/main.yml @@ -21,9 +21,10 @@ # The values are numbers. Generate an alert in Nagios if # the number of messages go above these values. -- assert: +- name: Validate parameters + assert: that: - - "queue_name.startswith(username)" + - "queue_name.startswith(username)" fail_msg: "Your queue name must be prefixed with your username" # See https://www.rabbitmq.com/access-control.html#permissions for details on @@ -74,10 +75,7 @@ owner: root group: root mode: 0644 - notify: - - restart nrpe - tags: - - nagios_client + notify: restart nrpe on rabbitmq - name: Monitor the {{ queue_name }} queue in Nagios when: thresholds and env == "production" @@ -85,4 +83,4 @@ template: src: nagios.cfg.j2 dest: /etc/nagios/services/rabbitmq-queue-{{ queue_name }}.cfg - notify: restart nagios \ No newline at end of file + notify: restart nagios on noc \ No newline at end of file diff --git a/roles/rabbit/queue/templates/nrpe.cfg.j2 b/roles/rabbit/queue/templates/nrpe.cfg.j2 index 23b04c832e..75df6127bf 100644 --- a/roles/rabbit/queue/templates/nrpe.cfg.j2 +++ b/roles/rabbit/queue/templates/nrpe.cfg.j2 @@ -1 +1 @@ -command[check_rabbitmq_queue_{{ vhost.replace("/", "") }}_{{ queue_name }}]=/usr/lib64/nagios/plugins-rabbitmq/check_rabbitmq_queue --extra-opts=common@/etc/nrpe.d/rabbitmq_args.ini --vhost {{ vhost }} --queue {{ queue_name }} {% if thresholds.warning %}-w {{ thresholds.warning }}{% endif %}{% if thresholds.critical %}-c {{ thresholds.critical }}{% endif %} \ No newline at end of file +command[check_rabbitmq_queue_{{ vhost.replace("/", "") }}_{{ queue_name }}]=/usr/lib64/nagios/plugins-rabbitmq/check_rabbitmq_queue --extra-opts=common@/etc/nrpe.d/rabbitmq_args.ini --vhost {{ vhost }} --queue {{ queue_name }} {% if thresholds.warning %}-w {{ thresholds.warning }}{% endif %} {% if thresholds.critical %}-c {{ thresholds.critical }}{% endif %}