Community discussions

MikroTik App
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Feature Request: SNMP-GET output to variable

Wed Mar 27, 2019 8:17 am

Currently /tool snmp-get does not allow you to store the output to variables i.e.
:global test [/tool snmp-get 127.0.0.1 oid=.1.3.6.1.4.1.14988.1.1.4.4.0]
:put $test
the 'test' variable is blank
I need to be able to store OID values for use in scripts

My primary use case at the moment is to poll radio links for EIRP/SNR/MCS and if values drop below a threshold I can force OSPF/BGP changes to reroute traffic
Links can still be up but perform very bad due to being knocked out of alignment, rain fade, new obstruction etc. If the link is very poor but still up it causes congestion, packet loss, poor performance etc. I want that link to be considered down entirely without relying on hold timers as they tell me nothing about the link performance

This seems like something very simple to implement and would be extremely useful, as many MikroTik customers use a lot of wireless gear
 
nathan1
Member Candidate
Member Candidate
Posts: 160
Joined: Sat Jan 16, 2016 7:05 pm

Re: Feature Request: SNMP-GET output to variable

Thu Mar 28, 2019 9:16 pm

+1 for this.

I discovered it a few years ago too but never complained, I should have.

I've worked around it like this:
:do {
:execute script={/tool snmp-get x oid=1.2.3.4.5 community=public} file=fetch1.txt
/delay 5
:local blah [/file get fetch1.txt contents]
:put $blah
}
It isn't great because :execute is async so we need to have a delay/notify method and $blah requires parsing. It does work though and I've been doing it for years.
 
nathan1
Member Candidate
Member Candidate
Posts: 160
Joined: Sat Jan 16, 2016 7:05 pm

Re: Feature Request: SNMP-GET output to variable

Thu Mar 28, 2019 9:48 pm

Generalized my code into a function. Not tested very well but seems to work in a few tests:
:global snmpGetFunc do={
   #Hack to be able to snmp-get an OID and capture the output into a variable (via a temporary file)
   #:put "host=$host oid=$oid community=$community tmpfile=$tmpfile"

   :do {
   :local snmpGet [:execute script="/tool snmp-get $host oid=$oid community=$community" file=$tmpfile]
   :do {
      :while ([:len [/system script job get $snmpGet]] > 1 || [:len [/file find where name="$tmpfile"]] = 0) do={
         :delay .1
      }
   } on-error={}

   :local snmpRet [/file get $tmpfile contents]
   /file remove [find name="$tmpfile"]
   :return $snmpRet
   }
}
Example:
:global someVar1 [$snmpGetFunc oid=1.3.6.1.2.1.17.7.1.2.2.1.2.89.184.39.235.105.228.124 host=192.168.69.3 community=public tmpfile=someVar1.txt]
:put $someVar1
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Feature Request: SNMP-GET output to variable

Fri Mar 29, 2019 12:06 am

Thanks. That will help and i'll give it a try later (mods can we get that put into the Wiki page for Tools/SNMP and scripts?)

I don't like doing it by that method though because as you say it relies on delay. It's also causing writes on the flash memory
For my purpose I need it to run very often, every second (and maybe even multiple times in the same script with delays so it runs every 100ms) to be ready to failover very rapidly
This wouldn't work if commands aren't run sequentially, and would kill the flash memory quickly
 
palii
just joined
Posts: 23
Joined: Sun Nov 19, 2017 6:57 pm

Re: Feature Request: SNMP-GET output to variable

Sat May 25, 2019 1:06 am

This is a must. +1 for feature request

Unfortunately the result needs serious string cleaning as well!

Result from my UPS charge level:
OID                             TYPE             VALUE                           
1.3.6.1.4.1.318.1.1.1.2.2.1.0   gauge            97  
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Feature Request: SNMP-GET output to variable

Fri Aug 16, 2019 7:38 am

Bump

I hope a MikroTik rep sees this and puts it on the drawing board. Would help a lot with the ability to read data off other devices
Our primary use case is pre-emptive route failover but I can think of a lot of other use cases i.e. emailing to alert of high temperature of devices that don't support their own alerting or email. Or just not having to enter email details in 100 devices....
"Small' monitoring networks so we don't have to occupy licences and set them up on our primary monitoring platform etc
 
carcharias04
just joined
Posts: 1
Joined: Sat Feb 18, 2012 3:24 pm

Re: Feature Request: SNMP-GET output to variable

Mon Sep 09, 2019 8:55 pm

Hi I also give +1 for must have feature.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3467
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Feature Request: SNMP-GET output to variable

Tue Sep 10, 2019 2:19 am

Agree this is a hole in script'ing, so +1.

But you can use the Dude to run scripts that use SNMP...might especially for the use case described above to switch network configuration based on some SNMP GET result. The needed Dude server is supported by even some lower cost routers like the hEX S. Not always ideal, but we use the Dude for these things, the added visualization of the SNMP-based data is worth the extra package required IMO.
 
palii
just joined
Posts: 23
Joined: Sun Nov 19, 2017 6:57 pm

Re: Feature Request: SNMP-GET output to variable

Fri Oct 04, 2019 1:34 am

Yes, indeed the Dude is a viable solution. But I would only need SNMP-GET for a few minor things and thus installing something as robust as the Dude would be overkill in my case. I'm still hoping the devs will give this function a fix up.
 
millenium7
Long time Member
Long time Member
Topic Author
Posts: 539
Joined: Wed Mar 16, 2016 6:12 am

Re: Feature Request: SNMP-GET output to variable

Fri Oct 04, 2019 10:59 am

It's a bit of a chicken and egg scenario

Because this feature doesn't work, it doesn't get used, people don't even think of it
But if it was implemented, there's A LOT of potential power that can be leveraged with a simple MikroTik router

I know i'd be writing monitoring templates then just chucking mAP Lite's everywhere to handle a lot of the 'per-site' monitoring that doesn't need to be in big monitoring platforms, where it just isn't viable (especially when you pay per sensor/device) or its overkill. Have the mAP send email alerts about a lot of things that I don't feel are important enough to deploy across all sites, and are too much work to implement on their own (i.e. setting up routing to all devices behind NAT on an overlapping IP segment) but are super handy to have.

Like setting up temperature or fan speed alerts for all the Camera's/Switches that the security company manage and charge them a monthly fee for it. It emails them as well as us. This would be an example of a 'per-site' setup thats just too complicated, fiddly and messy to setup on a company-wide monitoring platform that shares all our devices. It's complicated enough without having to add 100x small site monitoring setups. Yet would be easy enough to setup on a mAP and with some email scripts and simply plug it in somewhere in the network

Or a customer calls up and complains about slow internet performance from their server. Can easily monitor CPU, Memory, ping times, port throughput etc of all devices and do up a bit of a report to find where the problem is. I don't want to involve 'customer equipment' in our main monitoring systems but happy to do this as a once off by deploying a little mikrotik built with templates, then just take it out again later. Don't need to get server admin access or install anything on their PC's. It's more time and cost effective
 
palii
just joined
Posts: 23
Joined: Sun Nov 19, 2017 6:57 pm

Re: Feature Request: SNMP-GET output to variable

Mon Sep 07, 2020 12:08 pm

Without variable output it is almost useless. Unfinished. I could image tons of usages as well.

Mikrotik devs please finish this feature.

I completely agree with millenium7. It is a vicious circle.

Who is online

Users browsing this forum: infabo, pav5, tangent, yogi and 119 guests