trehn / hnmp

High-level Python SNMP library
ISC License
49 stars 16 forks source link

snmp set support #1

Closed eill closed 9 years ago

eill commented 10 years ago

Hi, are there plans for snmp set support?

Maybe I can code this for you? If so, could you provide some guidelines about realization?

Thanks in advance.

trehn commented 10 years ago

I have never used SNMP for anything but monitoring, so I don't have any experience with snmpset.

Here is an idea for an API:

from hnmp import SNMP
snmp = SNMP(...)
snmp.set("1.3.6.1.2.1.1.9.1.3.1", "foo")

Note that an implementation will have to guess the type of "foo" (if it's a Python string it should probably end up as an OctetString for pysnmp). I guess there would have to be a way of forcing a particular type:

snmp.set("1.3.6.1.2.1.1.9.1.3.1", "foo", value_type='hex_string')

The snmpset utility understands these types:

    i: INTEGER, u: unsigned INTEGER, t: TIMETICKS, a: IPADDRESS
    o: OBJID, s: STRING, x: HEX STRING, d: DECIMAL STRING, b: BITS
    U: unsigned int64, I: signed int64, F: float, D: double

TimeTicks is the easiest, that's just a datetime.timedelta. One would have to figure out what the best default mapping for a Python integer, float, etc. would be.

Please feel free to contribute :)

trehn commented 9 years ago

merged in #2, thanks again!