Community discussions

MikroTik App
 
User avatar
jspool
Member
Member
Topic Author
Posts: 469
Joined: Sun Oct 04, 2009 4:06 am
Location: Oregon

Fetch Status

Thu Nov 03, 2011 9:29 pm

I am looking for a way to enable or disable a firewall rule depending on a successful or failed tool fetch.

When I run the tool fetch itself from the terminal I see the status: finished or status:failed response. Is there a way to get this data and use it as the trigger to enable or disable the desired firewall rule.



Thanks
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Fetch Status

Fri Nov 04, 2011 9:05 am

you can put output of fetch into variable and then pick part of it and do comparison.
 
ManyX
Member Candidate
Member Candidate
Posts: 111
Joined: Sat Jan 07, 2006 12:48 pm
Location: PolanD

Re: Fetch Status

Wed May 30, 2012 4:23 pm

how can I put?
How can I do that?
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Fetch Status

Wed May 30, 2012 9:46 pm

 
ManyX
Member Candidate
Member Candidate
Posts: 111
Joined: Sat Jan 07, 2006 12:48 pm
Location: PolanD

Re: Fetch Status

Thu May 31, 2012 12:33 am

you can put output of fetch into variable and then pick part of it and do comparison.
how I can put output od fetch into variable
I want check status od fetch
(status: finished)
and then continue my script

reg.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Fetch Status

Thu May 31, 2012 2:04 am

function "get status" is required
 
ManyX
Member Candidate
Member Candidate
Posts: 111
Joined: Sat Jan 07, 2006 12:48 pm
Location: PolanD

Re: Fetch Status

Thu May 31, 2012 12:31 pm

Perhaps some hint or example.

reg.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Fetch Status

Thu May 31, 2012 1:41 pm

Unfortunately it is not possibel to get that status. And if fetch fails script stops executing immediatly.

So only way to check if fetch succeeded or failed is run in one script fetch and then run another script which checks if fetch fetched a file to the router. If there is a file then fetch succeeded otherwise fetch failed.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Fetch Status

Thu May 31, 2012 10:35 pm

first add a sccript with
/tool fetch url="http://www.example.com/test.html" mode=http

then add other script with
:local checkpage "test.html";
:local found "0";
:foreach i in=[/file find] do={
	:local filename [/file get $i name];
	if ( $filename = $checkpage) do={ :set found "1"; :log info "found"; }
}
:log info "$found";
if ( $found = "0" ) do={ :log info "Disable rule, service down"; /ip firewall filter disable 0 } else={ :log info "Enable rule, service up"; /ip firewall filter enable 0; }
/file remove $checkpage;
from http://gregsowell.com/?p=3329
 
User avatar
omidkosari
Trainer
Trainer
Posts: 640
Joined: Fri Sep 01, 2006 4:18 pm
Location: Canada, Toronto

Re: Fetch Status

Sun Sep 30, 2012 11:02 pm

1. what if the router could not retrieve file from proxy ? is there a way to just check the port is open ?

2. writing a file periodically may damage flash memory of router .
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7056
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Fetch Status

Mon Oct 01, 2012 10:51 am

Use keep-result=no then it will not write anything to flash.
 
User avatar
omidkosari
Trainer
Trainer
Posts: 640
Joined: Fri Sep 01, 2006 4:18 pm
Location: Canada, Toronto

Re: Fetch Status

Mon Oct 01, 2012 2:28 pm

Then how we check the file is downloaded or not ?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Fetch Status

Mon Oct 01, 2012 2:34 pm

see status message.
 
mahdideveloepr
just joined
Posts: 4
Joined: Sun Sep 30, 2012 4:36 pm

Re: Fetch Status

Mon Oct 01, 2012 2:59 pm

how we use this status message in script when the status is failed my script finished
:global myStr;
:set myStr  [ /tool fetch url="http://xxx.xxx.xxx.xxx/index.html/" port=3128  mode=http  keep-result=no ];
:if ( :put [:len $myStr] != 0 ) do={ :put "(port close)"}
:if ( :put [:len $myStr] = 0 ) do={ :put "(port open)"} 
when a file downloaded status not finish myStr length return 0
but when file not downloaded or port is closed script finish and nothing return and exit script done
please help how I can receive open port message without download a page
 
User avatar
omidkosari
Trainer
Trainer
Posts: 640
Joined: Fri Sep 01, 2006 4:18 pm
Location: Canada, Toronto

Re: Fetch Status

Mon Oct 01, 2012 3:08 pm

With scripting can we read the status massage ?
 
mahdideveloepr
just joined
Posts: 4
Joined: Sun Sep 30, 2012 4:36 pm

Re: Fetch Status

Mon Oct 01, 2012 3:24 pm

yes I want to store output in my variable
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Fetch Status

Mon Oct 01, 2012 3:26 pm

not possible to store result or downloaded file into variable. Maybe future RouterOS versions will have that capability, but currently it is not possible and there is no time-frame when it could become available.
 
mahdideveloepr
just joined
Posts: 4
Joined: Sun Sep 30, 2012 4:36 pm

Re: Fetch Status

Mon Oct 01, 2012 3:57 pm

not possible to store result or downloaded file into variable. Maybe future RouterOS versions will have that capability, but currently it is not possible and there is no time-frame when it could become available.
please guide me to check port with script and run command after check it
thank u janisk

Who is online

Users browsing this forum: rextended and 8 guests