This example script adds a read only community string to the selected Cisco device. It relies on the task that is calling the script having a newCommunity parameter. Different tasks can use the same add community string step, but have different values for their newCommunity parameter.
1. expect.with
2. {
3. if( vendor.equals("9") )
4. {
5. sendln "configure terminal"
6. expect( configPrompt, {} )
7. setDiagnosticLogging false
8. setLogUser false
9. sendln "snmp-server community " + param.newCommunity + " ro"
10. expect( configPrompt, {} )
11. setLogUser true
12. setDiagnosticLogging true
13. }
14. else
15. {
16. println "NO VALID METHOD FOR THIS DEVICE"
17. throw new Exception("no valid method for this device")
18. }
19. }
Overview of the add read only community string script structure:
- Line 3. finds the seventh character of the sysOID to identify the device vendor.
- Line 5. sets the terminal to configure.
- Lines 7. and 8. turn off the terminal logging. This hides the community string from the
display. - Line 9. sets the snmp-server community to the value of the task’s newCommunity parameter.
- Line 10. checks for the return of the prompt. This instruction is sent before turning on logging as it clears from the expect buffer the community string. The next two lines turn on logging and will clear the buffer displaying the prompt.
- Lines 11. and 12. turn on the terminal logging.
- Line 14. to Line 18. return an error message when the device is not a Cisco device. This script concentrates on Cisco, but you could extended it to use with devices from other vendors.
Comments
0 comments
Please sign in to leave a comment.