Skip to content

Instantly share code, notes, and snippets.

@nabakdev
Last active August 30, 2023 09:48
Show Gist options
  • Save nabakdev/658f6c1d210b533712c4da5d9b2b98df to your computer and use it in GitHub Desktop.
Save nabakdev/658f6c1d210b533712c4da5d9b2b98df to your computer and use it in GitHub Desktop.
mikrotik router OS script monitoring via telegram BOT
:local apiToken "xxx"
:local chatId "xxx"
:local pingit "10.10.10.1"
:local count 30
# ojo diganti
:local avgRtt;
:local pin
:local pout
:local datetime "$[/system clock get time]"
/tool flood-ping interval=1 count=$count $pingit do={
:if ( $sent = count ) do={
:set avgRtt $"avg-rtt"
:set pout $sent
:set pin $received
}
}
:local ploss (100 - (($pin * 100) / $pout))
if ( $ploss > 5 ) do={
:local msg ("$datetime - ".[:tostr $avgRtt]."ms - ".[:tostr $ploss]."%")
:log info $msg
delay 1
:tool fetch url="https://api.telegram.org/$apiToken/sendMessage?chat_id=$chatId&text=$msg" keep-result=no
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment