python3-netsnmp icon indicating copy to clipboard operation
python3-netsnmp copied to clipboard

RemotePort parameter not used

Open Guens opened this issue 5 years ago • 3 comments

When the parameter RemotePort is modified (with another value than 161), snmpget/walk still uses 161 as a remote port.

Guens avatar Jan 15 '20 12:01 Guens

It works if you append the port to the DestHost like this DestHost="<HOST>:<PORT>":

sess = netsnmp.Session(Version=2,
                       DestHost="{}:{}".format(host, port),
                       Community='public')

AlexandreYang avatar Oct 01 '20 11:10 AlexandreYang

Thanks for your answer Alexandre. But it looks like more an undocumented workaround than a bugfix of the RemotePort parameter. Isn't it ?

Guens avatar Oct 01 '20 11:10 Guens

Agree it's a bit confusing.

I found this test using this syntax in net-snmp-5.9/python/netsnmp/tests/test.py. Makes me think it might not be a workaround.

def snmp_dest(**kwargs):
    """Return information about how to communicate with snmpd"""
    dest = {
        'Version':    1,
        'DestHost':   'localhost:' + str(os.environ.get("SNMP_SNMPD_PORT", 161)),
         # Both the community strings "public" and "private"
         # cannot be used to set variables using "snmpset"
         # operations. Run the "snmpset" tests after replacing
         # the following 'Community' string with any other
         # configured community string from the snmpd.conf file.  
        'Community':  'public',
    }
    for key, value in kwargs.items():
        dest[key] = value
    return dest

Not sure what's the purpose of RemotePort, possibly a bug (?)

The doc in netsnmp source indicates:

RemotePort  - default '161', allow remote UDP port to be overridden

AlexandreYang avatar Oct 01 '20 12:10 AlexandreYang