RouterOS SNMP Get

Can I use the RouterOS commands to pull SNMP OID’s from devices attached to the ethernet port of the Router Board? For example I want to pull SNMP data from a device that reads Voltage and I want to store that information on the Router Board in a file. Then once a day have my server pull the data from that Router Board. Is this possible or should the server pull the data directly. Mainly trying to limit bandwidth usage over the wireless back haul from the server to the Router Board. Thanks.

Still looking for help… I’ve started experimenting with the SNMP-GET command, but I’m not able to store the information into a variable or into a file. /tool snmp-get community=XXXXX port=XXXX oid=1.3.6.1.4.1.994.3.4.7.21.1.66.1 version=2c address=XXX.XXX.XXX.XXX returns the following.
[admin@router]
OID TYPE VALUE
1.3.6.1.4.1.994.3.4.7.21.1.66.1 octet-string 53.8

Can I store the value into a variable or into an array if I had the name of the value from another oid from the value below?

OID TYPE VALUE
1.3.6.1.4.1.994.3.4.7.21.1.3.1 octet-string Battery_String_1

There are about 10 values and names I need to store. Please any help would be greatly appreciated!

You will have to write a script that uses this command and put the output in a variable, then you can write this variable in a file when you like.
You would use the script construct:

:local variable;
:set variable [ /tool snmp-get … ];

This doesn’t work…

[admin@MikroTik] > :global x
[admin@MikroTik] > env pr
x=[:nothing]

[admin@MikroTik] > :set x [/tool snmp-get address=192.168.0.1 oid=1.3.6.1.4.1.14988.1.1.11.1.1.4.3]
OID                                 TYPE             VALUE                               
1.3.6.1.4.1.14988.1.1.11.1.1.4.3    octet-string     6.42.6 (stable)                     

[admin@MikroTik] > env pr
x=[]

Thank you for the responses, I’ve tried putting the output into a variable before with the same results. I think the issue is the amount of data coming from the snmp-get statement is more than can be held in a single variable. Also the return line and blank spaces could be throwing a wrench into the system.

Hi! The is no “issue” with amount of data or anything… It’s simple it’s just NOT SUPPORTED yet :slight_smile:.

I believe someone from MT staff said that they plan to introduce it later (can’t remember, where), for now the snmp-get is just for user interaction, can’t be scripted.

I’m also waiting for it to be developed! :slight_smile:

This needs to be implemented, would be hugely useful

My particular use case is monitoring link quality of radio’s so I can force a re-route when SNR or signal strength drops below a certain point
Without this, link can flap up and down with packet loss, high latency, congestion etc. OSPF becomes very unreliable

I want to move traffic ‘before’ the link goes down entirely to prevent a poor link (rain, knocked out of alignment, obstruction etc) from affecting network performance

If the data is readable within routerOS using a command, you can do it without need for SNMP.
Make a scheduled scripts that reads the data likes this to get the CPU load

:local cpuload ([/system resource get cpu-load])

Then do an if statement and change some when a threshold is passed.

Well yes obviously if it was local to the device, however the point of SNMP is to retrieve data from ‘other’ devices

i.e.
RouterA->RadioA->RadioB->RouterB

Neither router has any visiblity of the link, they only see the physical ethernet port status, RadioA->RadioB can be down entirely, still shows up from the perspective of either Router though
Or worse, RadioA->RadioB is still up and so OSPF/BGP keepalives get through, barely. But the link performance might be say 3mbit/s when it should be 500mbit/s
Again, no visibility, no way to change link metrics etc

SNMP-GET would mean RouterA can monitor RadioA’s reported information on the link to RadioB, then adjust metrics or make it unreachable pre-emptively, meaning near instantaneous and pre-emptive failover when conditions worsen instead of keeping that terrible link alive and passing traffic which is a nightmare for VoIP traffic

That is a wellknown problem. Well, at least wellknown to me, it sometimes surprises me that it isn’t mentioned more often.
When you make a network out of MikroTik routers (e..g. RBx011) and point-to-point links (e.g. LHG5) where there are redundant paths in the network,
it is quite difficult to get it routing properly, especially out-of-the-box.
Routing protocols like BGP have simple path selection algorithms like “less hops is better” that do not work well in wireless link environments.
E.g. with 3 routers A B and C where all 3 have wireless links but from A to C is a poor link, traffic from A to C should be routed via B when the
two links A-B and B-C are considerably better than A-C. However there is no easy way to feed the link quality into the routing algorithm.

Why not?? I thought that this kind of network was the core business of companies like MikroTik…

