WARNING
This hack was done as a proof of concept to learn more about net-snmp and how one can extend it. This is the first working version, not production ready and not sanctioned by Untangle as it requires changes via the command line. It has not been tested to survive reboots or upgrades. I am documenting it to demonstrate it is possible and hopefully garner support enough to get it into a future version of the product.
With that said here is the issue I am trying to solve. I want the “friendly name” that is displayed on the interface configuration page and the tunnel VPN status page to be accessible via SNMP to my network monitoring tools.
My network monitoring tool de jour tries to “Always Keep It Purely Simple”. (Look it up via the acronym. The licensed version is great for work and the unlicensed free version is great for homelabs.) It supports the ifDescr, ifName and ifAlias. Untangle only makes ifName (ie eth0, em0, tun200) and ifDescr (ie Intel Corporation Ethernet Connection I354, Intel Corporation I210 Gigabit Network Connection , tun200) available via SNMP. It makes it more difficult for me to remember which one of my physical interfaces was used for guest access and which VPN tunnel I send their traffic out via.
Enough backstory let’s get onto the technical parts. Below are the steps I used to map the data to ifAlias.
- Since Untangle still uses Python 2.7 and they don’t include various future proof packages you will need to get the 2.7 compatible snmp-passpersist package file elsewhere. This file makes extending the net-snmp functionality with python a snap. Kinda hard to find by I found it here: https://aur.archlinux.org/packages/p...mp-passpersist Untar it and copy snmp_passpersist.py to /tmp on Untangle. In the future with more modem version of python we could pull this from a current repo.
- First review the code below and copy it into a file named ifalias.py in /tmp. Make it executable via “chmod +x ifalias.py” on the Untangle command line.
Code:#!/usr/bin/python -u # -u is unbuffered and required from subprocess import check_output import snmp_passpersist as snmp import json import re # Configure the interface dictionary and ip comamnd regex interface = {} regex = r"^(\d+):\s([\w\d\.]+):" # Function that runs periodically to update the values def update(): # Get the output of "ip link" command to map ifIndex to ifName output = check_output(["/bin/ip", "link"]) matches = re.finditer(regex, output, re.MULTILINE) # Add to dictionary such as eth0 = 1 or tun203 = 2262 for matchNum, match in enumerate(matches, start=1): interface[match.group(2)] = match.group(1) # Grab the contents of the network.js file with open('/usr/share/untangle/settings/untangle-vm/network.js') as f: data = json.load(f) # Go through the physical interfaces and add the index number and name into # the pass persist object. 4 = "WAN1: Cox Gigablast" for item in data["interfaces"]["list"]: try: pp.add_str(str(interface[str(item["physicalDev"])]), item["name"]) except: pass # Go through the physical interfaces contatidate "tun" with the index number # from network.js to get ifName (ie tun203) to then get the actual ifIndex number # like 2263 to finally map that to the friendly name # into the pass persist object. 263 = "tunnel-WS-Germany" for item in data["virtualInterfaces"]["list"]: try: pp.add_str(str(interface["tun" + str(item["interfaceId"])]), str(item["name"])) except: pass # Configrue pass persis for the ifAlias oid and have it run the update # This is configured for 5 seconds for testing but would change it # to 5 minutes (300 seconds) for ongoing as the data should be fairly static pp=snmp.PassPersist(".1.3.6.1.2.1.31.1.1.1.18") pp.start(update,5)
- Add the following line at the end of /etc/snmp/snmpd.conf that will reference the script anytime the ifAlias OID is requested.
Code:pass_persist .1.3.6.1.2.1.31.1.1.1.18 /tmp/ifalias.py
- Restart the snmpd service from the Untangle command line
Code:service snmpd restart
- Using your SNMP community string from the Untangle command line check that it works
Code:snmpwalk -c YOURCOMMUNITY -v 2c 127.0.0.1 .1.3.6.1.2.1.31.1.1.1.18
- Re-walk Untangle from your favorite monitoring tool and notice friendly interfaces names all over
In summary its not very difficult and I hope it finds its way into a future release.
Comment