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 Update Agent via API (Invoke-SwisVerb)?

Hello,

Does anyone know how to use the API to initiate an update of the Orion Agent?  It looks like I need to provide 'SolarWinds.AgentManagement.Contract.Models.AgentRecord' data plus a boolean (I assume true/false), but I'm not sure how to construct the AgentRecord.

I'm trying to do it via PowerShell, i.e.:

$agent = #details from 'SolarWinds.AgentManagement.Contract.Models.AgentRecord'
$updateRemoteSettings = $true
Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.AgentManagement.Agent -Verb UpdateAgent -Arguments @($agent, $updateRemoteSettings)

It looks like I need to add a LOT of data to that xml string.  Is there a better way?

(sorry for code context, PowerShell not an option in code block)

Parents
  • Hi, did you ever get this to work? I am also looking to initiate agent updates via PowerShell 

  • When I look at the Orion.AgentManagement.Agent.UpdateAgent function within the SWQL Studio, it has two parameters:

    • agent [SolarWinds.AgentManagement.Contract.Models.AgentRecord]
    • updateRemoteSettings [boolean]

    if I copy out that sample XML block and reformat it, I get:

    <Agent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.solarwinds.com/2013/AgentManagement">
    	<AgentGuid>00000000-0000-0000-0000-000000000000</AgentGuid>
    	<AgentId>0</AgentId>
    	<AgentStatus>Unknown</AgentStatus>
    	<AgentStatusData/>
    	<AgentStatusMessage/>
    	<AgentStatusTimeStamp>0001-01-01T00:00:00</AgentStatusTimeStamp>
    	<AgentVersion xmlns:d2p1="http://schemas.datacontract.org/2004/07/System">
    		<d2p1:_Build>-1</d2p1:_Build>
    		<d2p1:_Major>0</d2p1:_Major>
    		<d2p1:_Minor>0</d2p1:_Minor>
    		<d2p1:_Revision>-1</d2p1:_Revision>
    	</AgentVersion>
    	<AutoUpdateEnabled>false</AutoUpdateEnabled>
    	<CPUArch>Unknown</CPUArch>
    	<ConnectionStatus>Unknown</ConnectionStatus>
    	<ConnectionStatusMessage/>
    	<ConnectionStatusTimeStamp>0001-01-01T00:00:00</ConnectionStatusTimeStamp>
    	<DNSName/>
    	<Hostname/>
    	<IP/>
    	<LogLevel/>
    	<Mode>Auto</Mode>
    	<Name/>
    	<NetFrameworkRelease/>
    	<NodeId i:nil="true"/>
    	<OSArch>Unknown</OSArch>
    	<OSDistro/>
    	<OSType>Unknown</OSType>
    	<OSVersion/>
    	<PassiveAgentHostname/>
    	<PassiveAgentPort>0</PassiveAgentPort>
    	<Password/>
    	<PollingEngineIP/>
    	<PollingEngineId>0</PollingEngineId>
    	<PollingEngineName/>
    	<PollingEnginePort>0</PollingEnginePort>
    	<ProxyId>0</ProxyId>
    	<RegisteredOn>0001-01-01T00:00:00</RegisteredOn>
    	<ResponseTime>PT0S</ResponseTime>
    	<RuntimeOSDistro/>
    	<RuntimeOSVersion/>
    	<SID/>
    	<Type>FullFeaturedAgent</Type>
    </Agent>

    I'm not sure if you need all of the fields in the XML or just a few, but I'm going to do some quick testing with various degrees of completeness.  Stay tuned.

