Saving SNMP to variable

I do try to save output of Tool SNMP to a variable or send it to syslog. It does not seem to work:

I need to store/send to log, the the output of:

/tool snmp-walk community=public version=2c address=127.0.0.1 oid=1.3.6.1.2.1.1

Tried this, but just give output to console.

{
:local test [/tool snmp-walk community=public version=2c address=127.0.0.1 oid=1.3.6.1.2.1.1]
:put $test
}



{
:local test [/tool snmp-walk community=public version=2c address=127.0.0.1 oid=1.3.6.1.2.1.1]
:log info message="$test"
}

Mikrotik does log that I do run the SNMP command, but not output of it.

snmp MikroTik: getnext 1.3.6.1.2.1.1.7.0
snmp MikroTik: getnext 1.3.6.1.2.1.1.6.0
snmp MikroTik: getnext 1.3.6.1.2.1.1.5.0
snmp MikroTik: getnext 1.3.6.1.2.1.1.4.0
snmp MikroTik: getnext 1.3.6.1.2.1.1.3.0
snmp MikroTik: getnext 1.3.6.1.2.1.1.2.0
snmp MikroTik: getnext 1.3.6.1.2.1.1.1.0
snmp MikroTik: getnext 1.3.6.1.2.1.1

If this does not work, please add this to later build.

PS from the manual:
Return value to a variable
Since RouterOS v6.43 it is possible to save the result of fetch command to a variable

So add it to all tools

The same with reading lte cell-monitor feature…

Only way I know is via file… http://forum.mikrotik.com/t/send-script-output-to-a-file/116250/1

execute "/tool snmp-walk community=public version=2c address=127.0.0.1 oid=1.3.6.1.2.1.1" file=out.txt
file edit out.txt contents 
global out2 [file get out.txt contents]
put [typeof $out2]
str

Thanks for this suggestion.
I did send a request about this to MT Support SUP-33094
Having a lot of file write may wear out the flash?

Every command on RouterOS should be able to store data to all type of storage (Flash/Variable/log/syslog ++)

So to get it to syslog id did this:

:execute "/tool snmp-walk community=public version=2c address=127.0.0.1 oid=1.3.6.1.2.1.1" file=out.txt
:log info message=[file get out.txt contents]

I agree, and can only say at some netinstall RouterBoards we can write file into memory (ram disk, tempfs, etc.), not NAND

If anyone interested, it’s now possible to get an oid value inside script by using as-value property. I don’t know in which ROS version it appeared, but in 7.8 it exists and works.

:local snmpvar [/tool snmp-get address=x.x.x.x oid=x.x.x... as-value]
:log info ($snmpvar->"value")

I had a feature request in for this, and it was closed in late March, so it’s new.

:put [/tool/snmp-get address=127.0.0.1  oid=1.3.6.1.4.1.14988.1.1.3.8.0 community=public as-value ]                      
# oid=1.3.6.1.4.1.14988.1.1.3.8.0;type=integer;value=517

One note, the value returned seems to always be a string type (but reports the original SNMP type in type=).

:put [:typeof ([/tool/snmp-get address=127.0.0.1  oid=1.3.6.1.4.1.14988.1.1.3.8.0 community=public as-value ]->"value") ] 
# str