This template takes user input of old site prefix and new site prefix then does string manipulation to allow you to update this. This template requires you to update two variables used to hold in your company's domain name. This script template does NOTHING if no domain name is configured on your cisco IOS devices so it wont leak. This also after renaming regenerates the SSH keys as well as turning off some weak ssh algorithms. If you do NOT want that to be pushed out - by all means edit and remove those lines to fit your team/company's standards.
This will also preserve all of the hostname past the designated site code prefix and ensure it gets carried over.
The code runs without really using the @altdomainName variable but it is there as a safeguard to help cover all scenarios that occur with string manipulation. Also, I am not using the indexOf method as in my testing it worked only 1/10th of the time so I hard code the prefix. This works for me and my team as we are just wanting to finally fix our legacy site codes that are no longer uniform with new standards en masse.
If in your testing the indexOf method works for you, then update the template. This was all tested/developed under SolarWinds Observability Self-Hosted Advanced Enterprise 2025.1.1.
The only limitation is that if you are wanting to update a substring located in the middle of your hostname or the end you will need to update the formulas used.
The domain name is being obtained because the @ContextNode.SysName variable is used which contains the fully qualified name of the device.
Again, if no domain is configured this does NOTHING in its current state.
This also does not automatically save the config unless you check the box for NCM to save config to NVRAM for you.
Variables to update:
@domainName = '.mydomain.com'
@altdomainName = '.mydomain.co'
Example of script:
If your hostname is: mySiteCode-restOfHostname.mydomain.com
You pass along old site code prefix: mySiteCode
You pass along new site code prefix: myNewSiteCode
Then your new hostname will be: myNewSiteCode-restOfHostname
The old sitecode prefix is replaced, restOfHostname is preserved and the .mydomain.com is removed.
Then the following code is ran to preserve SSH functionality:
ip ssh version 2
ip ssh dh min size 2048
no ip ssh server algorithm mac hmac-sha1
no ip ssh server algorithm mac hmac-sha1-96
no ip ssh server algorithm encryption 3des-cbc
no ip ssh client algorithm mac hmac-sha1
no ip ssh client algorithm mac hmac-sha1-96
no ip ssh client algorithm encryption 3des-cbc
crypto key generate rsa general-keys modulus 2048
ip ssh version 2
exit