Community discussions

MikroTik App
 
imadsani
newbie
Topic Author
Posts: 26
Joined: Mon Jun 24, 2013 4:06 pm

using /tool fetch to create a connection check script

Wed Nov 12, 2014 9:41 am

Following up on a recent thread that the simple netwatch is not enough for me to verify if my internet connections are working, I stumbled upon /tool fetch. I wonder if I can create a script to download a file from my servers to verify whether the connections are working.

Hurdles I've encountered so far, i cannot find a way to restrict the interface from which to run fetch, second I can't seem to figure out how to judge success or failure while in a script.

Any help would be greatly appreciated.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: using /tool fetch to create a connection check script

Wed Nov 12, 2014 4:37 pm

fetch will always follow routing path to get to host to download/upload files. So, using this you can only check if router has any connectivity.
 
User avatar
rgraham
Frequent Visitor
Frequent Visitor
Posts: 60
Joined: Thu May 05, 2005 10:50 pm
Location: USA Minneapolis, Minnesota

Re: using /tool fetch to create a connection check script

Mon Feb 23, 2015 5:14 am

To determine success or failure of fetch, use :do { } on-error={ } ; Instead of the script stopping, it continues if fetch fails.
This is a sample of my program the sends all the files to an FTP server to back them up.

:set ftpresults "Sucessful"
:do { /tool fetch address=$ftpserver port=$ftpport src-path=$locfilename upload=yes user=$ftpuser mode=ftp password=$ftppw dst-path=$remfilename keep-result=yes } \
on-error={ :set failcount ( $failcount + 1 ) ; :set ftpresults "Failed"; }
 
User avatar
otgooneo
Trainer
Trainer
Posts: 581
Joined: Tue Dec 01, 2009 3:24 am
Location: Mongolia
Contact:

Re: using /tool fetch to create a connection check script

Tue Aug 15, 2017 5:47 am

Good guidance
 
User avatar
otgooneo
Trainer
Trainer
Posts: 581
Joined: Tue Dec 01, 2009 3:24 am
Location: Mongolia
Contact:

Re: using /tool fetch to create a connection check script

Tue Aug 15, 2017 5:58 am

I`m wondering possibility of routeros if I use HTTP POST to interact with 3rd party system instead of API, because routeros can`t call 3rd party API. In other word, 3rd party web server will hear http post to get information from routeros. Routeros will POST queue stats over http to this web server. Server side it`s ok to handle thousands of POST requests in seconds but how about routeros. How many simultaneous http post can routeros handle? Does any one have such experience?
 
User avatar
otgooneo
Trainer
Trainer
Posts: 581
Joined: Tue Dec 01, 2009 3:24 am
Location: Mongolia
Contact:

Re: using /tool fetch to create a connection check script

Tue Aug 15, 2017 7:19 am

I just tested http post. please see below.
I sent 100 post request with one shot using script
/tool fetch http-method=post port=80 keep-result=no url="http://posttestserver.com/post.php?dir=otgoo_2" http-data=otg1
But all 100 requests take 2 minutes to complete. I included log command at the start and end of the script.
:log info "post_starts";
:log info "post_ends";
You can that it took almost minutes.
12:00:21 script,info post_starts 
12:02:01 script,info post_ends
Delay from my router to server is ~279ms. Bandwidth is really enough. This small post requests take only few kbps. When do fetch, CPU was max 1% on fetcher process. Router is hap ac (720 MHz). Memory was always 99MB free out of 128MB.
What can be the possible bottleneck?

Who is online

Users browsing this forum: No registered users and 67 guests