Api Call – Adding Server

by Apr 10, 2014

Having issues using the API and powershell.

 

Here is my code:


    $postParams = @{"name"="$VMName";"description"="$Description";"hostname"="$VMName.igibsons.com";"groupId"=24;"type"="Server";"collectionMethod"=@{"connectionType"="agent";"useGlobalConnectionSettings"="true"}
                   }
    $PostParams = ConvertTo-Json $postParams
    Invoke-WebRequest -URI "uptime.igibsons.com:9997/.../elements" -Method POST -Body $postParams -Credential $UserCredentials

Here is what I get when I run it:


PS C:WINDOWSsystem32>     $postParams = @{"name"="$VMName";"description"="$Description";"hostname"="$VMName.igibsons.com";"groupId"=24;"type"="Server";"collectionMethod"=@{"connectionType"="agent";"useGlobalConnectionSettings"="true"}
                   }
    $PostParams = ConvertTo-Json $postParams

PS C:WINDOWSsystem32> $postParams
{
    "name":  "JOnTest1",
    "groupId":  24,
    "description":  "",
    "hostname":  "JOnTest1.igibsons.com",
    "type":  "Server",
    "collectionMethod":  {
                             "useGlobalConnectionSettings":  "true",
                             "connectionType":  "agent"
                         }
}

PS C:WINDOWSsystem32> Invoke-WebRequest -URI "uptime.igibsons.com:9997/.../elements" -Method POST -Body $postParams -Credential $UserCredentials


StatusCode        : 200
StatusDescription : OK
Content           : [{"description":"PROD Uptime
                    Monitoring","groupId":2,"hostname":"localhost","id":1,"isMonitored":true,"monitors":[{"elementId":1,"id":535,"isHidden":false,"isMonitored":true,"name":"Commvault
                    Communic...
RawContent        : HTTP/1.1 200 OK
                    Content-Length: 389015
                    Content-Type: application/json;charset=utf-8
                    Date: Wed, 09 Apr 2014 17:49:19 GMT
                    Expires: Thu, 01 Jan 1970 00:00:00 GMT
                    Set-Cookie: JSESSIONID=1wn0xf77t22gc...
Forms             : {}
Headers           : {[Content-Length, 389015], [Content-Type, application/json;charset=utf-8], [Date, Wed, 09 Apr 2014 17:49:19 GMT], [Expires, Thu, 01 Jan 1970 00:00:00 GMT]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 389015

I can’t get the server to show up in uptime.  Any ideas?  It’s getting a 200 code back.