Community discussions

MikroTik App
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 1873
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Saving SNMP to variable

Fri Nov 06, 2020 10:12 pm

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
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
User avatar
SiB
Forum Guru
Forum Guru
Posts: 1314
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: Saving SNMP to variable

Sat Nov 07, 2020 3:21 am

The same with reading lte cell-monitor feature...

Only way I know is via file... viewtopic.php?f=9&t=130448&hilit=execute#p819073
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
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL
WinBox Tip: F6 works as ALT+TAB | Gliffy.com - free network schematic | prnt.sc - free ScreenShot software
At vacation until 15.jan.2021
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 1873
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Saving SNMP to variable

Sun Nov 08, 2020 11:50 am

Only way I know is via file...
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]
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
User avatar
SiB
Forum Guru
Forum Guru
Posts: 1314
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: Saving SNMP to variable

Sun Nov 08, 2020 4:17 pm

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 ++)
I agree, and can only say at some netinstall RouterBoards we can write file into memory (ram disk, tempfs, etc.), not NAND
Image
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL
WinBox Tip: F6 works as ALT+TAB | Gliffy.com - free network schematic | prnt.sc - free ScreenShot software
At vacation until 15.jan.2021

Who is online

Users browsing this forum: No registered users and 30 guests