Cisco tftp upload via snmpset

Discussion in 'Ruby' started by Heinrich Piard, Jul 23, 2008.

  1. 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
    --
    Posted via http://www.ruby-forum.com/.
     
    Heinrich Piard, Jul 23, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry
    Replies:
    3
    Views:
    383
    Joerg Jooss
    Oct 14, 2005
  2. TFTP client in python

    , Jul 14, 2006, in forum: Python
    Replies:
    3
    Views:
    2,790
    Stefan Behnel
    Jul 14, 2006
  3. msoulier
    Replies:
    1
    Views:
    365
    msoulier
    Oct 5, 2006
  4. Chris G.
    Replies:
    1
    Views:
    127
    Ted Zlatanov
    Jul 21, 2006
  5. Natxo
    Replies:
    3
    Views:
    122
    Peter J. Holzer
    Oct 25, 2010
Loading...

Share This Page