Skip to content
Snippets Groups Projects
Select Git revision
  • bb852ad8b97d592c767f2c4ad155414862ae3368
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_couchdb-lb

Blame
  • check_dns_responsetime 2.06 KiB
    #!/bin/bash
    # ======================================================================
    #
    # Check DNS response time
    # requirements:
    # - netstat
    #
    # ----------------------------------------------------------------------
    # 2020-06-17  v1.0  <axel.hahn@iml.unibe.ch>
    # ======================================================================
    
    
    . `dirname $0`/inc_pluginfunctions
    tmpfile=/tmp/check_netstat_out_$$
    infofile=/tmp/check_netstat_out_2_$$
    myHost=www.unibe.ch
    
    
    # ----------------------------------------------------------------------
    # MAIN
    # ----------------------------------------------------------------------
    
    
    # --- check param -h
    if [ "$1" = "-h" ]; then
        echo "
        usage: $0 [ -w value -c value -h ]
    
            -w  Warning level
            -c  Critical level
            -h  this help
        "
        exit 0
    fi
    
    # set default / override from command line params
    typeset -i iWarnLimit=`     ph.getValueWithParam  300 w "$@"`
    typeset -i iCriticalLimit=` ph.getValueWithParam 1000 c "$@"`
    
    rm -f $tmpfile $infofile 2>/dev/null
    
    typeset -i iMax=0
    typeset -i iTime=0
    
    for mydns in `grep ^nameserver /etc/resolv.conf | awk '{ print $2 } ' `
    do
        typeset -i iSrvMax=0
        echo "" >>$infofile
    
        # echo "---------- `date` $mydns " >>$infofile
        # todo loop
        for i in `seq 5`
        do
            # echo "" >>$infofile
            # echo "---------- `date` -- $mydns - $i" >>$infofile
            (time nslookup ${myHost} $mydns) >$tmpfile 2>&1
    
            iTime=`cat $tmpfile | grep "^real.*m.*\..*s" | cut -f 2 -d "m" | sed "s#[\.s]##g" | sed "s#^0*##g" `
            echo "$mydns #$i >>> $iTime ms" >>$infofile
            test $iTime -ge $iWarnLimit && cat $tmpfile >> $infofile
    
            test $iTime -gt $iSrvMax && iSrvMax=$iTime
        done
    
        label=`echo $mydns | sed "s#\.#-#g" `
        ph.perfadd "response-$label" "${iSrvMax}"
        test $iSrvMax -gt $iMax && iMax=$iSrvMax
    done
    
    # --- set status
    ph.setStatusByLimit $iMax $iWarnLimit $iCriticalLimit
    
    ph.status "DNS check - found maximum was $iMax ms"
    cat $infofile
    
    rm -f $tmpfile $infofile
    
    
    ph.exit
    
    # ----------------------------------------------------------------------