lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

PRTG - Could not authenticate #351

Closed derSchweiger closed 1 year ago

derSchweiger commented 1 year ago

Describe the bug

It seems like that there is a bug similar as described in 181. When creating sensors based on SNMP, I receive the following error message:

Add-Sensor : Could not authenticate to PRTG; the specified username and password were invalid.
In H:\Scripting\A8N\Automatisierung\anx-win-roles-prtg\scripts\CreateWindowsPRTGDevice.ps1:106 Zeichen:47
+ ...     $sensor = Get-Device -Id $device.Id | Add-Sensor $params -Resolve
+                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Sensor], HttpRequestException
    + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,PrtgAPI.PowerShell.Cmdlets.AddSensor
$error[1].Exception.StackTrace
   bei PrtgAPI.Request.RequestEngine.ValidateHttpResponse(HttpResponseMessage responseMessage, PrtgResponse response)
   bei PrtgAPI.Request.RequestEngine.ExecuteRequest(PrtgRequestMessage request, CancellationToken token, Func`2 responseParser)
   bei PrtgAPI.Request.RequestEngine.ExecuteRequest(ICommandParameters parameters, Func`2 responseParser, CancellationToken token)
   bei PrtgAPI.PrtgClient.AddObjectInternalDefault(ICommandParameters internalParams, CancellationToken token)
   bei PrtgAPI.Request.VersionClient18_1.AddSensorInternal(ICommandParameters internalParams, Int32 index, CancellationToken token)
   bei PrtgAPI.PrtgClient.AddObjectInternal(Either`2 parent, NewObjectParameters parameters, CancellationToken token)
   bei PrtgAPI.PrtgClient.<>c__DisplayClass151_0`1.<AddObject>b__0(CancellationToken t)
   bei PrtgAPI.PrtgClient.ResolveWithDiff[T](Action`1 createObject, Func`2 getObjects, Func`3 exceptFunc, CancellationToken token, Action`2 errorCallback, Func`1 shouldStop, Boolean allowMultiple, String enhancedResolutionError)
   bei PrtgAPI.PrtgClient.AddObject[T](Either`2 parent, NewObjectParameters parameters, Func`3 getObjects, Boolean resolve, CancellationToken token, Action`2 errorCallback, Func`1 shouldStop, Boolean allowMultiple)
   bei PrtgAPI.PowerShell.Base.NewObjectCmdlet.<>c__DisplayClass6_0`1.<AddAndResolveObject>b__0()
   bei PrtgAPI.PowerShell.Base.NewObjectCmdlet.AddAndResolveRunner[T](Func`1 addObject)
   bei PrtgAPI.PowerShell.Base.AddObject`2.ExecuteOperationAction(Int32 destinationId)
   bei PrtgAPI.PowerShell.Base.PrtgOperationCmdlet.ExecuteOperation(Action action, String progressMessage, Boolean complete, Boolean incrementRecord)
   bei PrtgAPI.PowerShell.Base.AddObject`2.AddObjectInternal(Int32 destinationId)
   bei PrtgAPI.PowerShell.Cmdlets.AddSensor.ProcessRecordEx()
   bei PrtgAPI.PowerShell.Base.PrtgCmdlet.ExecuteWithCoreState(Action action)
   bei System.Management.Automation.CommandProcessor.ProcessRecord()

There are no issues while creating or deleting the device. Seems like the bug came with one of the newest PRTG updates. Details about my environment:

Steps to reproduce

$params = Get-Device -Id $device.Id | New-SensorParameters -RawType snmptraffic
$params.interfacenumber__check = $params.Targets["interfacenumber__check"] | Where-Object {($_.Name -like "*Ethernet Traffic*" -OR $_.Name -like "*Ethernet? Traffic*") -AND $_.Properties -like "*Connected*"}
$sensor = Get-Device -Id $device.Id | Add-Sensor $params -Resolve

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

PSVersion      : 5.1.19041.3031
PSEdition      : Desktop
OS             : Microsoft Windows 10 Pro
PrtgAPIVersion : 0.9.18
Culture        : de-AT
CLRVersion     : 528372
PrtgVersion    : 23.3.86.1520
PrtgLanguage   : english.lng
lordmilko commented 1 year ago

Can you please try the latest pre-release as described in #345

derSchweiger commented 1 year ago

Yep, it's working. Thank you very much and sorry for the duplicate!

mhcmind commented 1 year ago
2023-09-01 14_01_48-mw-v-mhc-win - Remote Desktop Connection

Working great in this one