Mikrotik Bandwidth test scriptting

hi everyone
i am new at mikrotik scripting

i have a problem for this script. CODE 1 script is working well it sends telegram message to me but i am tying to convert this code if bandwidth test result lower then 7 send message to me if not dont send any message. i tried in CODE 2 but it doesnt work. can u have any ideas for this

Thanx for your help

CODE1


:local rxta
:local rxtaA
:local rxtaB
:local rxtaC
/tool bandwidth-test 5.5.5.1 protocol=tcp direction=receive duration=10s user=cemil.bakir@mernet password=cemil.bakir do={
:set rxtaA ($“rx-total-average” / 1000)
:set rxtaB ($rxtaA / 1000 * 1000)
:set rxtaC ($rxtaA - $rxtaB)
:set rxtaB ($rxtaB / 1000)
:set rxta “$rxtaB.$rxraC”
/tool fetch keep-result=no url="https://api.telegram.org/xxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=813083613&text=MERNET-TEPE-GURE-AP-MUSTERI-TEST $rxta Mbps "


CODE 2

:local rxta
:local rxtaA
:local rxtaB
:local rxtaC
/tool bandwidth-test 5.5.5.1 protocol=tcp direction=receive duration=10s user=cemil.bakir@mernet password=cemil.bakir do={
:set rxtaA ($“rx-total-average” / 1000)
:set rxtaB ($rxtaA / 1000 * 1000)
:set rxtaC ($rxtaA - $rxtaB)
:set rxtaB ($rxtaB / 1000)
:set rxta “$rxtaB.$rxraC”
:set hiz “8”


:if ($rxta!<= ($hiz) do={
/tool fetch keep-result=no url="https://api.telegram.org/xxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=813083613&text=MERNET-TEPE-GURE-AP-MUSTERI-TEST $rxta Mbps "
}

You can try to use logic

:if ($rxta < "7") do={

and remove variables “hiz”

no :frowning:
it does not work

do ypu have any idea someone?

:local rxta
:local rxtaA
:local rxtaB
:local rxtaC
/tool bandwidth-test 192.168.5.1  protocol=udp direction=both duration=10s user=admin password=kuningan do={
:set rxtaA ($"rx-total-average" / 1000)
:set rxtaB ($rxtaA / 1000 * 1000)
:set rxtaC ($rxtaA - $rxtaB)
:set rxtaB ($rxtaB / 1000)
:set rxta "$rxtaB.$rxtaC"
}

:if ($rxta <= "7") do={
/tool fetch url="https://api.telegram.org/botXXXXXXXXXX/sendMessage?chat_id=XXXXXXXXXXX&text=$rxta Mbps" keep-result=no
}

try it using received and send but it doesn’t work, but using both of them works

I don’t know why this isn’t received and send

there is an error in the variable so this doesn’t work $ rxcaC should be $ rxtaC

I record result’s of Bandwidth Test into logs, your script’s was convert into function and now is perfect.
The scheduler do every x time the “Bandwidth Test” via duration=15s and grab rx/tx-10-second-average data what is write into log’s like this:

by script:

local speedtest [tool bandwidth-test [:resolve btserver.domain.tld] protocol=tcp user=btest password=******* direction=both duration=15s as-value ] ;

local MyFuncDataToMKbps do={
local DataOriginal $1
set DataOriginal ($DataOriginal / 1000)
local Mbps ($DataOriginal / 1000 * 1000)
local Kbps ($DataOriginal - $Mbps)
set Mbps ($Mbps / 1000)
return ($Mbps."M ".$Kbps."K - bps")
}

local Rx [$MyFuncDataToMKbps ($speedtest->"rx-10-second-average")]
local Tx [$MyFuncDataToMKbps ($speedtest->"tx-10-second-average")]
local Time ([/system clock get date]." ".[/system clock get time])
put "$Time | Rx: $Rx | Tx: $Tx"
log warning "$Time | Rx: $Rx | Tx: $Tx"

I can easy display filtred results in CLI / Terminal via

/log print where message~" - bps "

thanx for your message but my first code is doing same thing too. i wanna do if bandwidth test result lower then 7 send message to me if not dont send any message

cumhureren

But this is so easy, at the end of my script I receive in $Rx the “18M 200K …” then i select first numbers and compare them, add this at the end of my script:

local DLMb [pick $Rx 0 [:find $Rx "M"]]
if ($DLMb < 7) do={/tool fetch keep-result=no url="https://api.telegram.org/xxxxxxxxxxxxx: ... STERI-TEST $Rx "}

thank you my friend it worked..