I tried today, as workaroud of dude discovery that does not resolve device name from dns or snmp.
So I’m trying snmp-get command, but it does return contact mirkotik LoL

I was hoping this was fixed in v7.1rcX… But there is no “get” or “as-value” for /tool/snmp-get there either.


Since there is v7 Dude yet, there just no way to get SNMP values in v7 either AFAIK…

+1

search tag # rextended read snmp put value on variable

After 4 years the solution…

Just ask…

I just invented that method.

One example:

/file remove [find where name="testgetsnmp.txt"]
{
    :local jobid [:execute file=testgetsnmp.txt \
        script="/tool snmp-get tries=3 try-timeout=3s address=192.168.0.1 port=161 version=2c \
        community=public oid=1.3.6.1.4.1.14988.1.1.3.8.0"]
    :put "Waiting the end of process for file testgetsnmp.txt to be ready, max 20 seconds..."
    :global Gltesec 0
    :while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < 20)) do={
        :set Gltesec ($Gltesec + 1)
        :delay 1s
        :put "waiting... $Gltesec"
    }
    :put "Done. Elapsed Seconds: $Gltesec\r\n"
    :if ([:len [/file find where name="testgetsnmp.txt"]] = 1) do={
        :local filecontent [/file get [/file find where name="testgetsnmp.txt"] contents]
        :if ([:len $filecontent] = 83) do={:put "No result"; :return ""}
        :local oidstart ([:find $filecontent "\r\n" -1] + 2)
        :local oidend [:find $filecontent " " $oidstart]
        :local typestart ($oidstart + [:find $filecontent "TYPE" -1])
        :local typeend [:find $filecontent " " $typestart]
        :local valuestart ($oidstart + [:find $filecontent "VALUE" -1])
        :local valueend [:find $filecontent " " $valuestart]
        :local getoid [:pick $filecontent $oidstart $oidend]
        :local gettype [:pick $filecontent $typestart $typeend]
        :local getvalue [:pick $filecontent $valuestart $valueend]
        :put "The >$getoid< return >$gettype< value >$getvalue<"
    } else={
        :put "File not created."
    }
}

Outputting to file is still not a great method, it’s slow (will likely slow the router down while it waits) and going to wear out the flash memory very quickly when writing often. So it’s not suitable for i.e. radio link monitoring every 5 seconds

I just don’t understand it, it makes me think MikroTik intentionally is blocking this functionality for some reason. What reason I don’t know, but it’s seemingly so simple to implement and has the potential to enormously improve RouterOS functionality and become a.whole network of mini monitoring/alerting/actioning nodes. Would even be possible to write an entire routing protocol dedicated solely to wireless connectivity via SNMP get/set
It’s opening up an entire API suite effectively, for maybe a day of development work to fix this bug… Yet nothing has been done… Madness

The method do not wear FLASH memory, because is used the RAM,
and on NAND memory the wearing is ignorable, on another topic already is explained than the wearing can be a problem after dozens of years…
My user-manager for hotspot is on NAND of one RB1100AHx4, and after uncountables read and writes still work without problem from 2009…
On some device you can use external usb/sd/disks…

Fair enough – since your script is 4+ years old – that does say something about the “wearing out the flash” argument here :wink:.

Still, mainly a +1 for “get” or “as-value” in /tool/snmp-get - than always importing a script to do it…

In my case, I just used a REST API with /tool/fetch to get the data from the device instead

But

:global myRemoteSnmpValue [/tool/snmp-get oid=1.1 ... as-value]

be a lot easier (ideally the result being a key=value type)

I do not have a device or a vm with 7.x for test.
Was it added or is it a hope??? :slight_smile:

I’m a (W)ISP from 2007, all the 1100 or 1200 I have buyed just when are available on market (2009/2010?), all are on production without NAND problems…

I do not haved any “wearing” problem till now, with any other type of device, after all this years…

Sorry, it was only a hope - but no such luck.

I only went looking when I realized there WAS NOT a Dude v7 yet, which would have also solve my “I need a couple variables from non-Mikrotik device to use in a Mikrotik script” problem.

@rextended, I wasn’t doubting you! In fact, my point was exactly your long term usage seems to disavow speculation. By the same token, /tool/fetch has improved a lot since this thread started, and most devices has some kinda HTTP API nowadays. Still SNMP a lot times richer/better curated, and has stuff sometimes not in a HTTP API…

FWIW the "as-value" with /tool/snmp-get is available in v7.8: Saving SNMP to variable

This is for who not want beta software on own network…