Cisco tftp upload via snmpset

H

Heinrich Piard

Hi all,

whoever is interested in it.

#!/usr/bin/ruby
#Version 0.1 Heinrich Piard - basic version of
snmpset-copy-running-config-to-tftp.rb

require 'yaml'
require 'snmp'
require 'socket'
#require 'daemons'
#require 'action_mailer'
require 'csv'
include Socket::Constants
#include Daemonize


# Cisco OIDs (variables)
#The ConfigCopyProtocol is set to TFTP
oid_setTFTP = "1.3.6.1.4.1.9.9.96.1.1.1.1.2.111 i 1"
#Set the SourceFileType to running-config
oid_setRUNNINGCONFIG = "1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4"
#Set the DestinationFileType to networkfile
oid_setDSTFILENETWORK = "1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 1"
#Sets the ServerAddress to the IP address of the TFTP server
1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a <TFTP IP>
oid_setIPADDRTFTPSERVER = "1.3.6.1.4.1.9.9.96.1.1.1.1.5.111 a"
#Sets the CopyFilename to your desired file name
1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s <Filename>
oid_setDSTFILENAME = "1.3.6.1.4.1.9.9.96.1.1.1.1.6.111 s"
#Sets the CopyStatus to active which starts the copy process
1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1
oid_setSTARTPROCESS = "1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1"
#idcnetwatch1.bxc.is-teledata.com (TFTP server)
tftpserver = '172.29.0.254'
#hostlist including all switches
hostlist =
'/homes/network-monitoring/snmpset-copy-running-config-to-tftp.conf'
#snmp RO
rocommunity = 'public'
#snmp RW
rwcommunity = 'secret'



#start logic

#check if configfile is available
if ((File.exist?(hostlist)) && (File.readable?(hostlist)))
host = CSV.readlines(hostlist)
else
puts 'Cannot locate configuration file! Please check!'
exit
end

host.each do |ip|
system('snmpset -v2c -c ' + "#{rwcommunity} #{ip} #{oid_setTFTP}")
system('snmpset -v2c -c ' + "#{rwcommunity} #{ip}
#{oid_setRUNNINGCONFIG}" )
system('snmpset -v2c -c ' + "#{rwcommunity} #{ip}
#{oid_setDSTFILENETWORK}" )
system('snmpset -v2c -c ' + "#{rwcommunity} #{ip}
#{oid_setIPADDRTFTPSERVER} #{tftpserver}" )
system('snmpset -v2c -c ' + "#{rwcommunity} #{ip}
#{oid_setDSTFILENAME} #{ip}" )
system('snmpset -v2c -c ' + "#{rwcommunity} #{ip}
#{oid_setSTARTPROCESS}" )
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top