From 797890f152bbad65d1113445a1b42916b3f9c4f4 Mon Sep 17 00:00:00 2001 From: slerena Date: Tue, 11 May 2010 09:03:15 +0000 Subject: [PATCH] 2010-05-11 Sancho Lerena * util/dns_plugin.sh: New DNS plugin for the Plugin Server. It checks a Domain/IP pair and also get time to get response from a given DNS server (ms). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2691 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 ++ pandora_server/util/plugin/dns_plugin.sh | 94 ++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100755 pandora_server/util/plugin/dns_plugin.sh diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 47f0e3892d..f20ca3170e 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2010-05-11 Sancho Lerena + + * util/dns_plugin.sh: New DNS plugin for the Plugin Server. It + checks a Domain/IP pair and also get time to get response from + a given DNS server (ms). + 2010-05-10 Ramon Novoa * lib/PandoraFMS/Core.pm: Made cascade protection recursive to diff --git a/pandora_server/util/plugin/dns_plugin.sh b/pandora_server/util/plugin/dns_plugin.sh new file mode 100755 index 0000000000..6ec4de874e --- /dev/null +++ b/pandora_server/util/plugin/dns_plugin.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# DNS Plugin Pandora FMS Server plugin +# (c) Antonio Delgado, Sancho Lerena 2010 + +# Hint: Use this DNS servers as reference: +# Google: 8.8.8.8 +# Telefonica: 194.179.1.101 + +function help { + echo -e "DNS Plugin for Pandora FMS Plugin server. http://pandorafms.com" + echo " " + echo "This plugin is used to check if a specific domain return a specific IP " + echo -e "address, and to check how time (milisecs) takes the DNS to answer. \n" + echo -e "Syntax:" + echo -e "\t\t-d domain to check" + echo -e "\t\t-i IP address to check with domain" + echo -e "\t\t-s DNS Server to check" + echo -e "\t\t-t Do a DNS time response check instead DNS resolve test" + echo -e "Samples:" + echo " ./dns_plugin.sh -d artica.es -i 69.163.176.17 -s 8.8.8.8" + echo " ./dns_plugin.sh -d artica.es -t -s 8.8.8.8" + echo "" + exit +} + +if [ $# -eq 0 ] +then + help +fi + +TIMEOUT_CHECK=0 +DOMAIN_CHECK="" +IP_CHECK="" +DNS_CHECK="" + +# Main parsing code +while getopts ":htd:i:s:" optname + do + case "$optname" in + "h") + help + ;; + "d") + DOMAIN_CHECK=$OPTARG + ;; + "t") + TIMEOUT_CHECK=1 + ;; + "i") + IP_CHECK=$OPTARG + ;; + "s") + DNS_CHECK=$OPTARG + ;; + + ?) + help + ;; + default) + help + ;; + + esac +done + +if [ -z "$DNS_CHECK" ] +then + help +fi + +TMPFILE=/tmp/dns_$DNS_CHECK.tmp + +dig @$DNS_CHECK $DOMAIN_CHECK > $TMPFILE +RETURN_IP=`cat $TMPFILE | grep "^$DOMAIN_CHECK" | awk '{print $5}'` +RETURN_TIMEOUT=`cat $TMPFILE | grep "Query time" | grep -o "[0-9]*"` + + rm $TMPFILE 2> /dev/null + +if [ $TIMEOUT_CHECK == 1 ] +then + echo $RETURN_TIMEOUT + exit 0 +fi + +if [ "$RETURN_IP" != "$IP_CHECK" ] +then + echo 0 + exit 1 +else + echo 1 + exit 0 +fi + +