Skip to content

Instantly share code, notes, and snippets.

@epcim
Last active May 18, 2021 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save epcim/09f058f5d62b9eabd41ab61a5d5310f4 to your computer and use it in GitHub Desktop.
Save epcim/09f058f5d62b9eabd41ab61a5d5310f4 to your computer and use it in GitHub Desktop.

script examples

https://mikrotik.com/testdocs/ros/2.8/appex/scripting1.php https://www.mikrotik-routeros.com/2010/12/simple-routeros-http-loadbandwidth-tester/

btest /tools /bandwith-server

TBD

https://forum.mikrotik.com/viewtopic.php?f=2&t=104266&p=645201#p645201

ping

/ping size=1400 address=root.cz

test upload/download

[admin@mt-test] /tool> fetch address=192.168.88.2 src-path=conf.rsc \
user=admin mode=ftp password=123 dst-path=123.rsc upload=yes

Another file download example that demonstrates the usage of url property.

[admin@test_host] /> /tool fetch url="http://www.mikrotik.com/img/netaddresses2.pdf" mode=http 
  status: finished

[admin@test_host] /> /file print 
 # NAME                     TYPE                  SIZE                 CREATION-TIME       
 ...
 5 netaddresses2.pdf        .pdf file             11547                jun/01/2010 11:59:51

Sending information to a remote host
It is possible to use HTTP POST request to send information to a remote server, that is prepared to accept it. In the following example, we send geographic coordinates to a PHP page:

/tool fetch http-method=post http-content-type="application/json" http-data="{\"lat\":\"56.12\",\"lon\":\"25.12\"}" url="http://testserver.lv/index.php"              

notify on issue

:local sysname [/system identity get name]
:local CurDate [/system clock get date] 
:local CurTime [/system clock get time] 
:local Interface "Interface_Name"
:local LinkName "Link_Description"
:local ifspeed "GET_DESIRED_INTERFACE_SPEED"

#Email
/tool e-mail send to="YourEmail@email.com" subject="$StatusTraffic speed is more then $DSpeed at $CurTime $CurDate" body="Device : $sysname 
Date : $CurDate 
Time : $CurTime 

conditions

/interface ethernet monitor ether2 once do={
 :if ($"status" != "link-ok") do={ :log info "ether2 is WITHOUT LINK"};
 :if ($"auto-negotiation" != "done") do={ :log info "ether2 auto-negotiation NOT WORKING"};
 :if ($"rate" != "100Mbps") do={ :log info "ether2 is NOT 100Mbps"};
 :if ($"full-duplex" = "no") do={ :log info "ether2 is NOT Full-Duplex"};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment