lordmilko / PrtgAPI

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

Could not retrieve PassHash from PRTG Server. #228

Closed Tann1th closed 3 years ago

Tann1th commented 3 years ago

Hi,

I've been using PrtgAPI for quite a while now (it has saved us days of adding devices and sensors to remote probe installs), but I've hit an issue. When working with on-premise installs of PRTG it works perfectly when connecting:

$prtgServer = "https://prtg.mycoolsite.com" $prtgUser = "myUsername" $prtgPass = "myPassword" Connect-PrtgServer $prtgServer (New-Credential $prtgUser $prtgPass))

However when we attempt to connect to a hosted install of PRTG it fails with the reply of "Could not retrieve PassHash from PRTG Server" (followed by the HTML of the login page: connection-error)

$prtgServer = "https://mycoolsite.my-prtg.com" $prtgUser = "myUsername" $prtgPass = "myPassword" Connect-PrtgServer $prtgServer (New-Credential $prtgUser $prtgPass))

Thanks, Kyle

lordmilko commented 3 years ago

Hi @Tann1th,

Are you able to check in the PRTG UI and see what version of PRTG it says its running?

Tann1th commented 3 years ago

Thanks for the fast response!

Version is showing as 21.3.69.1333+

lordmilko commented 3 years ago

My on-prem system is also running 21.3.69.1333 and does not have this issue. Are you able to advise whether PrtgAPI ever worked against the hosted version of PRTG?

Tann1th commented 3 years ago

I've as of yet never successfully connected to the hosted version. Have done many on-premise installs on both http and https and it's been flawless everytime.

Tann1th commented 3 years ago

I think I may have finally got a connection (it's now giving feedback that I have a connection if not using the -Force switch after specifying to use the password hash instead of an actual password), but am getting 404 errors when trying to get any data from the server:

$prtgServer = "https://mycoolsite.my-prtg.com/" $prtgUser = "myUsername" $prtgHash = "myPasswordHash"

Connect-PrtgServer $prtgServer (New-Credential $prtgUser $prtgHash) -PassHash -Force

PS C:> Get-PrtgStatus Get-PrtgStatus : Response status code does not indicate success: 404 (Not Found). At line:1 char:1

PS C:> Get-Probe Get-Probe : Response status code does not indicate success: 404 (Not Found). At line:1 char:1

lordmilko commented 3 years ago

Thanks @Tann1th,

Based on the information that has been provided I want to say that hosted instances of PRTG may in fact disable the PRTG API by default, if the PRTG API is even supported at all!

In regards to the passhash issue, according to the API documentation (under https://<your server>/api.htm?tabid=2) if you execute the API request in the address bar of your web browser

http://yourserver/api/getpasshash.htm?username=myuser&password=mypassword

e.g.

http://prtg.example.com/api/getpasshash.htm?username=prtgadmin&password=prtgadmin

it should give you your passhash that can you can use for executing API requests. Potentially you can try and do this and see what PRTG responds with in the web browser. Based on the error message you received, I expect that in fact PRTG will simply redirect you to the normal login screen, as if this API endpoint doesn't even exist at all.

You can also extract your passhash from the PRTG UI under your account, but only if your account is not AD integrated (which I would assume is what you have done?) however if you specify this along with -PassHash to PrtgAPI this does not really give you a connection per se; you've simply created a PrtgClient object that stores your server's connection details

Given that the /api/table.xml endpoint is returning 404 not found as well, this says to me this functionality has either been stripped or disabled in hosted instances of PRTG

As such, I would recommend reaching out to Paessler support regarding this. I will close this ticket for now, however please let me know what they have to say about this!

Regards, lordmilko

Tann1th commented 3 years ago

Awesome, thanks for the info; I'll reach out to them now and will update you on the outcome!

Thanks for taking the time to look into this.