Community discussions

MikroTik App
 
cnolte23
just joined
Topic Author
Posts: 3
Joined: Sat Jul 14, 2018 6:30 pm

RouterOS SNMP Get

Sat Jul 14, 2018 6:36 pm

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.
 
cnolte23
just joined
Topic Author
Posts: 3
Joined: Sat Jul 14, 2018 6:30 pm

Re: RouterOS SNMP Get

Sun Aug 05, 2018 4:11 am

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!
 
pe1chl
Forum Guru
Forum Guru
Posts: 10218
Joined: Mon Jun 08, 2015 12:09 pm

Re: RouterOS SNMP Get

Sun Aug 05, 2018 1:00 pm

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 .... ];
 
sid5632
Long time Member
Long time Member
Posts: 554
Joined: Fri Feb 17, 2017 6:05 pm

Re: RouterOS SNMP Get

Sun Aug 05, 2018 3:06 pm

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=[]      
 
cnolte23
just joined
Topic Author
Posts: 3
Joined: Sat Jul 14, 2018 6:30 pm

Re: RouterOS SNMP Get

Sun Aug 05, 2018 6:47 pm

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.
 
User avatar
dasiu
Trainer
Trainer
Posts: 231
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: RouterOS SNMP Get

Mon Aug 06, 2018 11:12 am

Hi! The is no "issue" with amount of data or anything... It's simple it's just NOT SUPPORTED yet :).

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! :)
 
millenium7
Long time Member
Long time Member
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: RouterOS SNMP Get

Wed Mar 27, 2019 8:10 am

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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: RouterOS SNMP Get

Wed Mar 27, 2019 9:01 am

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.
 
millenium7
Long time Member
Long time Member
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: RouterOS SNMP Get

Wed Mar 27, 2019 9:47 am

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
 
pe1chl
Forum Guru
Forum Guru
Posts: 10218
Joined: Mon Jun 08, 2015 12:09 pm

Re: RouterOS SNMP Get

Wed Mar 27, 2019 3:18 pm

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...
 
maxfava
Member Candidate
Member Candidate
Posts: 225
Joined: Mon Oct 17, 2005 12:30 am

Re: RouterOS SNMP Get

Thu Jan 23, 2020 8:45 pm

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
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3433
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: RouterOS SNMP Get

Fri Sep 03, 2021 11:17 pm

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
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS SNMP Get  [SOLVED]

Sat Sep 04, 2021 1:20 am

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."
    }
}
Last edited by rextended on Sat Sep 04, 2021 12:03 pm, edited 4 times in total.
 
millenium7
Long time Member
Long time Member
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: RouterOS SNMP Get

Sat Sep 04, 2021 2:01 am

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
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS SNMP Get

Sat Sep 04, 2021 2:05 am

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...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3433
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: RouterOS SNMP Get

Sat Sep 04, 2021 2:28 am

Fair enough – since your script is 4+ years old – that does say something about the "wearing out the flash" argument here ;).

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)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS SNMP Get

Sat Sep 04, 2021 2:53 am

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

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...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3433
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: RouterOS SNMP Get

Sat Sep 04, 2021 4:57 am

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...
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3433
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: RouterOS SNMP Get

Fri Apr 14, 2023 7:33 pm

search tag # rextended read snmp put value on variable

After 4 years the solution...

Just ask...
FWIW the "as-value" with /tool/snmp-get is available in v7.8: viewtopic.php?t=168638#p996470
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS SNMP Get

Fri Apr 14, 2023 7:36 pm

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

Who is online

Users browsing this forum: No registered users and 26 guests