From 01bb987fb328d46c7d7f77934aaebd9d8c46382f Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Wed, 17 May 2017 10:32:39 +0200 Subject: [PATCH] nagios-nrpe: add varnish check and tags --- .../files/plugins/check_varnish_health | 89 +++++++++++++++++++ nagios-nrpe/tasks/main.yml | 4 + nagios-nrpe/templates/evolix.cfg.j2 | 3 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100755 nagios-nrpe/files/plugins/check_varnish_health diff --git a/nagios-nrpe/files/plugins/check_varnish_health b/nagios-nrpe/files/plugins/check_varnish_health new file mode 100755 index 00000000..6b2d883a --- /dev/null +++ b/nagios-nrpe/files/plugins/check_varnish_health @@ -0,0 +1,89 @@ +#!/bin/bash +# +# check_varnish_health +# +# A nagios plugin to check the health status of a varnish web cache using varnishadm. +# by rudi kramer +# Copyright 2010 rudi Kramer , BSD-style copyright and disclaimer. +# +# version 1.1 - Fixed bug where backend server is not called default +# +# Command Line Usage: ./check_varnish_health -i -p +# +# Example: ./check_varnish_health -i 127.0.0.1 -p 6082 +# +################################################################################# + +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +E_SUCCESS="0" +E_WARNING="1" +E_CRITICAL="2" +E_UNKNOWN="3" + +PROGNAME=`basename $0` +CHECK_VARNISHD=`ps ax| grep varnishd| grep -v grep` + +print_help() { + echo "" + echo "This plugin checks the health status of a varnish web cache using varnishadm" + echo "" + echo "Usage: $PROGNAME -i -p -s -w -c " + echo "" +} + +if [ $# -lt 10 ]; then + print_help + exit $E_UNKNOWN +fi + +if [ -z "$CHECK_VARNISHD" ]; then + echo "CRITICAL: varnishd is not running, unable to check health status" + exit $E_CRITICAL +fi + +while test -n "$1"; do + case "$1" in + --help | -h) + print_help + exit $E_UNKNOWN + ;; + -i) + IP=$2 + shift + ;; + -p) + PORT=$2 + shift + ;; + -s) + SECRET=$2 + shift + ;; + -w) + WARNING=$2 + shift + ;; + -c) + CRITICAL=$2 + shift + ;; + esac + shift +done + +COMMAND=`varnishadm -S $SECRET -T $IP\:$PORT debug.health 2>&1 | grep "^Backend " | grep -v "Healthy" |wc -l` +OUTPUT=`varnishadm -S $SECRET -T $IP\:$PORT debug.health 2>&1 | grep "^Backend " |tr '\n' ','` + +if [ $COMMAND -lt $WARNING ]; then + echo "OK: $OUTPUT" + exit ${E_SUCCESS} + +elif [ $COMMAND -lt $CRITICAL ]; then + echo "WARNING: $OUTPUT" + exit ${E_WARNING} + +else + echo "CRITICAL: $OUTPUT" + exit ${E_CRITICAL} +fi diff --git a/nagios-nrpe/tasks/main.yml b/nagios-nrpe/tasks/main.yml index bb765176..e723d322 100644 --- a/nagios-nrpe/tasks/main.yml +++ b/nagios-nrpe/tasks/main.yml @@ -1,6 +1,10 @@ --- - include: debian.yml when: ansible_os_family == "Debian" + tags: + - nagios - include: openbsd.yml when: ansible_os_family == "OpenBSD" + tags: + - nagios diff --git a/nagios-nrpe/templates/evolix.cfg.j2 b/nagios-nrpe/templates/evolix.cfg.j2 index 24f569f1..96bc5649 100644 --- a/nagios-nrpe/templates/evolix.cfg.j2 +++ b/nagios-nrpe/templates/evolix.cfg.j2 @@ -45,6 +45,7 @@ command[check_redis]=/usr/lib/nagios/plugins/check_tcp -p 6379 command[check_clamd]=/usr/lib/nagios/plugins/check_clamd -H /var/run/clamav/clamd.ctl -v command[check_ssl]=/usr/lib/nagios/plugins/check_http -f follow -I 127.0.0.1 -S -p 443 -H ssl.evolix.net -C 15,5 command[check_elasticsearch]=/usr/lib/nagios/plugins/check_http -H localhost -u /_cluster/health -p 9200 -r '"status":"red",' --invert-regex +command[check_memcached]=/usr/lib/nagios/plugins/check_tcp -H 127.0.0.1 -p 11211 # Local checks (not packaged) command[check_mem]={{ nagios_plugins_directory }}/check_mem -f -C -w 20 -c 10 @@ -57,7 +58,7 @@ command[check_drbd]={{ nagios_plugins_directory }}/check_drbd -d All -c StandAlo command[check_mongodb_connect]={{ nagios_plugins_directory }}/check_mongodb -H localhost -P27017 -A connect command[check_glusterfs]={{ nagios_plugins_directory }}/check_glusterfs -v all -n 0 command[check_supervisord_status]={{ nagios_plugins_directory }}/check_supervisord -command[check_memcached]=/usr/lib/nagios/plugins/check_tcp -H 127.0.0.1 -p 11211 +command[check_varnish]={{ nagios_plugins_directory }}/check_varnish_health -i 127.0.0.1 -p 6082 -s /etc/varnish/secret -w 2 -c 4 # Check HTTP "many". Use this to check many websites (http, https, ports, sockets and SSL certificates). # Beware! All checks must not take more than 10s!