Ad Widget

Collapse

net.tcp.dns.query doesn't support SRV records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frater
    Senior Member
    • Oct 2010
    • 340

    #1

    net.tcp.dns.query doesn't support SRV records

    I wanted to monitor some SRV-records of a foreign SIP-provider and found out that the native function net.tcp.dns.query doesn't support them.
    Creating a trigger that will give an alert also didn't work out because the answer is not always given in the same order when it resolves to more than 1 IP.

    That's why I created this quick-and-dirty alternative where the output gets sorted and the first field where it repeats the DNS-name gets cut. I implemented that latest part because it enables me to create a trigger that does a comparison of 2 different domains.


    Code:
    UserParameter=net.dns.query[*],/usr/local/sbin/dnsquery "$1" "$2" "$3"
    UserParameter=net.dns.query.cksum[*],/usr/local/sbin/dnsquery "$1" "$2" "$3" | md5sum | tr -cd 0-9 | cut -b1-10
    Code:
    SRV-record sip.dom1.com is not the same as sip.dom2.com
    {Zabbix server:net.dns.query.cksum[, "_sip._udp.sip.dom1.com", "SRV"].last(0)}#{Zabbix server:net.dns.query.cksum[, "_sip._udp.sip.dom2.com", "SRV"].last(0)}
    Code:
    SRV-record sip.dom1.com has changed
    {Zabbix server:net.dns.query[, "_sip._udp.sip.dom1.com", "SRV"].diff(0)}=1
    Code:
    #!/bin/bash
    #####################################################
    # dnsquery
    #####################################################
    #
    # echo 'UserParameter=net.dns.query[*],/usr/local/sbin/dnsquery "$1" "$2" "$3"' >>/etc/zabbix/zabbix_agentd.conf
    #
    # echo 'UserParameter=net.dns.query.cksum[*],/usr/local/sbin/dnsquery "$1" "$2" "$3"' >>/etc/zabbix/zabbix_agentd.conf
    #####################################################
    export PATH=${PATH}:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin
    
    IP=$1
    RAWZONE=$2
    TYPE=$3
    WAIT=4
    
    [ -z "${RAWZONE}" ] && exit 1
    ZONE="`echo "${RAWZONE}" | grep '\.' | grep '[A-Za-z0-9.-]*'`"
    [ "${RAWZONE}" = "${ZONE}" ] || exit 1
    
    if [ ! -z "${IP}" ] ; then
      if ! echo "${IP}" | grep -qE '^([0-9]{1,3}\.){3}[0-9]{1,3}$' ; then
        exit 1
      fi
    fi
    
    [ -z "$TYPE" ] && TYPE=A
    
    ftmp1=`mktemp`
    host -W${WAIT} -t${TYPE} ${ZONE} ${IP} 2>/dev/null >${ftmp1}
    ERRNO=$?
    
    [ $ERRNO -gt 1 ] && exit 1
    if [ $ERRNO -eq 0 ] ; then
      sort ${ftmp1} | cut -d' ' -f2-
    else
      cat ${ftmp1}
    fi
    rm -f ${ftmp1}
    Last edited by frater; 24-01-2011, 13:30.
    Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP
Working...