lordmilko / PrtgAPI

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

PRTG-API does not work anymore since latest PRTG-Server Update #268

Closed Rottinator closed 2 years ago

Rottinator commented 2 years ago

Describe the bug

Hello, we've updated our PRTG version to 22.1.74.1869 from February 1st 2022. Since then write operations via the powershell API does not work anymore. (Changelog: https://www.paessler.com/prtg/history/stable) PRTG brings only the error message: Could not authenticate to PRTG; the specified username and password were invalid.

I think this may be related to the "Improved Security"-Changset: image

Steps to reproduce

Sample Code:
`Connect-PrtgServer -Server "http://myserver.de" (New-Credential "someusername" "somepassword");

$device = Get-Device -Id 5555;

$parameters = $device | New-SensorParameters -RawType httpdataadvanced;
`

Results in:
New-SensorParameters : Could not authenticate to PRTG; the specified username and password were invalid.

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

PSVersion      : 5.1.19041.1320
PSEdition      : Desktop
OS             : Microsoft Windows 10 Enterprise
PrtgAPIVersion : 0.9.16
Culture        : de-DE
CLRVersion     : 528372
PrtgVersion    : 22.1.74.1869
PrtgLanguage   : Unknown

Additional context

Read operations like Get-Device or Get-Group still works without problem. Write-Operations like New-SensorParameters or New-Sensor fails

No response

lordmilko commented 2 years ago

I've managed to replicate this issue; based on my analysis this is only affecting requests pertaining to creating new objects (as these rely on cookies instead to be "authenticated" and don't work when you explicitly specify credentials). I am investigating what exactly I need to do to get these working again

Regards, lordmilko

lordmilko commented 2 years ago

Hi @Rottinator,

I have pushed a new pre-release version of PrtgAPI which should include a fix for this issue

Are you able to try using the manual installation instructions to run the latest pre-release and advise whether the issue is now resolved?

Regards, lordmilko

Rottinator commented 2 years ago

Hi @lordmilko

I've downloaded the latest pre-release and the fix worked in all of our constellations.

Thanks for this quick fix!

Regards Rottinator

rickyrickuk commented 2 years ago

Hi @lordmilko I am having a similar issue after updating to the latest PRTG version. I downloaded the pre-release from the manual link (it still shows 0.9.16 - is that correct?) but after a 'remove-module -Name prtgapi' and then import-module I am still getting the authentication error when trying to create objects. Could you help please? Thanks

Rottinator commented 2 years ago

Hi @rickyrickuk, thats the wrong one. The correct one is 0.9.17-preview.10, so it looks like you downloaded not the correct one. I've got the correct one using the following link on the "manual installation instructions", linked from @lordmilko

image

rickyrickuk commented 2 years ago

Hi @rickyrickuk, thats the wrong one. The correct one is 0.9.17-preview.10, so it looks like you downloaded not the correct one. I've got the correct one using the following link on the "manual installation instructions", linked from @lordmilko

image

Thanks @Rottinator , that's the link I used, just downloaded again, file is called PRTGAPI.zip and inside the PrtgAPI.psd1 file it says :

Version number of this module.

ModuleVersion = '0.9.16'

Checking my version 👍

_**PS D:\PRTG-Scripts> get-module -Name prtgapi

PS D:\PRTG-Scripts> import-module "D:\PRTG-Scripts\PRTG-0.9.17PRE\prtgapi.psd1"

PS D:\PRTG-Scripts> get-module -name prtgapi

ModuleType Version Name ExportedCommands


Binary 0.9.16 prtgapi {Add-Device, Add-Group, Add-NotificationTrigger, Add-Sensor...}**_

Strange !

Richard

@lordmilko Could you advise what I am doing wrong please? :-)

SwissJay commented 2 years ago

Hi @rickyrickuk, thats the wrong one. The correct one is 0.9.17-preview.10, so it looks like you downloaded not the correct one. I've got the correct one using the following link on the "manual installation instructions", linked from @lordmilko image

Thanks @Rottinator , that's the link I used, just downloaded again, file is called PRTGAPI.zip and inside the PrtgAPI.psd1 file it says :

Version number of this module.

ModuleVersion = '0.9.16'

Checking my version 👍

_**PS D:\PRTG-Scripts> get-module -Name prtgapi

PS D:\PRTG-Scripts> import-module "D:\PRTG-Scripts\PRTG-0.9.17PRE\prtgapi.psd1"

PS D:\PRTG-Scripts> get-module -name prtgapi

ModuleType Version Name ExportedCommands

Binary 0.9.16 prtgapi {Add-Device, Add-Group, Add-NotificationTrigger, Add-Sensor...}**_

Strange !

Richard

@lordmilko Could you advise what I am doing wrong please? :-)

You're not doing anything wrong, that version number just didn't get updated. But check the version on fullclr\PrtgAPI.PowerShell.dll, you'll see it shows a file version of 0.9.16.0 but a product version of 0.9.17-preview10...

lordmilko commented 2 years ago

Get-PrtgClient -Diagnostic will also show you the version is 0.9.17-preview10

rickyrickuk commented 2 years ago

Thanks @lordmilko and @SwissJay

I checked the files that I am doing an import module on and the fullclr\PrtgAPI.PowerShell.dll one does show 0.9.17-preview10 but Get-PrtgClient -Diagnostic shows 0.9.16 still :

PS D:\PRTG-Scripts> get-prtgclient -Diagnostic

PSVersion : 5.1.14393.4583 PSEdition : Desktop OS : Microsoft Windows Server 2016 Standard PrtgAPIVersion : 0.9.16 Culture : en-GB CLRVersion : .NET Framework 4.8 (528049) PrtgVersion : 22.1.74.1869 PrtgLanguage : english.lng

A remove-module prtgapi followed by import-module "D:\PRTG-Scripts\PRTG-0.9.17PRE\prtgapi.psd1" should work shouldnt' it? Or do I need to restart any services or reboot?

lordmilko commented 2 years ago

Hi @rickyrickuk,

If you close all instances of PowerShell, then do Remove-Module PrtgAPI, or better yet go into C:\Program Files\WindowsPowerShell\Modules and delete the PrtgAPI folder that will ensure you are not accidentally importing the wrong version somehow

rickyrickuk commented 2 years ago

Hi @rickyrickuk,

If you close all instances of PowerShell, then do Remove-Module PrtgAPI, or better yet go into C:\Program Files\WindowsPowerShell\Modules and delete the PrtgAPI folder that will ensure you are not accidentally importing the wrong version somehow

Thanks @lordmilko, another instance of ps was running by another user ! All sorted now and auth errors gone too, cheers :-)

lordmilko commented 2 years ago

Please be advised PrtgAPI 0.9.17 has now been released

codepend commented 2 years ago

Thanks @lordmilko