Created
December 11, 2015 03:50
-
-
Save netmanchris/bd73f18cbcd44cf56213 to your computer and use it in GitHub Desktop.
Python code using pysnmp library to set interface description on a network device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pysnmp | |
def set_snmp_single(rwstring, ip_address, ifAlias, description): | |
from pysnmp.entity.rfc3413.oneliner import cmdgen | |
from pysnmp.proto import rfc1902 | |
cmdGen = cmdgen.CommandGenerator() | |
cmdGen.setCmd( | |
cmdgen.CommunityData(rwstring), | |
cmdgen.UdpTransportTarget((ip_address, 161)), | |
(ifAlias, rfc1902.OctetString(description))) | |
def set_interface_description(ipaddress, ifIndex, descr): | |
""" | |
Issues SNMP SET Command to change the description on a interface of device | |
:param ifIndex: type int | |
:param descr: type string | |
:return: None | |
""" | |
ip_address = ipaddress | |
community_string = 'private' | |
snmp_port = 161 | |
ifIndex = str(ifIndex) | |
descr = descr | |
ifAlias = str("1.3.6.1.2.1.31.1.1.1.18." + ifIndex) | |
set_snmp_single(community_string, ip_address, ifAlias, descr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment