2

All, I am fairly new to python, but my approach to writing scripts is to try to use as few lines of code as possible without sacrificing readability. With that being said, that is what I tried to do with the script at hand.

I have a script that gets either the running or the startup configuration from a cisco switch via Pysnmp and sends it to a TFTP server. This requires that the value of multiple OID's be set on the switch. When I tried to set the value multiple OID's on a single setCmdcommand via snmp as so:

g = setCmd(SnmpEngine(),
                   CommunityData(snmp_community),
                   UdpTransportTarget((host_ip, 161)),
                   ContextData(),
                   ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopyProtocol', random_number), 1),
                   #ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopySourceFileType', random_number), users_numeric_entry),
                   #ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopyDestFileType', random_number), 1),
                   #ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopyServerAddress', random_number), '10.10.11.100'),
                   #ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopyFileName', random_number), destination_file),
                   #ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopyEntryRowStatus', random_number), 1)
                   )

        next(g)

I can see on the switch(via debugs) that the SNMP packets are delivered, but there must be a timing issue when applying them(setting the OIDs' values). With that being said, is there a way to insert a few millisecond delay between each setCmd command?

When Set the value of each OID individually, my script works as expected, and the configuration is copied to the TFTP server. So for each OID that I need to set the value for, I have a setCmd like below:

g = setCmd(SnmpEngine(),
                   CommunityData(snmp_community),
                   UdpTransportTarget((host_ip, 161)),
                   ContextData(),
                   ObjectType(ObjectIdentity('CISCO-CONFIG-COPY-MIB', 'ccCopySourceFileType', random_number),
                              users_numeric_entry))

        next(g)

Is my problem with setting all OIDs in a single setCmd command really a delay issue? If so, can I insert a delay within the command?

Thank you for your time!

UPDATING WITH DEBUGS FROM SWITCH

Debugs when sending a single setCmd:

00:19:16: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:19:16: SNMP: Get request, reqid 2179409, errstat 0, erridx 0
 system.5.0 = NULL TYPE/VALUE
00:19:16: SNMP: Response, reqid 2179409, errstat 0, erridx 0
 system.5.0 = Switch
00:19:16: SNMP: Packet sent via UDP to 10.10.10.10
00:19:17: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:19:17: SNMP: Set request, reqid 2179410, errstat 0, erridx 0
 ccCopyEntry.2.21 = 1
 ccCopyEntry.3.21 = 4
 ccCopyEntry.4.21
Switch# = 1
 ccCopyEntry.5.21 = 10.10.10.10
 ccCopyEntry.6.21 = Switch-running.txt
 ccCopyEntry.14.21 = 1
00:19:17: SNMP: Response, reqid 2179410, errstat 12, erridx 6
 ccCopyEntry.2.21 = 1
 ccCopyEntry.3.21 = 4
 ccCopyEntry.4.21 = 1
 ccCopyEntry.5.21 = 10.10.10.10
 ccCopyEntry.6.21 = Switch-running.txt
 ccCopyEntry.14.21 = 1
00:19:17: SNMP: Packet sent via UDP to 10.10.10.10

When I send separate setCmd commands:

00:15:33: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:33: SNMP: Get request, reqid -1563913845, errstat 0, erridx 0
 system.5.0 = NULL TYPE/VALUE
00:15:33: SNMP: Response, reqid -1563913845, errstat 0, erridx 0
 system.5.0 = Switch
00:15:33: SNMP: Packet sent via UDP to 10.10.10.10
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Set request, reqid -1563913844, errstat 0, erridx 0
 ccCopyEntry.2.102 = 1
00:15:34: SNMP: Response, req
Switch#id -1563913844, errstat 0, erridx 0
 ccCopyEntry.2.102 = 1
00:15:34: SNMP: Packet sent via UDP to 10.10.10.10
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Set request, reqid -1563913843, errstat 0, erridx 0
 ccCopyEntry.3.102 = 3
00:15:34: SNMP: Response, reqid -1563913843, errstat 0, erridx 0
 ccCopyEntry.3.102 = 3
00:15:34: SNMP: Packet sent via UDP to 10.10.10.10
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Set request, reqid
Switch# -1563913842, errstat 0, erridx 0
 ccCopyEntry.4.102 = 1
00:15:34: SNMP: Response, reqid -1563913842, errstat 0, erridx 0
 ccCopyEntry.4.102 = 1
00:15:34: SNMP: Packet sent via UDP to 10.10.10.10
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Set request, reqid -1563913841, errstat 0, erridx 0
 ccCopyEntry.5.102 = 10.0.1.81
00:15:34: SNMP: Response, reqid -1563913841, errstat 0, erridx 0
 ccCopyEntry.5.102 = 10.0.1.81
00:15:34: SNMP: Packet sent via UDP to 10.0.
Switch#1.20
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Set request, reqid -1563913840, errstat 0, erridx 0
 ccCopyEntry.6.102 = Switch--start.txt
00:15:34: SNMP: Response, reqid -1563913840, errstat 0, erridx 0
 ccCopyEntry.6.102 = Switch--start.txt
00:15:34: SNMP: Packet sent via UDP to 10.10.10.10
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Set request, reqid -1563913839, errstat 0, erridx 0
 ccCopyEntry.14.102 =
Switch#1
00:15:34: SNMP: Response, reqid -1563913839, errstat 0, erridx 0
 ccCopyEntry.14.102 = 1
00:15:34: SNMP: Packet sent via UDP to 10.10.10.10
00:15:34: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:34: SNMP: Get request, reqid -1563913838, errstat 0, erridx 0
 ccCopyEntry.10.102 = NULL TYPE/VALUE
00:15:34: SNMP: Response, reqid -1563913838, errstat 0, erridx 0
 ccCopyEntry.10.102 = 2
00:15:34: SNMP: Packet sent via UDP to 10.10.10.10
Switch#
00:15:37: SNMP: Packet received via UDP from 10.10.10.10 on Vlan1
00:15:37: SNMP: Set request, reqid -1563913837, errstat 0, erridx 0
 ccCopyEntry.14.102 = 6
00:15:37: SNMP: Response, reqid -1563913837, errstat 0, erridx 0
 ccCopyEntry.14.102 = 6
00:15:37: SNMP: Packet sent via UDP to 10.10.10.10
adamz88
  • 319
  • 3
  • 12

2 Answers2

1

I do not think you can make SNMP agent inside the cisco switch to process SNMP variables individually with delays. It also looks highly suspicious that you (as a user) is expected to take care of the timing...

So I'd probably try to understand why the switch does not like your management command, what's the right way to manage it.... One possible source of inspiration is the descriptions in the MIB where the variables you are tackling are defined.

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21
  • per your suggestion I will look at the MIB. In the meantime, I'd like to clarify that I am inquiring about controlling the timing from within PySNMP(is it possible) if not, am I expected to create a separate `setCmd` per OID I want to set the value to? If that's what I have to do, oh well, I just like my code better when I set all of the OID's on the same `setCmd` command. I'm really not sure about best practices. – adamz88 Jan 16 '19 at 14:53
1

That entry follows RowStatus semantics as detailed in https://www.rfc-editor.org/rfc/rfc2579

It seems to me that you need to set ccCopyEntryRowStatus to createAndGo instead of active.

Community
  • 1
  • 1
Gambit Support
  • 1,432
  • 1
  • 7
  • 17