Yes, we use python with easysnmp to push lat/long, customer, and the ISP to the SMs (https://easysnmp.readthedocs.io/en/latest/). The code below is updated for Python 3.
Below is my SNMP wrapper library (config has the configurations for snmp strings, etc you can hard code your values there instead if needed)
bbsnmp.py
import time
from easysnmp import Session, EasySNMPConnectionError, EasySNMPTimeoutError, EasySNMPError
from . import config as snmpconfig
from . import ping
#======== SM MAP ========#
# This SNMP MAP info was in a config file until a refactor (along with the update functionality)
# It can probably be refactored into a nice module with a map passing in, but until that is needed, leaving it all in this base file
# SM Record
CONTACT = 'contact'
LATITUDE = 'latitude'
LONGITUDE = 'longitude'
LOCATION = 'location'
NAME = 'name'
snmp_map = {
CONTACT: ['sysContact.0',None],
LATITUDE: ['.1.3.6.1.4.1.161.19.3.3.2.88.0','OCTEETSTR'],
LONGITUDE: ['.1.3.6.1.4.1.161.19.3.3.2.89.0','OCTETSTR'],
LOCATION: ['sysLocation.0',None],
NAME: ['sysName.0',None],
}
snmp_record_map = {
CONTACT: 'rsp',
LATITUDE: 'latitude',
LONGITUDE: 'longitude',
LOCATION: 'location',
NAME: 'customer',
}
#======== Base Methods ========#
def get(session, key):
return session.get(key).value
# 'OCTETSTR'
def set(session, key, old, new, stype=None):
if new != old:
session.set(key, new, stype)
def update(session, field, value):
key = snmp_map[field][0]
stype = snmp_map[field][1]
old = get(session, key)
set(session, key, old, value, stype)
time.sleep(.01)
#======== Cambium AP Methods ========#
# SMs attached to AP
# IP of AP passed in
def get_ap_sms(ip):
session = Session(hostname=ip,community=snmpconfig.SNMP_AP_COMMUNITY_RO,version=snmpconfig.SNMP_AP_VERSION)
return session.walk('.1.3.6.1.4.1.161.19.3.1.4.1.69')
#======== Cambium SM Methods ========#
# Auth username field
def get_username(ip):
session = Session(hostname=ip,community=snmpconfig.SNMP_COMMUNITY_RO,version=snmpconfig.SNMP_VERSION)
return get(session,'1.3.6.1.4.1.161.19.3.2.7.8.0')
# Utilizes AP SNMP string, so be careful when writing to the AP
def drop_session(ap_ip, sm_mac):
session = Session(hostname=ap_ip,community=snmpconfig.SNMP_AP_COMMUNITY_RW,version=snmpconfig.SNMP_AP_VERSION)
session.set('.1.3.6.1.4.1.161.19.3.1.1.87.0', sm_mac, 'OCTETSTR')
time.sleep(.01)
def clear_idle(ap_ip):
#print ap_ip
session = Session(hostname=ap_ip,community=snmpconfig.SNMP_AP_COMMUNITY_RW,version=snmpconfig.SNMP_AP_VERSION)
session.set('.1.3.6.1.4.1.161.19.3.1.1.108.0', 1, 'INTEGER')
time.sleep(.01)
# 1. Is ip in excluded list? - Update: IP coming from cnmaestro should be
# valid, so currently there should be no need to check it
# 2. Is IP reachable?
def send(record):
# if ip is valid, continue updating SM fields
if ping.isUp(record.ip):
try:
# Setup session
session = Session(hostname=record.ip,community=snmpconfig.SNMP_COMMUNITY_RW,version=snmpconfig.SNMP_VERSION)
[update(session,key,record[value]) for key,value in snmp_record_map.items()]
# This radio could be having connection issues, so do not end program on timeout/connection error
# https://easysnmp.readthedocs.io/en/latest/exceptions.html
except EasySNMPTimeoutError:
pass
except EasySNMPConnectionError:
pass
except EasySNMPError as e:
print(str(e))
Then to use the function I call a method similar to this (I have a csv file I read the values from):
from bbnetworking import snmp as bbsnmp
def update_sms():
sms = []
with open(MERGE_FILE) as csvfile:
filereader = csv.reader( csvfile )
for row in filereader:
record = SMRecord()
record.customer = str(row[0]).replace("'",'').strip()
record.ip = str(row[1]).strip()
record.rsp = str(row[2]).strip()
record.location = str(row[3]).strip()
record.latitude = str(row[4]).strip()
record.longitude = str(row[5]).strip()
print(record.customer, record.ip, record.rsp, record.location, record.latitude, record.longitude)
sms.append(record)
# This is outside the above while loop of course
for item in sms:
print(item.customer, item.ip, item.rsp, item.location, item.latitude, item.longitude)
bbsnmp.send(item)