Skip to content
Snippets Groups Projects

dns_response - shell fixes; remove pipe in output

Merged Hahn Axel (hahn) requested to merge 5823-grep-regex-with-spaces into master
1 file
+ 8
7
Compare changes
  • Side-by-side
  • Inline
+ 8
7
@@ -10,10 +10,11 @@
@@ -10,10 +10,11 @@
# 2021-11-12 v1.1 <axel.hahn@iml.unibe.ch> check fqd instead of fixed value
# 2021-11-12 v1.1 <axel.hahn@iml.unibe.ch> check fqd instead of fixed value
# test tcp 53 first
# test tcp 53 first
# check result depends on 1st nameserver only
# check result depends on 1st nameserver only
 
# 2022-10-24 v1.2 <axel.hahn@unibe.ch> shell fixes; remove pipe char in output
# ======================================================================
# ======================================================================
. `dirname $0`/inc_pluginfunctions
. $(dirname $0)/inc_pluginfunctions
tmpfile=/tmp/check_netstat_out_$$
tmpfile=/tmp/check_netstat_out_$$
infofile=/tmp/check_netstat_out_2_$$
infofile=/tmp/check_netstat_out_2_$$
myHost=$( hostname -f )
myHost=$( hostname -f )
@@ -26,8 +27,8 @@ if [ $? -ne 0 ]; then
@@ -26,8 +27,8 @@ if [ $? -ne 0 ]; then
fi
fi
# set default / override from command line params
# set default / override from command line params
typeset -i iWarnLimit=` ph.getValueWithParam 300 w "$@"`
typeset -i iWarnLimit=$( ph.getValueWithParam 300 w "$@")
typeset -i iCriticalLimit=` ph.getValueWithParam 1000 c "$@"`
typeset -i iCriticalLimit=$( ph.getValueWithParam 1000 c "$@")
rm -f $tmpfile $infofile 2>/dev/null
rm -f $tmpfile $infofile 2>/dev/null
@@ -54,7 +55,7 @@ if [ "$1" = "-h" ]; then
@@ -54,7 +55,7 @@ if [ "$1" = "-h" ]; then
exit 0
exit 0
fi
fi
for mydns in `grep ^nameserver /etc/resolv.conf | awk '{ print $2 } ' `
for mydns in $(grep ^nameserver /etc/resolv.conf | awk '{ print $2 } ' )
do
do
iCounter=$iCounter+1
iCounter=$iCounter+1
typeset -i iSrvMax=0
typeset -i iSrvMax=0
@@ -72,7 +73,7 @@ do
@@ -72,7 +73,7 @@ do
do
do
(time nslookup ${myHost} $mydns) >$tmpfile 2>&1
(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" `
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
echo "$mydns #$i >>> $iTime ms" >>$infofile
test $iTime -ge $iWarnLimit && cat $tmpfile | grep -vE "^(real|user|sys)" >> $infofile
test $iTime -ge $iWarnLimit && cat $tmpfile | grep -vE "^(real|user|sys)" >> $infofile
test $iTime -gt $iSrvMax && iSrvMax=$iTime
test $iTime -gt $iSrvMax && iSrvMax=$iTime
@@ -83,11 +84,11 @@ do
@@ -83,11 +84,11 @@ do
# --- set status
# --- set status
test $iCounter -eq 1 && ph.setStatusByLimit $iSrvMax $iWarnLimit $iCriticalLimit
test $iCounter -eq 1 && ph.setStatusByLimit $iSrvMax $iWarnLimit $iCriticalLimit
label=`echo $mydns | sed "s#\.#-#g" `
label=$(echo $mydns | sed "s#\.#-#g" )
ph.perfadd "response-$label" "${iSrvMax}"
ph.perfadd "response-$label" "${iSrvMax}"
test $iSrvMax -gt $iMax && iMax=$iSrvMax
test $iSrvMax -gt $iMax && iMax=$iSrvMax
fi
fi
test $iCounter -eq 1 && (echo " ^"; echo " |"; echo " +--- 1st nameserver is relevant for total status of the check. Limits are warning=$iWarnLimit and critical=$iCriticalLimit") >>$infofile
test $iCounter -eq 1 && (echo " ^"; echo " :"; echo " +--- 1st nameserver is relevant for total status of the check. Limits are warning=$iWarnLimit and critical=$iCriticalLimit") >>$infofile
echo "" >>$infofile
echo "" >>$infofile
done
done
Loading