With this script in place in all our CPE's it will decide what is the correct IP address to continue pinging to know it has a connection to the tower and update the netwatch to reflect that. One less thing we have to set in our config script. The only settings we place in the CPE during installation now is the tower or sector name and the customer name.
Yes this script assumes that the WLAN1 connection is the gateway to the net and it gets a DHCP address assigned to it. If you want to use this on a router that uses an Ethernet port as the gateway, change the second line of the script to get the interface you want.
Thought that someone else may find this useful. Use this as is or customize it as needed.
Netwatch Settings:
Code: Select all
/tool netwatch
add down-script="log info \"Netwatch missed a ping - starting timeout au\
to reboot script\" ; /system script run NetWatchBoot" host=10.0.0.1 \
interval=30s timeout=2s
Code: Select all
/system script
add name=NetWatchBoot owner=admin policy=ftp,reboot,read,write,policy,\
test,password,sniff,sensitive source=":local addresstoping [tool netwatch get 0 host];\
\n:local interface [interface wireless get [ find default-name=wlan1 ] name ];\
\n#\
\n:local continue true;\
\n:local counter 0;\
\n:local maxcounter 18;\
\n:local sleepseconds 10;\
\n:local goodpings 0;\
\n:log error \"-----> Netwatch-Script-Warning - Netwatch could not ping \$\
addresstoping - Will begin further testing in \$sleepseconds seconds - and\
\_will continue for \$maxcounter times \$sleepseconds seconds\";\
\n:while (\$continue) do={\
\n:set counter (\$counter + 1);\
\n:delay \$sleepseconds;\
\n:if ([/ping \$addresstoping interval=1 count=1] =0) do={\
\n:log info \"----->ping to \$addresstoping failed on attempt \$counter of\
\_\$maxcounter -- Will try again in \$sleepseconds seconds\";\
\n} else {\
\n:log warning \"-----> ping success to \$addresstoping attempt \$count\
er of \$maxcounter <----- No Further testing needed --- Program will exit \
-----\";\
\n:set continue false;\
\n:set goodpings (\$goodpings +1);\
\n/interface wireless monitor \$interface once without-paging do={\
\n:local status \$\"status\";\
\n:local noise \$\"noise-floor\";\
\n:log info \"-----> Status: \$status --- NoiseFloor: \$noise\";\
\n/interface wireless monitor \$interface once\
\n:local txr \$\"tx-rate\";\
\n:local rxr \$\"rx-rate\";\
\n:local sstr \$\"signal-strength\";\
\n:local signoise \$\"signal-to-noise\";\
\n:local txccq \$\"tx-ccq\";\
\n:local rxccq \$\"rx-ccq\";\
\n:log info \"-----> TxRate: \$txr --- RxRate: \$rxr --- SignalStreng: \$s\
str --- SignalToNoise: \$signoise --- TxCcq: \$txccq --- RxCcq: \$rxccq\"\
;\
\n};\
\n}\
\n:if (\$counter=\$maxcounter) do={:set continue false;}\
\n}\
\n:local addressforping [ip dhcp-client get [find interface=$interface \
] gateway ];\
\n:if (\$addresstoping = \$addressforping ) do= {\
\n:delay 1;\
\n} else {\
\n:log error \"-----> Changed netwatch address to \$addressforping\";\
\n/tool netwatch set 0 host=\$addressforping\
\n}\
\n:if (\$\"goodpings\" = 0 ) do={\
\n:log info \"-----> Rebooting in 15 seconds\";\
\n:delay 5;\
\n/file print file=ScriptRebootReason\
\n/file set ScriptRebootReason.txt contents=\"Rebooted by script on \$[/sy\
stem clock get date] at \$[/system clock get time]\"\
\n:log error \"-----> Rebooting in 10 seconds\";\
\n:delay 5;\
\n:log error \"-----> Rebooting in 5 seconds\";\
\n:delay 5;\
\n:log error \"-----> Rebooting now\";\
\n:delay 1;\
\n/system reboot\
\n/system reboot\
\n/system reboot\
\n/system reboot\
\n}\
\n"