lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Add-Device with Parmeter not working anymore #276

Closed schoenm1 closed 2 years ago

schoenm1 commented 2 years ago

Describe the bug

We have an automation script. Before PRTG Update to 21.4.73.1656+, everything was working. But no, the script can not add a device anymore. In our script: $Device = $DeviceGroup | Add-Device $currentRow.Name $currentRow.Host

[DBG]: PS C:\Visual_Studio\net-team\monitoring\macd> $DeviceGroup | Add-Device $currentRow.Name $currentRow.Host

'Add-Device' failed to resolve device: object is still being created. Retries remaining: 4
'Add-Device' failed to resolve device: object is still being created. Retries remaining: 3
'Add-Device' failed to resolve device: object is still being created. Retries remaining: 2
'Add-Device' failed to resolve device: object is still being created. Retries remaining: 1
Add-Device : Could not resolve object: PRTG is taking too long to create the object. Confirm the object has been created in the Web UI and then attempt resolution again manually.
At line:1 char:16
+ $DeviceGroup | Add-Device $currentRow.Name $currentRow.Host
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Device], ObjectResolutionException
    + FullyQualifiedErrorId : PrtgAPI.ObjectResolutionException,PrtgAPI.PowerShell.Cmdlets.AddDevice

=> Device is added in PRTG / only response is missing Same issue when I change command to Add-Device -Name $currentRow.Name -Host $currentRow.Host -Destination $DeviceGroup But when I try to add a device manually, it is working.

Add-Device -Name bla -Host 1.2.3.4  -Destination $DeviceGroup

Name                        Id     Status      Host            Sensors    Group                     Probe
----                        --     ------      ----            -------    -----                     -----
bla                         52373  Up          1.2.3.4         0          Test-Group            LocalProbe

Even if I entert the string from param manually, it is working

[DBG]: PS C:\Visual_Studio\net-team\monitoring\macd> $currentRow.Name
 su-sw-3og03
[DBG]: PS C:\Visual_Studio\net-team\monitoring\macd> $currentRow.Host
10.10.10.106
[DBG]: PS C:\Visual_Studio\net-team\monitoring\macd>  $DeviceGroup | Add-Device "su-sw-3og03" "10.10.10.106"

Name                        Id     Status      Host            Sensors    Group                     Probe
----                        --     ------      ----            -------    -----                     -----
su-sw-3og03              52374  Up          10.10.10.106   0          Test-Group             LocalProbe

Steps to reproduce

One different I found with '-verbose' command. This could explain the issue.

Working:
Add-Device -Name "su-sw-3og03" -Host "10.10.10.106" -Destination $DeviceGroup -verbose
https://prtg.domain.com/adddevice2.htm?name_=su-sw-3og03&host_=10.10.10.106&ipversion_=0&discoverytype_=0&discoveryschedule_=0&id=16768&username=myuser&passhash=******
=> no "+" before "su-sw-3og3

Not working:
And here is the point I found.
Write-Host "MyString = '$($currentRow.Name)'"
MyString = ' su-sw-3og03' => Leading Space in String before 'su-sw-3og3'
If I try this with fix value (no param) -> same issue.
Add-Device -Name " su-sw-3og3" -Host "10.10.10.106" -Destination $DeviceGroup -verbose
https://prtg.domain.com/adddevice2.htm?name_=+su-sw-3og3&host_=10.10.10.106&ipversion_=0&discoverytype_=0&discoveryschedule_=0&id=16768&username=myuser&passhash=******
=> "+" before "su-sw-3og3

Could this be a general issue. Is it possible you can add this to the PRTGApi Module to catch the error or not to send the "+" sign?
It took me a long time to find the issue (hope this there is not a 2nd issue". Other PRTGApi User should not be affected with same issue (I think this is (again) a PRTG Issue and not PRTGAPI, but you can handle this error where Paessler will not).

What is the output of 'Get-PrtgClient -Diagnostic'?

PSVersion      : 5.1.17763.2268
PSEdition      : Desktop
OS             : Microsoft Windows 10 Enterprise LTSC
PrtgAPIVersion : 0.9.17
Culture        : de-CH
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 21.4.73.1656
PrtgLanguage   : Unknown

Additional context

No response

lordmilko commented 2 years ago

Hi @schoenm1,

So are you saying the issue is that in your CSV, there is a leading space before "su-sw-3og3"?

schoenm1 commented 2 years ago

Hi @lordmilko Yes, I found this issue because there was a leading space in my excel/csv. " su-sw-3og3" and not "su-sw-3og3" But even if I try to use PRTGApi wich 'Add-Device -Name ' and a leading space in <myname<, I won't get a reply from PRTG Server that the object was created.