How to Set Node Captions to Lower Case Host Name in SolarWinds Orion Using PowerShell

By default, SolarWinds Orion will use either the sysname it gets from the device via SNMP, WMI, or the agent, etc. when it sets the nodes name in the "caption" field. If it can't get the sysname, it will try to get a name from reverse DNS and use that if it is available. Unfortunately, this can leave the node names inconsistent where some will have be using a fully qualified domain name (FQDN) and other won't. Some will use capital letters, while others will be lower case. 

I wrote a PowerShell script which will truncate the name down to the hostname and convert all of the letters to lower case. This makes viewing a list of nodes much easier on the eyes when they are all consistent, especially if you have a touch of OCD. I have the full script available on GitHub here, if you'd like to download it.

I tried to dummy-proof the script a little bit. So, you'll notice that the first section will check that the OrionSDK is installed and that the snap-in has been loaded, which is a prerequisite requirement. 

The second section will prompt you for credentials to log into the SolarWinds SWIS API. I use the export-clixml and import-clixml cmdlets to store and retrieve the credentials. These cmdlets use the "Windows Data Protection API" to securely encrypt/decrypt the credentials.

The next section creates a connection to the SolarWinds SWIS API. It will check to see if there's already an "Orion" environment variable. If not, it will prompt you for the hostname or IP address of the primary Orion server and cache it in the "Orion" environment variable. That way it doesn't have to ask you for the Orion server again the next time you run the script.

I also use the "ScriptLogPath" environment variable to cache the directory where you want to store the script logs. If this hasn't been set yet, it will prompt you for a file path. The next section roll these logs if they are over 10 MB.

Finally we are getting to the guts of the script. First, we'll query the Orion API for nodes in the private IP space which have alphabetic characters, a period, and no spaces in it's name. I limited it to the private IP space because if it's an external node, the domain is probably more useful and probably wants to be preserved. If it has a period, it obviously isn't just a hostname. Finally, if it has a space, it's probably a custom caption of sort, so we won't mess with it.

The script takes all of the results from the query above, splits them at all of the periods and takes the first section for the new caption. It then converts that new caption, converts it to lower case and writes it back to the Orion API.

The final section of the script uses the ExecuteSQL verb in the Orion.Reporting path of the Orion API to get any remaining nodes that has a capital letter in it's name. We do it this way because the Orion API isn't able to use case sensitive regex to find the nodes. The Orion database typically uses SQL_Latin1_General_CP1_CI_AS for collation, which is case insensitive. By piping the SQL query into SQL through the ExecuteSQL verb, we can force it to use the Latin1_General_BIN collation for this query. We then manually build a URI for that node, convert the caption to lower case, and update the node via the Orion API.

I hope this is useful for you. As always, test any scripts before using them in production. Feel free to catabolize the parts that are important to you, and drop what isn't.

Full Script: Set-OrionCaptionToLowerCaseHostName.ps1

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Issue Where SolarWinds Orion Agents Show As Connected But They Are Not Updating Statistics (RESOLVED)

This issue can easily slip by unnoticed. All of that status indicators still show green, so everything is good, right? Not so! Statistics an...