This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

How to automate port shut down not used for more than 30 days

I've heard UDT users would like to somehow automate port shut down for non-used ports. This is a great functionality for UDT but it will take some time to bring it in OOTB. However I don't see a reason why to not provide decent workaround you may find useful.

What we need in order to accomplish this trick:

  1. UDT
  2. Latest version of Orion SDK installed on the UDT server.
  3. Access to Windows PowerShell (could be applied on Python, Perl or VBScript as well)
  4. User and Password into UDT
  5. Ten minutes of your time :-)

Install and configure your UDT

Simple start, install and configure your UDT. It must contain at least one Node with ports.

Install your Orion SDK

Orion SDK will provide API access to UDT database via secure methods. I don't expect any single problem during install process (link for download). My recommendation is to install as local Administrator.

If you run into any problem, please speak up in this forum on Thwack.

Load customized SWIS Schema for UDT Non-Used ports

Copy this file:UDT_Unused_Ports.xml into \Program Files (x86)\SolarWinds\Orion\Information Service\3.0\Schemas\

This is customized SWIS entity that allow us to read data from database safely via Information Service (not directly from SQL).

Open your PowerShell window

And now the real fun begins. Run your PowerShell Window and make sure that Orion SDK was successfully registered:

Type this command: Get-PSSnapin | where {$_.Name -eq "SwisSnapin"}) and hit enter key.

The result should looks like this:

pastedImage_9.png

If you didn't get this, simple type following command (will add PowerShell snappin from SDK)

Add-PSSnapin "SwisSnapin"


Now you have to setup connection to your database/UDT.

Type in following commands and change your $hostname to domain name or IP address of your UDT, $username to the username you want to use for connection and $password to your password (like $password = "solarwinds"). If you are using Eval of UDT and running the script from the same machine, keep it as it is below.


$hostname = "localhost"

$username = "admin"

$password = New-Object System.Security.SecureString  

$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$swis = Connect-Swis -host $hostname -cred $cred

OK, so we set up the connection, and now we can call an API method and get information about ports which hasn't been used for 30 days or more. Type in the command below and hit enter key:

$ports = Get-SwisData $swis 'SELECT Caption, Name, DaysUnused, PortID,NodeID FROM Orion.UDT.Custom

.UnunsedPorts WHERE (CASE WHEN DaysUnused=''Never'' THEN 31 ELSE DaysUnused END) > 30'


If you want to see what ports and where it will shut down (before the real action), run this command:


foreach ($port in $ports) {

write-hosts "Port to shut down:" $port.Name" on Node:"$port.Caption " not used for:"$port.DaysUnused" days"

}

pastedImage_5.png

Now if you're really sure about shutting those port down use this syntax:

foreach ($port in $ports) {

write-hosts "Shutting down:" $port.Name" on Node:"$port.Caption " not used for:"$port.DaysUnused" days"

Invoke-SwisVerb $swis Orion.UDT.Port AdministrativeShutdown @($port.NodeID, $port.PortID)

}


And this is really all you need. For the full automation, you can execute this script from Windows Scheduler every month.

*warning - this is customization which is not fully supported by SolarWinds support. However if something doesn't work, let us know via the comment section below and we will do our best to help you.