Community discussions

 
millenium7
Member Candidate
Member Candidate
Topic Author
Posts: 190
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: 107
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: 107
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
Member Candidate
Member Candidate
Topic Author
Posts: 190
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: 16
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
Member Candidate
Member Candidate
Topic Author
Posts: 190
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

Who is online

Users browsing this forum: No registered users and 6 guests