Reply
  • When I look at the Orion.AgentManagement.Agent.UpdateAgent function within the SWQL Studio, it has two parameters:

    • agent [SolarWinds.AgentManagement.Contract.Models.AgentRecord]
    • updateRemoteSettings [boolean]

    if I copy out that sample XML block and reformat it, I get:

    <Agent xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.solarwinds.com/2013/AgentManagement">
    	<AgentGuid>00000000-0000-0000-0000-000000000000</AgentGuid>
    	<AgentId>0</AgentId>
    	<AgentStatus>Unknown</AgentStatus>
    	<AgentStatusData/>
    	<AgentStatusMessage/>
    	<AgentStatusTimeStamp>0001-01-01T00:00:00</AgentStatusTimeStamp>
    	<AgentVersion xmlns:d2p1="http://schemas.datacontract.org/2004/07/System">
    		<d2p1:_Build>-1</d2p1:_Build>
    		<d2p1:_Major>0</d2p1:_Major>
    		<d2p1:_Minor>0</d2p1:_Minor>
    		<d2p1:_Revision>-1</d2p1:_Revision>
    	</AgentVersion>
    	<AutoUpdateEnabled>false</AutoUpdateEnabled>
    	<CPUArch>Unknown</CPUArch>
    	<ConnectionStatus>Unknown</ConnectionStatus>
    	<ConnectionStatusMessage/>
    	<ConnectionStatusTimeStamp>0001-01-01T00:00:00</ConnectionStatusTimeStamp>
    	<DNSName/>
    	<Hostname/>
    	<IP/>
    	<LogLevel/>
    	<Mode>Auto</Mode>
    	<Name/>
    	<NetFrameworkRelease/>
    	<NodeId i:nil="true"/>
    	<OSArch>Unknown</OSArch>
    	<OSDistro/>
    	<OSType>Unknown</OSType>
    	<OSVersion/>
    	<PassiveAgentHostname/>
    	<PassiveAgentPort>0</PassiveAgentPort>
    	<Password/>
    	<PollingEngineIP/>
    	<PollingEngineId>0</PollingEngineId>
    	<PollingEngineName/>
    	<PollingEnginePort>0</PollingEnginePort>
    	<ProxyId>0</ProxyId>
    	<RegisteredOn>0001-01-01T00:00:00</RegisteredOn>
    	<ResponseTime>PT0S</ResponseTime>
    	<RuntimeOSDistro/>
    	<RuntimeOSVersion/>
    	<SID/>
    	<Type>FullFeaturedAgent</Type>
    </Agent>

    I'm not sure if you need all of the fields in the XML or just a few, but I'm going to do some quick testing with various degrees of completeness.  Stay tuned.

