Community discussions

MikroTik App
 
cumhureren
just joined
Topic Author
Posts: 5
Joined: Wed Jan 22, 2020 1:29 pm

Mikrotik Bandwidth test scriptting

Wed Jan 22, 2020 1:37 pm

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: ... STERI-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: ... STERI-TEST $rxta Mbps "
}
 
sopyan0807
newbie
Posts: 40
Joined: Wed Jan 22, 2020 5:21 pm
Location: Indonesia
Contact:

Re: Mikrotik Bandwidth test scriptting

Sun Jan 26, 2020 11:52 am

You can try to use logic
:if ($rxta < "7") do={
and remove variables "hiz"
 
cumhureren
just joined
Topic Author
Posts: 5
Joined: Wed Jan 22, 2020 1:29 pm

Re: Mikrotik Bandwidth test scriptting

Sat Feb 15, 2020 11:14 am

no :(
it does not work

do ypu have any idea someone?
 
sopyan0807
newbie
Posts: 40
Joined: Wed Jan 22, 2020 5:21 pm
Location: Indonesia
Contact:

Re: Mikrotik Bandwidth test scriptting

Sat Feb 22, 2020 3:43 pm

: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
 
User avatar
SiB
Forum Veteran
Forum Veteran
Posts: 858
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: Mikrotik Bandwidth test scriptting

Mon Mar 02, 2020 4:21 am

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:
Image

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 "
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL
WinBox Tip: F6 works as ALT+TAB | Gliffy.com - free network schematic | prnt.sc - free ScreenShot software
I will be at MUMEUROPE Prague on ?? ?? 202?
 
cumhureren
just joined
Topic Author
Posts: 5
Joined: Wed Jan 22, 2020 1:29 pm

Re: Mikrotik Bandwidth test scriptting

Tue May 12, 2020 10:17 am

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:
Image

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
 
User avatar
SiB
Forum Veteran
Forum Veteran
Posts: 858
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: Mikrotik Bandwidth test scriptting

Thu May 14, 2020 1:35 am

cumhureren
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
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 "}
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL
WinBox Tip: F6 works as ALT+TAB | Gliffy.com - free network schematic | prnt.sc - free ScreenShot software
I will be at MUMEUROPE Prague on ?? ?? 202?
 
cumhureren
just joined
Topic Author
Posts: 5
Joined: Wed Jan 22, 2020 1:29 pm

Re: Mikrotik Bandwidth test scriptting

Wed May 20, 2020 12:56 pm

cumhureren
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
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..

Who is online

Users browsing this forum: No registered users and 19 guests