02-13-2025 12:30 AM
Hello Everyone, I have been working on a template that uses the hostname as part of its CTS Creds, but Cat Center use the hostname with the fdqn while ISE doesn't use the FDQN tag. The first set command works as expected, but the issue is if I use substring or split or anything else, the hostname just outputs $device. I am wondering what am I doing wrong.
Code Snippet:
#set( $hostname = $__device.hostname)
hostname $hostname
#set( $device = $hostname.substringBefore(".") )
hostname $device
Result:
hostname siteid.mgmt.com
hostname $device
Config Command:
cts credentials id siteid.mgmt.com password 7 14341B180F0B7B7977
preferred output:
cts credentials id siteid password 7 14341B180F0B7B7977
Solved! Go to Solution.
02-16-2025 03:03 AM
Thanks for some reason it was not splitting on the " . " probably caused Velocity to think it was a wildcard or something, but your idea did lead me down to resolution.
#set( $hostname = $__device.hostname) ## Calls System Variable
#set( $ctsnameid = $hostname.split('\.')[0] ) ##
but it could also be a bit more compressed by:
#set( $test= $__device.hostname.split('\.')[0])
Thanks for the help.
02-13-2025 09:48 AM
substringBefore must not be implemented. Try using "split" function instead.
02-13-2025 04:45 PM - edited 02-14-2025 01:22 AM
I did the split option and getting java error. I am not sure how to pull the information or if I am coding it wrong.
#set( $hostname = $__device.hostname)
#set($desc = $hostname.split('.'))
hostname [Ljava.lang.String;@1d265e54
02-14-2025 09:19 AM
You'll want to select which element in the "split" array to display:
#set($desc = $hostname.split('.')[0])
02-16-2025 03:03 AM
Thanks for some reason it was not splitting on the " . " probably caused Velocity to think it was a wildcard or something, but your idea did lead me down to resolution.
#set( $hostname = $__device.hostname) ## Calls System Variable
#set( $ctsnameid = $hostname.split('\.')[0] ) ##
but it could also be a bit more compressed by:
#set( $test= $__device.hostname.split('\.')[0])
Thanks for the help.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide