]>
git.sthu.org Git - shutils.git/blob - nagios/plugins/check_rdns
3 # Copyright (c) 2013 Stefan Huber <shuber@sthu.org>
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation
7 # files (the "Software"), to deal in the Software without
8 # restriction, including without limitation the rights to use,
9 # copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 # OTHER DEALINGS IN THE SOFTWARE.
26 . $
(dirname $0)/utils.sh
29 PROGNAME
=$
(basename $0)
36 Copyright (c) 2013 Stefan Huber <shuber@sthu.org>
38 Usage: $PROGNAME -H ip-address [OPTIONS]
41 -H, --address IP-address The ip-addres on which reverse-DNS is performed.
44 -h, --help Print this text.
45 -a, --expect=HOST The expected result.
46 -s, --server=HOST The DNS server to contact.
47 -t, --timeout=SEC Seconds before lookup times out. (Default: 10)
48 -w, --warning=MSEC Return warning if lookup time exceeds value.
49 -c, --critical=MSEC Return critical if lookup time exceeds value.
50 -V, --version Print version info.
55 TEMP
=`getopt -o "H:a:c:hs:t:w:V" --long "help,address:,expect:,critical:,server:,timeout:,warning:,version" -n "$PROGNAME" -- "$@"`
71 echo "$PROGNAME v$REVISION"
74 ADDRESS
="$2"; shift 2 ;;
76 EXPECT
="$2"; shift 2 ;;
78 SERVER
="$2"; shift 2 ;;
80 TIMEOUT
="$2"; shift 2 ;;
82 WARNING
="$2"; shift 2 ;;
84 CRITICAL
="$2"; shift 2 ;;
93 if [ -z "$ADDRESS" ]; then
94 echo "Error: No address given."
99 DIGOPTS
="+time=$TIMEOUT +noquestion +noauthority -t PTR"
100 [ -z "$SERVER" ] || DIGOPTS
="@$SERVER $DIGOPTS"
102 RESULT
=$
(dig $DIGOPTS -x "$ADDRESS"):
105 if [ $DIGSTATUS != "0" ]; then
106 echo "DNS failed: dig exit code $DIGSTATUS |"
110 # Get the actual result
111 HOST
=$
(echo "$RESULT" |
grep -m 1 -o "[[:space:]]IN[[:space:]]*PTR[[:space:]].*\.$" |
awk '{ print $3 }' )
112 if [ -z "$HOST" ]; then
113 echo "DNS failed: reverse DNS gave no answer. |"
118 # Get the query time in msec
119 QUERYTIME
=$
(echo "$RESULT" |
grep -m 1 "Query time:" | cut
-d ":" -f 2 |
awk '{ print $1 }')
123 if [ -n "$EXPECT" ]; then
124 if [ "$EXPECT" != "$HOST" ]; then
125 echo "DNS critical - query result \"$HOST\" != \"$EXPECT\", query time: $QUERYTIME msec |"
128 MATCHED
=" (match ok)"
132 if [ -n "$CRITICAL" ] && [ "$QUERYTIME" -gt "$CRITICAL" ]; then
133 echo "DNS critical - query time $QUERYTIME msec too large ($CRITICAL msec), query result: \"$HOST\"$MATCHED |"
137 if [ -n "$WARNING" ] && [ "$QUERYTIME" -gt "$WARNING" ]; then
138 echo "DNS warning - query time $QUERYTIME msec too large ($WARNING msec), query result: \"$HOST\"$MATCHED |"
142 echo "DNS OK - query time $QUERYTIME msec, query result: \"$HOST\"$MATCHED |"