solarwinds / orionsdk-python

Python client for interacting with the SolarWinds Orion API
Apache License 2.0
210 stars 89 forks source link

Sample for Adding Agent using the python SDK #48

Open gssajith opened 4 years ago

gssajith commented 4 years ago

What is the best way to install agent (add agent) to a newly created VM in the network? Tried Orion.AgentManagement.Agent.Deploy but not fruitful. Is there any example somewhere?

Method1:

props = {
        "Name": "<AGENTNAME>",
        "Hostname": "<HOSTNAME>",
        "DNSName": "<DNSNAME>",
        "IP": "<IP>",
        "OSVersion": "<OS Version>",
        "PollingEngineId": 9,
        "ConnectionStatus": 0,
        "ConnectionStatusMessage": "Initial API insertion - connection pending",
        "AgentStatus": 0,
        "AgentStatusMessage": "Unknown",
        "Mode": 0,
        "AutoUpdateEnabled": True
    }

response = swis.invoke('Orion.AgentManagement.Agent', 'Deploy', **props)

Failed with: _Traceback (most recent call last): File "./add_agent.py", line 52, in main() File "./addagent.py", line 45, in main response = swis.invoke('Orion.AgentManagement.Agent', 'Deploy', **props) TypeError: invoke() got an unexpected keyword argument 'Name'

Method2:

response = swis.invoke('Orion.AgentManagement.Agent', 'Deploy', 9, "<AGENT_NAME>", "<HOST_NAME>", "<DNSName>",
                        "<IP>","<OSVersion>", "<PolingEngineID>","<AgentStatus>0")

Failed with: _Traceback (most recent call last): File "./add_agent.py", line 53, in main() File "./add_agent.py", line 46, in main "10.201.16.11","7.7", "9","0") File "/usr/lib/python2.7/site-packages/orionsdk/swisclient.py", line 31, in invoke "Invoke/{}/{}".format(entity, verb), args).json() File "/usr/lib/python2.7/site-packages/orionsdk/swisclient.py", line 63, in _req resp.raise_for_status() File "/usr/lib/python2.7/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Agent '"' must be assigned to existing polling engine for url: https://solarwindsEndpint:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.AgentManagement.Agent/Deploy_

Mesverrum commented 4 years ago

The argument is not called name, it is called agentname

The majority of the good full examples are under the powershell section as that is what the majority of Orion admins are using. See this one:

https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/DeployAgentViaVerb.ps1

Mesverrum commented 4 years ago

In fact looking at your code it appears you are just trying to populate all the default fields of an agent row in the db. That is not the way the SWIS verbs work at all. They all have pre-defined arguments. You will have a MUCH easier time if you install the Orion SDK on a Windows box to learn to navigate the table relationships verbs, otherwise it is a lot of work to constantly be looking up the syntax for everything in the schema and from the swagger.

http://solarwinds.github.io/OrionSDK/2019.4/schema/index.html http://solarwinds.github.io/OrionSDK/swagger-ui/

gssajith commented 4 years ago

Thanks for the guidelines