Children
  • Wow - I overthought that way too much.  You can use the ApproveUpdate verb instead.

    # Get a list of Agents in Need of updates
    # Swap in the name/IP of your Orion server here
    $SwisHost = "kmsorion01v.kmsigma.local"
    if ( -not ( $SwisConnection ) ) {
        $SwisCreds = Get-Credential -Message "Enter Orion credentials to connect to '$SwisHost'"
        $SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds
    }
    # For the query, all we need is the AgentId and AgentStatusMessage (or AgentStatus [numerical]), but we pull the rest to make output prettier
    $AgentQuery = @"
    SELECT [Agent].AgentId
         , [Agent].Name
         , [Agent].DNSName
         , [Agent].IP
         , [Agent].AgentStatusMessage
    FROM Orion.AgentManagement.Agent AS [Agent]
    -- ** Optionally, you can just remove the double-dash below to only process those agents with say they need an update
    --WHERE [Agent].AgentStatusMessage = 'Update available'
    "@
    
    
    # Retrieve the list from the Orion Server
    $AgentsNeedingUpdate = Get-SwisData -SwisConnection $SwisConnection -Query $AgentQuery
    
    # Cycle through each agent
    ForEach ( $Agent in $AgentsNeedingUpdate ) {
        # if the agent shows that it needs an update then...
        if ( $Agent.AgentStatusMessage -eq 'Update available' ) {
            # call the verb
            $Results = Invoke-SwisVerb -SwisConnection $SwisConnection -EntityName "Orion.AgentManagement.Agent" -Verb "ApproveUpdate" -Arguments $Agent.AgentId
            # Check to see if it ran clean (no output)
            if ( $Results.nil ) {
                Write-Host "Agent for $( $Agent.Name ) [$( $Agent.DNSName ) / $( $Agent.IP ) is updating." -ForegroundColor Green
            }
            else {
                Write-Error -Message "Error detected in sending agent update request"
            }
        }
        else {
            # This particular agent doesn't need an update or is offline or something
            Write-Warning -Message "Agent for $( $Agent.Name ) [$( $Agent.DNSName ) / $( $Agent.IP ) has a current status of: $( $Agent.AgentStatusMessage )"
        }
    }

  • Added another bit to check if plugins also needed to be updated.  (Can just be added to the bottom of the above script)

    # Now let's see if there are any plugins that require updating
    $PluginQuery = @"
    SELECT [Agent].AgentId
         , [Agent].Name
         , [Agent].DNSName
         , [Agent].IP
         , [Agent].Plugins.PluginId
         , [Agent].Plugins.Version AS [PluginVersion]
    FROM Orion.AgentManagement.Agent AS [Agent]
    WHERE [Agent].AgentStatusMessage = 'Plug-in update required'
    "@
    
    # Get the List
    $PluginsToUpdate = Get-SwisData -SwisConnection $SwisConnection -Query $PluginQuery
    # Cycle through the list
    ForEach ( $Agent in $PluginsToUpdate ) {
        # Invoke the DeployPlugin verb with the AgentId and the PluginId
        # Note: if you use the "RedeployPlugin" verb it doesn't update, just sends out the current version again
        $PluginResults = Invoke-SwisVerb -SwisConnection $SwisConnection -EntityName "Orion.AgentManagement.Agent" -Verb "DeployPlugin" @( $Agent.AgentId, $Agent.PluginId )
        if ( $PluginResults.nil ) {
            Write-Host "Plugin '$( $Agent.PluginId )' for $( $Agent.Name ) [$( $Agent.DNSName ) / $( $Agent.IP ) is updating from '$( $Agent.PluginVersion )'" -ForegroundColor Green
        } else {
            Write-Error -Message "Unable to request '$( $Agent.PluginId )' update on $( $Agent.Name )"
        }
    }

  • Many thanks for this! I will give the script a try

  • Are you able to get the desired result with this script? May i know how to use it. I am not well versed in power shell so just want to know how to use it on orion server.

  • If you are running this on your Orion server, you can run the same script from above, but swap out the username/password for the $SwisConnection to use the -Certificate parameter instead.

    Lines 4-7 from the 'correct' answer above would just be converted to:

    $SwisConnection = Connect-Swis -Hostname $SwisHost -Certificate

    You'll need to make sure that the SwisPowerShell module is installed on the server (I personally do not do this because I don't like running these things on the server, but each to his/her own.)

    The second resource on my session from this year's THWACKcamp explains the why and how to install these things on your computers.

  • Hello, this seems so cool. But how do you upgrade old agent that are not seen by solarwinds as agent that need an update ?

    we have upgraded our installation a few days ago and we still have a lot of agent that have not yet been upgraded. my idea was to force the upgrade using the API however it seems that the is no way to force an upgrade if solarwinds has not discover that the agent is old...

    Any advice would be welcome :)

  • Interesting. If you edit the agents that are out of date, are they configured to be allowed to auto-update? If they show out of date and aren't showing as update needed, I'd think that's a bug of some sort. What version of SolarWinds Orion are you on, and have you considered opening a Support Case on that issue?

  • hi, we have updated our installation to 2020.2.6 HF4. the agents are all configured for autoupdate.

    I have opened a support case, but i just wanted to know if other users are experimenting the same behavior.

    for example one is in Updated in progress for a few days now and the second one is even not upgrading.

    and when i select the node i can't update it.

  • the agent and the server have already been restarted without any change :(

  • Any change if you restart the agent on those nodes?