trehn / hnmp

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

Added support for SNMP version 3 #3

Closed verbosemode closed 9 years ago

verbosemode commented 9 years ago

I wrote my own wrapper around PySNMP, but I would rather contribute to your code than maintaining my own (and create yet another wrapper :D).

Just let me know if there is anyithing in the code you don't like and I'll try to change it.

I did some testing with a Cisco router to make sure the code is working and doesn't break the existing code base.

Best regards,

Jochen

SNMP v2c

R1(config)#snmp-server community public ro

In [1]: from hnmp import SNMP In [5]: snmpsession = SNMP("192.168.42.100", community="public") In [6]: snmpsession.get('1.3.6.1.2.1.1.5.0') Out[6]: u'R1'

SNMP v3 noAuthNoPriv

R1(config)# snmp-server view SNMP_VIEW_ALL iso included R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 noauth read SNMP_VIEW_ALL R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3

In [9]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring") In [10]: snmpsession.get('1.3.6.1.2.1.1.5.0') Out[10]: u'R1'

SNMP v3 AuthNoPriv

R1(config)# snmp-server view SNMP_VIEW_ALL iso included R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 auth read SNMP_VIEW_ALL R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3 auth sha superAuthSecret123

In [1]: from hnmp import SNMP In [2]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring", authkey="authSuperSecret123") In [3]: snmpsession.get('1.3.6.1.2.1.1.5.0') Out[3]: u'R1'

MD5

R1(config)# snmp-server view SNMP_VIEW_ALL iso included R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 auth read SNMP_VIEW_ALL R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3 auth md5 superAuthSecret123

In [1]: from hnmp import SNMP In [2]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring", authproto="md5", authkey="authSuperSecret123") In [3]: snmpsession.get('1.3.6.1.2.1.1.5.0') Out[3]: u'R1'

SNMP v3 AuthPriv

R1(config)# snmp-server view SNMP_VIEW_ALL iso included R1(config)# snmp-server group SNMP_GROUP_ADMINS v3 priv read SNMP_VIEW_ALL R1(config)# snmp-server user monitoring SNMP_GROUP_ADMINS v3 auth sha authSuperSecret123 priv aes 128 privSuperSecret123

In [10]: from hnmp import SNMP In [11]: snmpsession = SNMP("192.168.42.100", version=3, username="monitoring", authproto="sha", authkey="authSuperSecret123", privproto="aes128", privkey="privSuperSecret123") In [12]: snmpsession.get('1.3.6.1.2.1.1.5.0') Out[12]: u'R1'

trehn commented 9 years ago

Very cool, thanks!

Before I merge this, could you please:

verbosemode commented 9 years ago

I'm glad you like it. I've fixed the issues you mentioned in two addtional commits.

Feel free to ping me if someone opens a v3 related issue and I'll have a look at it.

trehn commented 9 years ago

Perfect, thank you very much!