summaryrefslogtreecommitdiff
path: root/puppet/modules/nagios/files/plugins/check_dns2
blob: 219563154016e9c6dd780a05397311075d98c25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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 <host> <type> <server>"
	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