- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
How to properly use greather than and less than with an action-command?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-18-2017 09:27 AM - edited 08-18-2017 09:29 AM
I have a CCS script where I am pinging a pair of SCP servers from a Cisco router and trying to determine based on the average latency which one is the best choice to use for upgrading the IOS. I have a number of device to upgrade and I would like to intelligenly distribute the copy process base on which server has the lowest latency. However I am not getting the < and > >= or <= operators to work as expected in the Action-Command. Below is the script. What is happening is the first action is always selected reguardless of what the latency valuers are.
###########################################################################
## Export of Script: PING TO SCP TEST
## Script-Level: 1
## Script-Category: Uncategorized
###########################################################################
Script:
PING TO SCP TEST
Script-Description:
'This Script will ping both of the SCP servers then determine which SCP server is closer'
Script-Filter:
$Vendor eq "Cisco" and $Model in ["ASR1002X","ISR4331","ISR4351"]
Script-Variables:
$scp_east string "1.1.1.1"
$scp_west string "2.2.2.2"
#########################################################################
Action:
Ping SCP-EAST
Action-Description:
Execute a ping
Action-Commands:
ping $scp_east
Output-Triggers:
Process PINGRATEEAST
#########################################################################
Action:
Ping SCP-WEST
Action-Description:
Execute a ping
Action-Commands:
ping $scp_west
Output-Triggers:
Process PINGRATEWEST
#########################################################################
Trigger:
Process PINGRATEEAST
Trigger-Description:
Get the ping latency rate to select the East SCP server
Trigger-Variables:
$PingLatencyEast int
Trigger-Template:
round-trip min\/avg\/max = \d{1,3}\/[[$PingLatencyEast]]\/\d{1,3} ms
Trigger-Commands:
SET: $EastLatencyCollected = "yes"
#########################################################################
Trigger:
Process PINGRATEWEST
Trigger-Description:
Get the ping latency rate to select the West SCP server
Trigger-Variables:
$PingLatencyWest int
Trigger-Template:
round-trip min\/avg\/max = \d{1,3}\/[[$PingLatencyWest]]\/\d{1,3} ms
Trigger-Commands:
SET: $WestLatencyCollected = "yes"
#########################################################################
Action:
GET BEST SERVER
Action-Description:
Get the best latency SCP server
Action-Filter:
$EastLatencyCollected eq "yes" and $WestLatencyCollected eq "yes"
Action-Commands: { $PingLatencyEast <= $PingLatencyWest }
SET: $EastIsBest = "yes"
Action-Commands: { $PingLatencyEast > $PingLatencyWest }
SET: $WestIsBest = "yes"
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-18-2017 10:04 AM
I have worked on it a little more and what I have discovered is that the comparision is not acting like a math operaration but more like a string operation. I have found that if I have a situation where when the latency is compared and I have a $PingLatencyEast = 137 and a $PingLatencyWest = 82 then the expression pick the $PingLatencyEast as the lower value, it looks like it is comparing only the first digit in the operation not the full numeric value.
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-18-2017 10:19 AM
They are string variables. To perform math or boolean operations, look at the EXPR function.
I wonder if you also are running into a scoping issue. When you declare and assign values to variables within a trigger, those won't exist at the next level up. So when the third action runs, they should be undefined. If you declare them at the top level, they will be visible at all levels.
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-23-2017 09:59 AM
I was looking at the EXPR: in the CCS guide but I cannot find a good sample of it being used in another script. The CCS guide is pretty bare on the context of how to use EXPR. I did find another forum message with a sample of the EXPR used in a trigger-command. I am also running into the scoping issue you mentioned, would I declare the variable in the Script-Varible section as the "top level". I am not sure what you mean by top level, I tried declaring the trigger varaible in the Script-Varibles and that did not work.
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-25-2017 05:47 PM
OK I tried again but now I am for sure running into a scoping issue, the print output was showing variable values as \d+ not the real value when I try to use that variable with the next trigger command. Here is the script I am using now.
#######################################################################
Script-Filter:
$Vendor eq "Cisco" and $Model in ["ASR1002X","ISR4331","ISR4351"]
#########################################################################
Action:
Get SCP Servers
Action-Description:
Collect the IP of the SCP server from the static route
Action-Commands:
sh run | i SCP-Server
Output-Triggers:
Process GETSCP
#########################################################################
Trigger:
Process GETSCP
Trigger-Description:
Get the IP of the SCP server
Trigger-Variables:
$scp_server /(1\.1\.(1|2)\.1)/
Trigger-Template:
[[$scp_server]]
Trigger-Commands: { $scp_server eq "1.1.1.1" }
ping $scp_server
SET: $EastScpPingCompleted = "yes"
Trigger-Commands: { $scp_server eq "1.1.2.1" }
ping $scp_server
SET: $WestScpPingCompleted = "yes"
Output-Triggers:
Process GETLATENCY
#########################################################################
Trigger:
Process GETLATENCY
Trigger-Description:
Get the ping latency rate to select the best SCP server
Trigger-Variables:
$PingLatency int
$EastPingLatency int
$WestPingLatency int
Trigger-Template:
round-trip min\/avg\/max = \d{1,3}\/[[$PingLatency]]\/\d{1,3} ms
Trigger-Commands: { $scp_server eq "1.1.1.1" and $EastScpPingCompleted = "yes" }
SET: $EastPingLatency = $PingLatency
SET: $EastLatencyCollected = "yes"
PRINT ($ipaddress.txt): $EastPingLatency
Trigger-Commands: { $scp_server eq "1.1.2.1" and $WestScpPingCompleted = "yes" and $EastLatencyCollected = "yes" }
SET: $WestPingLatency = $PingLatency
SET: $WestLatencyCollected = "yes"
PRINT ($ipaddress.txt): $EastPingLatency
PRINT ($ipaddress.txt): $WestPingLatency
EXPR: $BestPing = $EastPingLatency < $WestPingLatency
PRINT ($ipaddress.txt): $EastPingLatency
PRINT ($ipaddress.txt): $WestPingLatency
PRINT ($ipaddress.txt): $BestPing
Trigger-Commands: { $WestLatencyCollected eq "yes" and $EastLatencyCollected = "yes" and $BestPing like /1/ }
SET: $EastIsBest = "yes"
Trigger-Commands: { $WestLatencyCollected eq "yes" and $EastLatencyCollected = "yes" and $BestPing like /0/ }
SET: $WestIsBest = "yes"
######################################################################################
Here is the output from my print commands for one host.
78 = $EastPingLatency
\d+ = $EastPingLatency in the next trigger-command in the same trigger
25 = $WestPingLatency
\d+ = $EastPingLatency after using in an EXPR same trigger-command as previous just ordered before the expression
25 = $WestPingLatency
0 = $BestPing Boolean value of EXPR will always equal 0 reguardless of east and west latency values
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-25-2017 06:36 PM
Re: scoping, defining them at the Action level should make them accessible in all lower-level triggers. That will also work at the Script-Variables level but then those are needlessly presented to you every time you run the script.
I'm not spotting what is causing the result that you show, but I do have a couple suggestions:
1) Use the built-in regex tester to get your variables and template working with sample device outputs. That's a much faster way than editing and running the script against a device:
https://netmri.house.gov/netmri/ccs/tx/regex_test/index.tdf
There is a link to that in the Scripts -> Edit section, but you can just paste it into a window/tab.
2) I'm not sure why you're matching on portions of the SCP-server IP address instead of just declaring the variable as type IPaddress, given that you only have two possibilities.
I have had trouble in the past getting regex to "do what I want" in a template definition. It *should* work, but I wonder if that's why the "\d..." is showing up in the resulting string.
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-25-2017 06:42 PM
And one more thought.... your aim with all of this is to choose a server based on latency to improve the throughput of an image file copy. Since SCP is TCP-based, I suggest you consider config mods such as:
ip tcp mss 1460
ip tcp selective-ack
ip tcp window-size nnnnn
ip tcp path-mtu-discovery
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-27-2017 11:56 AM
The TCP tuning and MTU stuff was already setup, what I am trying to do it distribute the loading of and IOS image across a large network and pick the SCP server that is the best. There can be more than 80ms latency This was just another attempt to get the EXPR funtion to work for me. I was using this method to make sure I had the scoping right. The next attempt is I am going to try to use custom fields and see if I can make them work with an EXPR funtion. Something really strange is happening with using the EXPR and I just cannot figure out what is happening. I have litterly tried everything I can think of and I am not getting the behavior I would expect.
Re: How to properly use greather than and less than with an action-command?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
10-02-2017 10:19 AM
I finally figured it out and have a script working.
########################################################################
##
## Use PING from the Cisco router to the SCP server to get the best
## server based on average latency
##
#########################################################################
Action:
Ping SCP-EAST
Action-Description:
Execute a ping
Action-Commands:
ping $scp_east
Output-Triggers:
Process PINGRATEEAST
#########################################################################
Action:
Ping SCP-WEST
Action-Description:
Execute a ping
Action-Commands:
ping $scp_west
Output-Triggers:
Process PINGRATEWEST
#########################################################################
Trigger:
Process PINGRATEEAST
Trigger-Description:
Get the ping latency rate to select the East SCP server
Trigger-Variables:
$PingLatencyEast int
Trigger-Template:
round-trip min\/avg\/max = \d{1,3}\/[[$PingLatencyEast]]\/\d{1,3} ms
Trigger-Commands:
SET: $EastLatencyCollected = "yes"
#########################################################################
Trigger:
Process PINGRATEWEST
Trigger-Description:
Get the ping latency rate to select the West SCP server
Trigger-Variables:
$PingLatencyWest int
Trigger-Template:
round-trip min\/avg\/max = \d{1,3}\/[[$PingLatencyWest]]\/\d{1,3} ms
Trigger-Commands:
SET: $WestLatencyCollected = "yes"
#########################################################################
Action:
GET BEST SERVER
Action-Description:
Get the best latency SCP server
Action-Filter:
$EastLatencyCollected eq "yes" and $WestLatencyCollected eq "yes"
Action-Commands:
EXPR: $BestPing = $PingLatencyEast < $PingLatencyWest
SET: $BestPingCollected = "yes"
Action-Commands: { $BestPingCollected eq "yes" and $BestPing like /1/ }
SET: $EastIsBest = "yes"
Action-Commands: { $BestPingCollected eq "yes" and $BestPing like /0/ }
SET: $WestIsBest = "yes"