Community discussions

MikroTik App
 
ssbaksa
newbie
Topic Author
Posts: 31
Joined: Tue Oct 20, 2015 10:38 am

Fetch - How to access data variable?

Thu Apr 26, 2018 3:35 pm

How to access data variable when I use output=user?
[admin@mtTest] > /tool fetch output=

Output ::= file | none | user
none -- do not store downloaded data
user -- return up to 63k bytes directly in 'data' variable without storing on disk
file -- store to file
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Fetch - How to access data variable?

Thu Apr 26, 2018 3:51 pm

You can check /System Scripts Environment after a run how the name of the variable is, at-least if it is a global variable.
 
ssbaksa
newbie
Topic Author
Posts: 31
Joined: Tue Oct 20, 2015 10:38 am

Re: Fetch - How to access data variable?

Fri Apr 27, 2018 8:00 am

Hi,

Unfortunately it doesn't work (real IP hidden). I dknow that I can write it to file but that is not what I like and this new option (output=user) will be great if
only I can get it to work. There is no explanation for it on Wiki at this time.

[admin@mtTest] > /tool fetch mode=http url="http://api.ipify.org/" http-method=get output=user
status: finished
downloaded: 0KiBC-z pause]
total: 0KiB
duration: 1s
data: 1.2.3.4

result from variable print:

[admin@mtTest] /system script environment> print
# NAME VALUE

If I try to write to variable:

[admin@mtTest] > :global WANip [/tool fetch mode=http url="http://api.ipify.org/" http-method=get output=user]
status: finished
downloaded: 0KiBC-z pause]
total: 0KiB
duration: 1s
data: 1.2.3.4

Still no result:

[admin@mtTest] /system script environment> print
# NAME VALUE
0 WANip
 
ssbaksa
newbie
Topic Author
Posts: 31
Joined: Tue Oct 20, 2015 10:38 am

Re: Fetch - How to access data variable?

Fri May 04, 2018 11:22 am

Answer to myself. It isn't working at this time. Must wait for next release of fetch.
 
User avatar
merlinthemagic7
newbie
Posts: 47
Joined: Fri Sep 16, 2016 8:49 pm

Re: Fetch - How to access data variable?

Wed Mar 20, 2019 12:17 pm

I assume this is what you are looking for:
:local strData [ /tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]; :local arrData [ :toarray $strData ]; :local varData ( $arrData->"data" ); :put [ $varData ];
i broke out the type changes into separate variables, but obviously this can all be simplified.

if you want the status of the download:
:local strData [ /tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]; :local arrData [ :toarray $strData ]; :local varData ( $arrData->"status" ); :put [ $varData ] ;
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Fetch - How to access data variable?

Thu Mar 21, 2019 9:52 am

but obviously this can all be simplified.
Since you already have it in one line using many commands separated by ; you can do all in one go.

data
:put ([/tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]->"data")
status
:put ([/tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]->"status")
For the IP, you get an enter extra using this array method. Not sure how to get rid of it.
Last edited by Jotne on Wed Apr 17, 2019 9:01 pm, edited 1 time in total.
 
tangram
Member Candidate
Member Candidate
Posts: 132
Joined: Wed Nov 16, 2016 9:55 pm

Re: Fetch - How to access data variable?

Wed Apr 17, 2019 3:44 pm

How about this ?

:put ([/tool fetch url="https://api.ipify.org/" mode=http dst-path=ipcheck output=user as-value]->"data")
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Fetch - How to access data variable?

Wed Apr 17, 2019 9:17 pm

Can even be shorten more.
This site is some better since it does not give an extra empty line.
:put ([/tool fetch url="https://api.ipify.org/" output=user as-value]->"data")
 
tangram
Member Candidate
Member Candidate
Posts: 132
Joined: Wed Nov 16, 2016 9:55 pm

Re: Fetch - How to access data variable?

Thu Apr 18, 2019 12:21 pm

any idea how to do this when you have multiple isps to get address of all providers ?

