In this case the SNMP idx = internal interface ID, but that is not the case normally. So how to tell from :put [/interface print oid as-value ] that I need interface with id **1, 2 etc? It seem not to work with loop.?
Code should be some like this:
{
:foreach id in=[/interface find] do={
:local Name [/interface get $id name]
:local Idx [/interface print oid as-value $id actual-mtu]
:local SNMPIdx [ do some extract to get the last number in $Idx to get the actual SNMPIdx]
:put "ifname=$Name SNMPIdx=$SNMPIdx"
}
}
Hmm. This seems to be hard to solve.
Rotuer OS do send interface id in all netflow packets, but there are no easy way to get hold of them, since OID only shows it on the print command and not on the get command.
Why would you need that internally to RouterOS? I mean, the SNMP tools are not that powerful that you would want to do SNMP things inside RouterOS scripting, or did I miss something?
When observing from the outside (an external system using SNMP to monitor a MikroTik device) of course you can walk the IF-MIB::ifName or IF-MIB::ifDescr table to obtain the mapping between interface and index. Tools like MRTG do that.
Netflow packet do contain what interface they are sent trough. Name of the filed is inputSNMPidx or outputSNMPidx.
So I do know that with SNMP i can find the corresponding interface.
My goal is to get teh SNMPidx number and name sent to my Splunk server using Syslog. (I do already send a lot of stuff using syslog).
SNMP can not be used on routers behind NAT, and I like that all goes from Router to server and nothing do request to the router.
Since the list of interface changes when you add Vlan/VPN/bridges etc (Dynamic), I need to read this example once a day.