mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-12 03:58:34 +01:00
67 lines
1.9 KiB
Bash
67 lines
1.9 KiB
Bash
#!/bin/sh
|
|
# Copyright (C) 2019 iopsys Software Solutions AB
|
|
# Author: AMIN Ben Ramdhane <amin.benramdhane@pivasoftware.com>
|
|
|
|
|
|
UCI_CONFIG_DIR="/etc/config/"
|
|
UCI_GET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get"
|
|
UCI_SET_VARSTATE="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set"
|
|
LOG_FILE="/tmp/nslookup.log"
|
|
|
|
nslookup_get() {
|
|
local val=`$UCI_GET_VARSTATE $1`
|
|
echo ${val:-$2}
|
|
}
|
|
|
|
nslookup_launch() {
|
|
local i time1 time2 timeresponse
|
|
[ "`$UCI_GET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState`" != "Requested" ] && return
|
|
local hostname=`nslookup_get cwmp.@nslookupdiagnostic[0].HostName`
|
|
local dnsserver=`nslookup_get cwmp.@nslookupdiagnostic[0].DNSServer`
|
|
local cnt=`nslookup_get cwmp.@nslookupdiagnostic[0].NumberOfRepetitions 1`
|
|
[ "$hostname" = "" ] && return
|
|
i=0
|
|
[ -e "${LOG_FILE}" ] && rm ${LOG_FILE}
|
|
while [ $i -lt $cnt ]; do
|
|
let i++
|
|
time1=`date +%s`
|
|
if [ -z "$dnsserver" ]; then
|
|
nslookup $hostname >>${LOG_FILE} 2>&1
|
|
else
|
|
nslookup $hostname $dnsserver >>${LOG_FILE} 2>&1
|
|
fi
|
|
time2=`date +%s`
|
|
timeresponse=$(($(($time2-$time1))*1000))
|
|
echo "ResponseTime: $timeresponse" >>${LOG_FILE}
|
|
echo "***********************" >>${LOG_FILE}
|
|
done
|
|
$UCI_SET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState=Complete
|
|
event_dignostic
|
|
}
|
|
|
|
event_dignostic() {
|
|
local e=1
|
|
local i=0
|
|
while [ "$e" != 0 -a $i -lt 200 ]; do
|
|
ubus -t 1 call tr069 inform '{"event":"8 DIAGNOSTICS COMPLETE"}' &>/dev/null
|
|
e=$?
|
|
[ "$e" != "0" ] && sleep 1;
|
|
let i++
|
|
done
|
|
}
|
|
|
|
nslookup_stop_diagnostic() {
|
|
local pids=`ps | grep nslookup_launch | grep -v grep | awk '{print $1}'`
|
|
if [ -n "$pids" ]; then
|
|
kill -9 $pids &>/dev/null
|
|
$UCI_SET_VARSTATE cwmp.@nslookupdiagnostic[0].DiagnosticState=None
|
|
fi
|
|
}
|
|
|
|
if [ "$1" == "run" ]; then
|
|
nslookup_launch
|
|
elif [ "$1" == "stop" ]; then
|
|
nslookup_stop_diagnostic
|
|
else
|
|
return
|
|
fi
|