A few months ago, I really stated digging into the Orion SDK and I wanted to know more about ways to automate adding nodes to Orion. Sure, I can wait for the Network Discovery to kick off, but I’m impatient. I’ve gotten many of the parts together over time, but this is my first post where I put everything together. For this version, I use the PowerShell Snap-In. I will add an additional post later using the PowerOrion Module.
Normally I lay out each step, but I’ll just start with some pseudo-code to explain the steps.
<#
In this example we will be adding a Windows 2016 server and using a different monitored server as the "source" for the pollers to use.
#>
#region Automation Example
<#
--------------------------------------------------------------------------
Variables - at a minimum, we need
* IP - IP Address of the node to add
* Caption - name to give the device
* CredentialName - Credential name as stored in Orion
* ObjectSubType - External/ICMP/SNMP/WMI (Agent handled differently)
* PollerSourceNodeID - Similar type of node
--------------------------------------------------------------------------
#>
$IP = "10.1.100.27"
$Caption = "Test-WinCore"
$CredentialName = "Orion (Demo.Lab)"
$ObjectSubType = "WMI"
$PollerSourceNodeID = "38"
<#
--------------------------------------------------------------------------
Setup Connection
- connect to SolarWinds Information Service
--------------------------------------------------------------------------
#>
# Do we already have the connection? No, then set one up.
if ( -not $SwisConnection )
{
$SwisConnection = Connect-Swis -Hostname "10.196.3.50" -Credential ( Get-Credential -UserName "admin" -Message "Enter your Orion Credentials" )
}
<#
--------------------------------------------------------------------------
Collect Data from Orion
- Get the ID's for the Credential, the Polling Engine, and the Pollers
--------------------------------------------------------------------------
#>
# Credential ID
$CredID = Get-SwisData -SwisConnection $SwisConnection -Query "SELECT ID FROM Orion.Credential WHERE CredentialOwner = 'Orion' AND Name = '$CredentialName'"
# Polling Engine ID
$EngineID = Get-SwisData -SwisConnection $SwisConnection -Query "SELECT EngineID FROM Orion.Engines WHERE ServerTYpe = 'Primary'"
# Pollers to Use
$SwisPollers = Get-SwisData -SwisConnection $SwisConnection -Query "SELECT PollerType FROM Orion.Pollers WHERE NetObject = 'N:$PollerSourceNodeID' AND Enabled = 'True'"
<#
--------------------------------------------------------------------------
Steps to Create a Node
1) Create a "shell" node (basically a placeholder)
2) Assign the credentials to the node
3) Add the pollers to the device
--------------------------------------------------------------------------
#>
<#
--------------------------------------------------------------------------
Create Shell SWIS Object
We need the IP, the Engine, the ObjectSubType, the Caption, and the Type
--------------------------------------------------------------------------
#>
$ShellProps = @{
IPAddress = $IP
EngineID = $EngineID
ObjectSubType = $ObjectSubType
Caption = $Caption
EntityType = 'Orion.Nodes'
}
# Create the new 'shell' node
$NodeUri = New-SwisObject -SwisConnection $SwisConnection -EntityType "Orion.Nodes" -Properties $ShellProps
# Capture the 'shell' node's properties
$NodeProperties = Get-SwisObject -SwisConnection $SwisConnection -Uri $NodeUri
<#
--------------------------------------------------------------------------
Assign Credentials (which is a setting)
For the ID of the 'shell' node, we ask it about itself, then add the
type of credential (in this case WMI) and the value (the ID of the
credential.
--------------------------------------------------------------------------
#>
$Settings = @{
NodeID = $NodeProperties["NodeID"]
SettingName = "WMICredential"
SettingValue = $CredID
}
# Assign this setting
New-SwisObject -SwisConnection $SwisConnection -EntityType "Orion.NodeSettings" -Properties $Settings
<#
--------------------------------------------------------------------------
Add Pollers
This is a little more complex, but the gist is: using the list of pollers
that we are using for another similar device, add those pollers to this
device as well.
Normally this follows "MachineType" designations
--------------------------------------------------------------------------
#>
ForEach ( $SwisPoller in $SwisPollers )
{
Write-Host "Adding $( $SwisPoller ) to NodeID $( $NodeProperties["NodeID"] )"
$Poller = @{
NetObjectType = "N"
NetObjectID = $nodeProperties["NodeID"]
NetObject = "N:$( $nodeProperties["NodeID"] )"
PollerType = $SwisPoller
}
New-SwisObject -SwisConnection $SwisConnection -EntityType "Orion.Pollers" -Properties $Poller
}
<#
--------------------------------------------------------------------------
Poll it now!
This is equivalent of clicking "poll now" button.
--------------------------------------------------------------------------
#>
Invoke-SwisVerb -SwisConnection $SwisConnection -EntityName "Orion.Nodes" -Verb "PollNow" -Arguments "N:$( $NodeProperties["NodeID"] )"
#endregion Automation Example
I personally, prefer this way (instead of PowerOrion) due to some functionality that I can leverage using these lower level functions.
There’s a typo in your script. In the SwisPollers loop section (138 & 139) you’re calling “$nodeProps” which is not defined anywhere in the script. Changing to “$NodeProperties” resolved the cannot index in to null array error
Nice catch! I’ve updated the script to reflect the changes.