{ :global mailAddrTo "yourmail@dom.ru"; :global mailAddrCopy "yourbackupmail@dom2.com"; :global sec 3; :local cnt 10; :local cntOkRes 1; :local host1 ya.ru; :local host2 8.8.8.8; :global cpu100 0; for x1 from=1 to=$sec do={ :if ( [/system resource get cpu-load]="1") do={ :global cpu100 ($cpu100+1); } :delay 1; } :if ( $cpu100 = $sec ) do={ /tool e-mail send to=$mailAddrTo cc=$mailAddrCopy body="Within $sec seconds, CPU load on Mikrotik was 100%. Mikrotik will be restarted!" subject="$[/system identity get name]. Mikrotik CPU load was 100% on $[/system clock get time] $[/system clock get date]" :delay 20; /system reboot; } if ([/ip route find where dst-address=0.0.0.0/0] = "") do={ :log warning "No default gateway! USB port will be power cycled!"; /system routerboard usb power-reset duration=5s :delay 25; } :local defGw [/ip route get [/ip route find where dst-address=0.0.0.0/0] gateway]; :global ifName [/ip address get [/ip address find where network=$defGw] interface]; :global wanTrafTx "0"; :global wanTrafTxRes "0"; :global wanTrafRx "0"; :global wanTrafRxRes "0"; for x from=1 to=5 do={ /interface monitor-traffic [/interface find name=$ifName] once do={ :global wanTrafTx (tx-bits-per-second / 1024); } /interface monitor-traffic [/interface find name=$ifName] once do={ :global wanTrafRx (rx-bits-per-second / 1024); } if ($wanTrafTx > $wanTrafTxRes) do={ :global wanTrafTxRes $wanTrafTx; } if ($wanTrafRx > $wanTrafRxRes) do={ :global wanTrafRxRes $wanTrafRx; } :delay 1; } if ($wanTrafTxRes < 30000 and $wanTrafRxRes < 30000) do={ :local cntRes1 [/ping count=$cnt $host1]; :local cntRes2 [/ping count=$cnt $host2]; if ($cntRes1 < $cntOkRes and $cntRes2 < $cntOkRes) do={ :local logmsg ("Internet connection fail! \n\nCPU Load: ".[/system resource get cpu-load]."% \nWAN speed RX: ".[:tonum $wanTrafRxRes]." kbit/s \nWAN speed TX: ".[:tonum $wanTrafTxRes]." kbit/s \nHost - ".[:tostr $host1]." lost ".[:tonum $cnt] - [:tonum $cntRes1]." packets of ".[:tostr $cnt]." \nHost - ".[:tostr $host2]." lost ".[:tonum $cnt] - [:tonum $cntRes2]." packets of ".[:tostr $cnt]."\n"); :log info $logmsg; /interface ppp-client disable [/interface ppp-client find name=$ifName]; :delay 10; execute "/system script run \"modemStatus\""; :delay 5s; :global modemStatus; /interface ppp-client enable [/interface ppp-client find name=$ifName]; :delay 20; /tool e-mail send to=$mailAddrTo cc=$mailAddrCopy body="$logmsg$modemStatus" subject="$[/system identity get name]. Internet connection fails! $[/system clock get time] $[/system clock get date]" } } }