cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
606
Views
0
Helpful
4
Replies

Velocity Hostname Variable manipulation fails

econstas
Level 1
Level 1

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

 

 

1 Accepted Solution

Accepted Solutions

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. 

 

 

View solution in original post

4 Replies 4

Preston Chilcote
Cisco Employee
Cisco Employee

substringBefore must not be implemented.  Try using "split" function instead.

 

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

Preston Chilcote
Cisco Employee
Cisco Employee

You'll want to select which element in the "split" array to display:
#set($desc = $hostname.split('.')[0])

 

 

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.