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 Assign Agents to Pollers Based on a Custom Property


The use case here is to "load-balance" agents across pollers, but with a caveat that the actual agent machines (Citrix) are rebuilt every day, and then the agent MSI is called, with an MFT. However, there are multiple APEs, and since it's not possible in this scenario to use different MFTs we need a different approach

High-Level Design:

The workaround is to use a custom property assigned to each node, to track the preferred poller. When the agents come online they will automatically reconnect to the main poller (based on the MFT configuration). But we can use an alert then that compares the custom property value with each agents assigned engine. Then the alert trigger can call a powershell script, using the "Assigntoengine" verb.

To Configure

First create and assign a custom property. I created one called "preferredpoller", and assign to nodes. I used a list of values, to prevent typos, and pasted the names of the polling. To get the proper names you can query SWQL.

SELECT displayname, servertype from orion.Engines

Next, create the PowerShell script that will hold the code. I called mine Alert_Reset.ps1 and placed it in e:\scripts.  Into this I pasted the following. You can use whichever connect-swis approach you want. 

# Parameter help description
Param($nodeid, $enginename)

Import-Module SwisPowerShell

#set to "SilentlyContinue" for no logging, or "Continue" for logging
#$VerbosePreference = "Continue"  
#$logfile = ".\log.txt"
$now = Get-Date
write-verbose "Calling Script @ $now for node id $nodeid" 

# Build Connection to SWIS
$SwisHost = "localhost"
#$SwisCreds = Get-Credential -Message "Enter the username/password for '$SwisHost'"

Write-Verbose "Connecting to $SwisHost" 
#$SwisConnection = Connect-Swis -certificate -Hostname $SwisHost
#$SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds
$SwisConnection = Connect-Swis -Hostname $SwisHost -UserName REPLACE_WITH_USER -Password "REPLACE_WITH_PASSWORD" 

# Query for nodes meeting our requirements
$Swql = @"
SELECT 'agentid' as name, agent.agentid as value 
FROM Orion.AgentManagement.Agent AS Agent
where agent.NodeId = $nodeid
(select 'engineid' as name, engine.engineid as value 
from orion.engines as engine 
where engine.DisplayName like '%$enginename%')

Write-Verbose "Querying SWIS for Results" 
# Query SWIS
$results = Get-SwisData -SwisConnection $SwisConnection -Query $Swql

$agent = $results[0].value
$engine =  $results[1].value

Write-Verbose "Pointing agent id $agent to $enginename" 
Invoke-SwisVerb $SwisConnection Orion.AgentManagement.Agent AssignToEngine @($agent, $engine) 

 You also need to ensure that the SolarWinds SWIS PowerShell module is installed on the main server. (Run the following from an administrator PowerShell prompt).

Install-Module -Name SwisPowerShell -Scope AllUsers

To download an example of how to configure the alert, see this post. 

The logic for the alert trigger is some SWQL, and the reset is just when the trigger condition is no longer true.

For the trigger action, you can call the script above, and pass in the following arguments 

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "&  'E:\Scripts\Agent_Reset.ps1' -nodeid {N=SwisEntity;M=Node.NodeID} -enginename ${N=SwisEntity;M=Node.CustomProperties.PreferredPoller}"

(You can test the script manually using an example like below)