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.

Testing Agent with API

We have a lot of remote  Agent based nodes that get re-imaged and therefore we have an UP (new one) and a DOWN one. Sometimes the re-image fails to correctly install the agent I have a PowerShell script, that runs as a scheduled task, that finds Down agent polled Windows devices.

If the script finds an UP one with a matching node caption to the DOWN one, it deleted the DOWN one.

If the script finds an no UP one with a matching node caption to the DOWN one, it Unmanages the DOWN one.

The next challenge is to test the Unmanaged nodes to see if the agent is connectable again (the node was down, the WAN link was down, etc). I am trying to use the Orion.AgentManagement.Agent TestWithEngine verb to see if the agent is responding. Here is my code section and returns:

# Test Unamanaged ATMs connectability between the poller and the agent. Remanage any that have connectable agents

$agentToTest = Get-SwisData $swis 'SELECT Agent.AgentID, Agent.PollingEngineId, Agent.Node.Caption as Name, Agent.Node.NodeID FROM Orion.AgentManagement.Agent where Agent.Node.status = 9' ;

for ($i=0; $i -lt $agentToTest.Length; $i++)

{

    $testResults = Invoke-SwisVerb $swis Orion.AgentManagement.Agent TestWithEngine @($agentToTest[$i].AgentID, $agentToTest[$i].PollingEngineId)

    If($testResults.'#text' -eq "True")

    {

        $msg+= ("{0} INFO: Remanaging ATM {1} since it is now connectable. `n" -f `

        ((get-date -Format s).Replace("T", " ")), (($agentToTest[$i].name | Out-String).Replace("`n", "")) );

        $node = "N:" + $agentToTest.nodeID[$i]

        Invoke-SwisVerb $swis Orion.Nodes Remanage @($node)       

    }

    else

    {

       $msg+= ("{0} INFO: ATM {1} agent is still unconnectable. `n" -f `

        ((get-date -Format s).Replace("T", " ")), (($agentToTest[$i].name | Out-String).Replace("`n", "")) );

    }

}

The first get-SwisData call returns this:

AgentID    PollingEngineId      Name              NodeID

76          10                  Node026A154P      9690

159         10                  Node544A013P      9092

222         10                  Node211A202P      9536

256         10                  Node086A075P      9699

259         10                  Node521A271P      9679

265         10                  Node026A154P      9690

269         10                  Node086A075P      9699

270         10                  Node544A013P      9700

276         10                  Node544A013P      9708

Regardless of the state of the agent, I get the same thing as a return from $testResults = Invoke-SwisVerb $swis Orion.AgentManagement.Agent TestWithEngine @($agentToTest[$i].AgentID, $agentToTest[$i].PollingEngineId)

xmlns                                                                                            #text                                                                                         
-----                                                                                            -----                                                                                         
http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract                   true                                                                                          

I thought of using the DiscoverInterfacesOnNode but agent based nodes' NodeID returns InvalidNode as the Result regardless of the Agent state.

Any assistance will be appreciated.

...

  • So to be clear: the TestWithEngine verb is returning true even when the agent is actually down?

  • Yup.
    I have now gone to this code, which seems to be a reliable indicator:

    # Test Unamanaged ATMs connectability between the poller and the agent. Remanage any that have connectable agents

    $agentToRemanage = Get-SwisData $swis 'SELECT AgentStatus, ConnectionStatus, Agent.Node.Caption as Name, Agent.Node.NodeID FROM Orion.AgentManagement.Agent where Agent.Node.status = 9' ;

    if($agentToRemanage)

    {

        for ($i=0; $i -lt $agentToRemanage.Length; $i++)

        {

            # Review AgentStatus and ConnectionStatus. If both = 1, Remanage the node

            If(($agentToRemanage[$i].AgentStatus -eq 1) -and ($agentToRemanage[$i].ConnectionStatus -eq 1))

            {

                $msg+= ("{0} INFO: Remanaging ATM {1} since it is now connectable. `n" -f `

                ((get-date -Format s).Replace("T", " ")), (($agentToRemanage[$i].name | Out-String).Replace("`n", "")) );

                $node = "N:" + $agentToRemanage.nodeID[$i]

                Invoke-SwisVerb $swis Orion.Nodes Remanage @($node)      

            }

            else

            {

              $msg+= ("{0} INFO: ATM {1} agent is still unconnectable. `n" -f `

                ((get-date -Format s).Replace("T", " ")), (($agentToRemanage[$i].name | Out-String).Replace("`n", "")) );

            }

        }

    }

    Here is an example...

    # Test Unamanaged ATMs connectability between the poller and the agent. Remanage any that have connectable agents 

    $agentToTest = Get-SwisData $swis 'SELECT Agent.AgentID, Agent.PollingEngineId, Agent.Node.Caption as Name, Agent.Node.NodeID, Agent.Node.IP_address FROM Orion.AgentManagement.Agent where Agent.Node.status = 9' ; 

    for ($i=0; $i -lt $agentToTest.Length; $i++) 

        $testResults = Invoke-SwisVerb $swis Orion.AgentManagement.Agent TestWithEngine @($agentToTest[$i].AgentID, $agentToTest[$i].PollingEngineId) 

        If($testResults.'#text' -eq "True") 

        {  write-host "Start of test...`n"

        $agentToTest[$i]           

         $testResults

        Ping $agentToTest[$i].IP_Address /n  1

        write-host "End of test..."

        }

    }

    This returns this:

    Start of test...

    AgentID         : 259

    PollingEngineId : 10

    Name            : Node00521A271P

    NodeID          : 9679

    IP_address      : 10.1.1.1

    xmlns : http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract

    #text : true

    Pinging 10.1.1.1 with 32 bytes of data:

    Request timed out.

    Ping statistics for 10.1.1.1:

        Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

    End of test...

    I verified that the Agent is unreachable by Remanageing it and it went into a DOWN status

  • Yes, AgentStatus/ConnectionStatus are the way to go. I added them to https://github.com/solarwinds/OrionSDK/wiki/Agents to help the next one who needs them.

    After some investigation, here's what I learned about TestWithEngine:

    The purpose of TestWithEngine is to check whether an agent can communicate with a different polling engine than the one it is currently assigned to. If you reassign an agent without testing first and it turns out that a firewall blocks that communication, Orion would have no way to undo the change since it can no longer talk to the agent.

    This verb returns true immediately if you call it with the ID of the polling engine the agent is already assigned to, regardless of whether the agent is currently connected. Use the AgentStatusand ConnectionStatus properties if you just need to check on the status of the agent's normal connection.

  • Thank you for the TestWithEngine details.