Skip to content

Python tool to perform Cisco configuration copy operations via snmp.

License

Notifications You must be signed in to change notification settings

grelleum/snmp_tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

snmp_tool

snmp_tool is intended for copying Cisco router and switch configuration files to and from network based servers via snmp. This is especially useful when making configuration changes to access methods like tacacs. If a change to authentication has locked you out of the CLI, you can revert the change via pushing the configuration via snmp.

snmp_tool is designed to be compatible with both Python 2.6, 2.7, and 3.x.
snmp_tool requires pysnmp module installed.

Implements the features of the Cisco config copy MIB: ftp://ftp.cisco.com/pub/mibs/v2/CISCO-CONFIG-COPY-MIB.my
Based on information found within the Cisco document: "How To Copy Configurations To and From Cisco Devices Using SNMP" http://www.cisco.com/c/en/us/support/docs/ip/simple-network-management-protocol-snmp/15217-copy-configs-snmp.html

Usage:

Instantiate the snmp_tool class with a hostname or ip address and optionally a community string, udp port number and snmp server source address can be provided. These default to 'private', 161 and '0.0.0.0' respectively.
Output from the pysnmp package has been simplified in that the data is returned without the error status. Instead error with raise and OSError exception and will attempt to provide as much decoded error information as is available.

The snmp_tool class provides get, set, and copy methods. get and set are standard snmp operations and can be used with any SNMPv1 or SNMPv2c device. copy is specific to compatible Cisco routers and switches and the main purpose of the module.

Once you have instantiated the object, you can use it to perform the copy.
object.copy(source=None, destination=None, server=None, filename=None, username=None, password=None)
source and destination are always required and can be one of these: ['running', 'startup', 'tftp', 'ftp', 'rcp', 'scp', 'sftp']
server and filename are required when copying to/from a server.
With the exception of tftp, username and password are also required when copying to/from a server.

Example:
from snmp_tool import snmp_tool
snmp = snmp_tool('172.17.0.32', 'private', src_address = '1.1.1.1')
try:
    # Fetch configuration changes from tftp server.
    snmp.copy('tftp', 'running', '172.17.0.254', 'change_12345')
    # Save the running configuration to nvram.
    snmp.copy('running', 'startup')
    # Backup running configuration to secrue server
    snmp.copy(source='running', destination='scp',
        server='172.17.0.254', filename='NYCWAN01', 
        username='router', password='secret')
except OSError as exception:
    print(exception)

Intersting find: importing unicode_literals from __future__ in python2 breaks compatibility with the pysnmp package. Apparently the authors of pysnmp detect the python version running and require a Python 2 bytestring when runnning in Python 2.

About

Python tool to perform Cisco configuration copy operations via snmp.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages