/
Scripting Examples
Scripting Examples
This section provides the following script examples:
- A script that executes a Cisco Connectivity Fault Management feature update job on a series of Cisco 3400 switches.
- A script that allows copying a file to a device via SCP.
Script for Cisco Connectivity Fault Management Feature Update Job
Note the extended series of configuration commands in the trigger process-CFM.
###########################################################################
## Export of Script: CFM Update
## Script-Level: 2
## Script-Category:
###########################################################################
Script:
CFM Update
Script-Description: A script to dynamically configure CFM on switches
Script-Filter:
$Vendor eq "Cisco" and $Model like /3400/
#######
Action:
Determine CFM
Action-Description:
Do a show CFM to determine if a device already has CFM.
Action-Commands:
SET: $cfm_exists = "yes"
show ethernet cfm maintenance-points local
Output-Triggers:
Check CFM
########
Trigger:
Check CFM
Trigger-Description:
If CFM is already enabled on the device, we will update the cfm_exists variable to yes
Trigger-Template:
Local MEPs\: None
Trigger-Commands:
SET: $cfm_exists = "no"
#######
Action:
Get CFM Variables
Action-Description:
Perform a "show run interface Gi0/1" to get the existing VLAN information.
Action-Filter:
$cfm_exists eq "no"
Action-Commands:
sho run interface Gi0/1
SET: $correct_vlan = "no"
SET: $UpdateMade = "no"
Output-Triggers:
Process CFM
Incorrect VLAN
#######
Trigger:
Process CFM
Trigger-Description: Parse the output of the show run to get the vlan numbers.
Trigger-Variables:
$vlan integer
Trigger-Template:
switchport trunk allowed vlan 2[[$vlan]],3\d+
Trigger-Commands:
SET: $correct_vlan = "yes"
SET: $UpdateMade = "yes"
config t
ethernet cfm ieee
ethernet cfm global
ethernet cfm traceroute cache
ethernet cfm traceroute cache size 200
ethernet cfm traceroute cache hold-time 60
ethernet cfm mip filter
ethernet cfm alarm notification all
ethernet cfm domain Slight level 4
service vlan-id 2$vlan vlan 2$vlan
mep mpid 6$vlan
continuity-check
continuity-check interval 1s
continuity-check loss-threshold 2
mip auto-create
service vlan-id 3$vlan vlan 3$vlan
mep mpid 7$vlan
continuity-check
continuity-check interval 1s
continuity-check loss-threshold 2
mip auto-create
ethernet cfm lck link-status global
disable
ethernet cfm ais link-status global
disable
ethernet evc 2$vlan
oam protocol cfm svlan 2$vlan domain Slight
ethernet evc 3$vlan
oam protocol cfm svlan 3$vlan domain Slight
Int g0/1
No service-policy input CoS
No service-policy output parent-shape-1Gb/s
No l2protocol-tunnel
exit
No policy-map parent-shape-1Gb/s
No policy-map child-shape-100Mb/s
No policy-map CoS
No policy-map TXQ
policy-map child-shape-100Mb/s
class class-default
shape average 100000000
policy-map parent-shape-1Gb/s
class class-default
shape average 1000000000
service-policy child-shape-100Mb/s
policy-map 100Mb/s
class class-default
trigger-commands:{$Version like /12\.2\(55\)/}
police cir 100m conform-action transmit exceed-action drop
trigger-commands:{$Version not like /12\.2\(55\)/}
police cir 100m pir 100m conform-action transmit exceed-action drop violate-action drop
trigger-commands:
Int g0/1
Service-policy input 100Mb/s
Service-policy output parent-shape-1Gb/s
ethernet cfm mep domain Slight mpid 3$vlan vlan 3$vlan
cos 7
ethernet cfm mep domain Slight mpid 2$vlan vlan 2$vlan
cos 7
no ethernet cfm ais link-status
########
Action:
End and Write Memory
Action-Description:
End and Write Memory only if we entered config mode.
Action-Commands:{$UpdateMade eq "yes"}
end
DEBUG:write mem
########
Issue:
Incorrect VLAN
Issue-ID:
Incorrect_VLAN_CFM
Issue-Severity:
error
Issue-Description:
This device could not be upated by the CFM script
Issue-Filter:
$correct_vlan eq "no"
Issue-Details:
Host $Name
Address $IPAddress
Script for Copying a File to a Device via SCP
###########################################################################
## Export of Script: SSH file copy
## Script-Level: 3
## Script-Category: Uncategorized
###########################################################################
Script:
SSH file copy
Script-Description:
This script copies a file from a Cisco NX-OS device to
the Backup folder of NetMRI
Script-Filter:
$Vendor eq "Cisco" and
$sysDescr like /NX-OS/
Script-Variables:
$server string ""
$vrf string "management"
$new_file_name string "switch-router.conf"
$scp_username string ""
$scp_password password ""
#########################################################################
Action:
File copy
Action-Description:
Copy the new image file from the remote host via SCP
Action-Timeout:
120
# Overriding the prompt. NetMRI stops doing this action when meets this prompt
Action-Prompt: /(Are you sure you want to continue connecting.*$)|(.*'s password:)/
Action-Commands:
copy bootflash:$new_file_name scp://$server/Backup/$new_file_name\r$vrf\r$scp_username\r
Output-Triggers:
RSA warning prompt
Enter scp password
#########################################################################
Trigger:
RSA warning prompt
Trigger-Description:
This trigger detects RSA warning prompt during attempt to connect via SSH and automatically answer 'yes'
# Overriding the prompt. NetMRI stops doing this action when meets this prompt
Trigger-Prompt: /.*'s password:/
# Not the last line of RSA warning, because the last line is new prompt
# and it was cutted, so this trigger couldn't analyze it
Trigger-Template:
The authenticity of host .* can't be established
Trigger-Commands:
yes
Output-Triggers:
Enter scp password
#########################################################################
Trigger:
Enter scp password
Trigger-Description:
This trigger detects invitation to enter password and send the password to the device
# Override to old prompt
# THIS REGEX IS FOR CISCO PROMPT, PLEASE CHANGE IF YOU WANT TO RUN THIS JOB ON A DEVICE WITH ANOTHER VENDOR
Trigger-Prompt: /[\\r\\n]+[^\\r\\n]*[^>#]+?(>|#)[ ]?$/
# SSH banner of NetMRI (couldn't use string ends with 'password:' by the reason like in the previous trigger)
Trigger-Template:
ALL UNAUTHORIZED .*
Trigger-Commands:
$scp_password\r
Related content
Job Automation with CСS Scripting
Job Automation with CСS Scripting
More like this
Looping with CCS Scripting
Looping with CCS Scripting
More like this
About CCS
About CCS
More like this
Creating and Scheduling Jobs
Creating and Scheduling Jobs
More like this
Creating and Scheduling Jobs
Creating and Scheduling Jobs
More like this
Creating and Scheduling Jobs
Creating and Scheduling Jobs
More like this