mine are set with different distance in routes and mangle input/output to specific routing tables. so all traffic goes out the main isp, but the router can be reached over all isps.
i tried with src-address but i always get the reply of the main isp. I also tried setting a specific route for ipify but it didn't work.
 
User avatar
floaty
Member
Member
Posts: 321
Joined: Sat Oct 20, 2018 1:24 am
Location: 52°08'32.34"N 14°39'05.0"E

Re: Fetch - How to access data variable?

Fri Jan 06, 2023 8:55 pm

just asking myself ... why is a unicorn exeption like
.
:put ([/tool fetch url="https://api.ipify.org/" output=user as-value]->"data")
.
possible ...
... ( ... you may try this with https://www.your-xxxx-site.com ... )
...
while the following below is NOT possible to define as a variable:
.
/tool snmp-get security=private authentication-protocol=SHA1 authentication-password=*** encryption-protocol=AES encryption-password=*** version=3 community=**user** address=**IP** oid=1.3.6.1.2.1.33.1.1.1.0
.
is it a security concern that I've missed in the bigger picture ? ... or is it just forgotten to be implemented ?
.
a SNMP-OID gives back (most of the time) one decisive piece of information from a tree ...
a html-request gives (normally) back ... a ... ... a tur*
.
please walk me through
 
User avatar
floaty
Member
Member
Posts: 321
Joined: Sat Oct 20, 2018 1:24 am
Location: 52°08'32.34"N 14°39'05.0"E

Re: Fetch - How to access data variable?

Fri Jan 06, 2023 9:22 pm

.
[admin@***] > /tool snmp-get security=private authentication-protocol=SHA1 authentication-password=* encryption-protocol=AES encryption-password=* version=3 community=* address=* oid=1.3.6.1.2.1.33.1.1.1.0
OID                                                                                         TYPE             VALUE                                                                                        
1.3.6.1.2.1.33.1.1.1.0                                                                      octet-string     Alpha                                                                                        

[admin@***] > 
.
maybe "as-value" just needed to clip on the end of a (code-)line ... cause "VALUE" ... is already there ?!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Fetch - How to access data variable?

Sat Jan 07, 2023 10:54 am

(It's just not implemented)

Why hijack another topic?
Already answered in other topic, just search...
viewtopic.php?t=136809
 
User avatar
floaty
Member
Member
Posts: 321
Joined: Sat Oct 20, 2018 1:24 am
Location: 52°08'32.34"N 14°39'05.0"E

Re: Fetch - How to access data variable?

Mon Jan 09, 2023 10:22 pm

(obviously !)
.
the post was about: why is it implemented for a comparable method (fetch) and the possible reasons ( ... why not for snmp)
... so please read more diligent
.
I've searched the forum ... found your post ... and have not implemented it
halfway the reason I've posted this question
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Fetch - How to access data variable?

Tue Jan 10, 2023 2:34 am

... so please read more diligent

together with «a unicorn»?
 
User avatar
floaty
Member
Member
Posts: 321
Joined: Sat Oct 20, 2018 1:24 am
Location: 52°08'32.34"N 14°39'05.0"E

Re: Fetch - How to access data variable?

Tue Jan 10, 2023 3:21 am

: )
figure of speech for a "website" which gives a reasonable response
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Fetch - How to access data variable?

Fri Apr 14, 2023 7:32 pm

[admin@***] > /tool snmp-get security=private authentication-protocol=SHA1 authentication-password=* encryption-protocol=AES encryption-password=* version=3 community=* 
maybe "as-value" just needed to clip on the end of a (code-)line ... cause "VALUE" ... is already there ?!
The "as-value" with /tool/snmp-get is available in v7.8: viewtopic.php?t=168638#p996470
 
User avatar
floaty
Member
Member
Posts: 321
Joined: Sat Oct 20, 2018 1:24 am
Location: 52°08'32.34"N 14°39'05.0"E

Re: Fetch - How to access data variable?

Wed Apr 19, 2023 12:30 pm

magnificent

Who is online

Users browsing this forum: No registered users and 25 guests