From 6227899364bc721b9c728151a69c46386d96cf44 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 21 Oct 2010 02:24:09 +0200 Subject: add check_dns2 check_dns had some problems with down nameservers. This one properly checks the right nameserver. --- files/plugins/check_dns2 | 102 +++++++++++++++++++++++++++++++++++++++++ manifests/defaults/commands.pp | 4 ++ manifests/defaults/plugins.pp | 7 ++- 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 files/plugins/check_dns2 diff --git a/files/plugins/check_dns2 b/files/plugins/check_dns2 new file mode 100644 index 0000000..2195631 --- /dev/null +++ b/files/plugins/check_dns2 @@ -0,0 +1,102 @@ +#!/bin/bash +# Written by Damien Gy +# damien.gy+nagiosexchange(AT)gmail.com +# 2007-09-28 + +PROGNAME=`basename $0` +REVISION=1.00 +TMP=/tmp/tmpdig +DIG=/usr/bin/dig + +print_revision() { + echo $PROGNAME $REVISION +} + +print_usage() { + echo "Usage:" + echo " $PROGNAME -c|--check " + echo " $PROGNAME -h|--help" + echo " $PROGNAME -v|--version" +} + +print_help() { + print_revision + echo "" + print_usage + echo "Where:" + echo " host the name of the resource record to be looked up" + echo " type indicates the query required (any, a, mx, etc.)" + echo " server the name or IP address of the name server to query" + echo "" + echo " -h|--help prints this help screen" + echo "" + echo " -v|--version prints version and license information" + echo "" + echo " Created by Damien Gy, questions or problems e-mail damien.gy+nagiosexchange(AT)gmail.com" + echo "" +} + +check_dns() { + + if [ $# -ne 3 ] + then + echo "Number of arguments incorrect" + exit 3 + fi + if [ ! -e $DIG ] + then + echo "$DIG not found" + exit 3 + fi + $DIG $1 $2 @$3 > $TMP + + if ( grep "status" $TMP > /dev/null ) + then + # DNS server answered + if ( grep "NOERROR" $TMP > /dev/null ) + then + echo "DNS OK "`grep "time:" $TMP` + rm -f $TMP + exit 0 + else + echo "WARNING "`grep "time:" $TMP` + rm -f $TMP + exit 1 + fi + + else + # no answer + echo "CRITICAL - Connection timed out" + rm -f $TMP + exit 2 + fi +} + +case "$1" in +--help) + print_help + exit 0 + ;; +-h) + print_help + exit 0 + ;; +--version) + print_revision + exit 0 + ;; +-v) + print_revision + exit 0 + ;; +--check) + check_dns $2 $3 $4 + ;; +-c) + check_dns $2 $3 $4 + ;; +*) + print_usage + exit 3 + +esac diff --git a/manifests/defaults/commands.pp b/manifests/defaults/commands.pp index 9375858..06e45e9 100644 --- a/manifests/defaults/commands.pp +++ b/manifests/defaults/commands.pp @@ -98,6 +98,10 @@ class nagios::defaults::commands { # from mysql module check_mysql_health: command_line => '$USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$ --database $ARG6$'; + + # better check_dns + check_dns2: + command_line => '$USER1$/check_dns2 -c $ARG1 A $ARG2'; } # notification commands diff --git a/manifests/defaults/plugins.pp b/manifests/defaults/plugins.pp index 1df8064..842f9ce 100644 --- a/manifests/defaults/plugins.pp +++ b/manifests/defaults/plugins.pp @@ -1,5 +1,10 @@ class nagios::defaults::plugins { - nagios::plugin { 'check_mysql_health': source => 'nagios/plugins/check_mysql_health'; } + nagios::plugin { + 'check_mysql_health': + source => 'nagios/plugins/check_mysql_health'; + 'check_dns2': + source => 'nagios/plugins/check_dns2'; + } } -- cgit v1.2.3