lordmilko / PrtgAPI

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

Response status code does not indicate success: 500 (Internal Server Error) #312

Closed schoenm1 closed 2 years ago

schoenm1 commented 2 years ago

What's going on?

Have you ever had the Error Message from PRTGServer: 500 (Internal Server Error)? I try to add a snmplibrary Sensor with PRTGApi Module and can not add any sensor for a specific snmplibrary. (In PRTG GUI, the same snmplibrary is working well).

Steps to reproduce

PS C:\Users\user> $dev =Get-Device -id 61884
PS C:\Users\user> $param = $dev | New-SensorParameters -Rawtype snmplibrary -qt "netapp-node.oidlib" -dynamictype -Target *
PS C:\Users\user> $sensor = $dev | Add-Sensor $param -verbose
VERBOSE: Performing the operation "Add-Sensor" on target "Base Sensor (Destination: Netapp System (ID: 61884))".
VERBOSE: Add-Sensor: Synchronously executing request
https://myserver.domain.com/api/table.xml?content=sensors&columns=objid,name,probe,group,favorite,lastvalue,device,downtime,downtimetime,downtimesince,uptime,uptimetime,uptimesince,knowntim
e,cumsince,lastcheck,lastup,lastdown,minigraph,schedule,basetype,baselink,notifiesx,intervalx,access,dependency,position,status,comments,priority,message,parentid,tags,type,active&coun
t=*&filter_parentid=61884&username=user123&passhash=****
VERBOSE: Add-Sensor: Synchronously executing request https://myserver.domain.com/controls/addsensor2.htm?id=61884&sensortype=snmplibrary&username=user123&passhash=****
Add-Sensor : Response status code does not indicate success: 500 (Internal Server Error).
At line:1 char:19
+  $sensor = $dev | Add-Sensor $param -verbose
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Sensor], HttpRequestException
    + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,PrtgAPI.PowerShell.Cmdlets.AddSensor

In PRTG Serverlog, i found following logEntries: Core.log 2022-10-28 04:45:52.485849 ERRR TId 16024 Core> SendMetaRequest error(Cannot open file "C:\Program Files (x86)\PRTG Network Monitor\snmplibs\". The system cannot find the path specified) CoreWeb Server.log 2022-10-28 04:40:48.207350 ERRR TId 9288 CoreWebServer> Webserver: Error (/controls): Internal Error: Cannot open file "C:\Program Files (x86)\PRTG Network Monitor\snmplibs\". The system cannot find the path specified, URL: /controls/addsensor3.htm?id=61884&tmpid=1061& 2022-10-28 04:45:52.485849 ERRR TId 16024 CoreWebServer> Webserver: Error (/controls): Internal Error: Cannot open file "C:\Program Files (x86)\PRTG Network Monitor\snmplibs\". The system cannot find the path specified, URL: /controls/addsensor3.htm?id=61973&tmpid=1063&

What is the output of 'Get-PrtgClient -Diagnostic'? Tried with official 0.9.17 and 0.9.18-preview6


PSVersion      : 5.1.17763.2931
PSEdition      : Desktop
OS             : Microsoft Windows 10 Enterprise LTSC
PrtgAPIVersion : 0.9.18-preview.6
Culture        : de-CH
CLRVersion     : .NET Framework 4.8 (528049)
PrtgVersion    : 22.3.78.1873
PrtgLanguage   : english.lng```

I can not found any reason, why \snmplib is working from PRTG GUI, but can not be opened when using PRTGApi.

### Due Dilligance

- [X] It wasn't covered by the [wiki](https://github.com/lordmilko/PrtgAPI/wiki), I swear!
- [X] I have tried doing some basic research on this issue but haven't been able to come up with anything. Please help!
lordmilko commented 2 years ago

Does the very specific path C:\Program Files (x86)\PRTG Network Monitor\snmplibs\ exist? i.e. if you copy and paste that path into Windows Explorer and navigate to it (don't type it as there may be spelling differences) on the probe you attempted to add the folder to, does it work?

runnane commented 2 years ago

Hi,

I am seing this same issue.

Code ` var oidlib = client.GetSensorTypes(device.Id).First(t => t.Id == "snmplibrary").QueryTargets.First(t => t.Value.Contains("BGP-FULL"));

        DynamicSensorParameters dynamicSensorParameters = client.GetDynamicSensorParameters(
            deviceOrId: device, 
            sensorType: "snmplibrary",
            queryParameters: oidlib,
            timeout: 120
            );

        dynamicSensorParameters["interfacenumber__check"] = dynamicSensorParameters.Targets["interfacenumber__check"];

        client.AddSensor(device.Id, dynamicSensorParameters);`

Exception:

Synchronously executing request https://xx.xx.com/controls/addsensor2.htm?id=50532&sensortype=snmplibrary&username=xx&passhash=xx 568 [!] Exception caught System.Net.Http.HttpRequestException: Response status code does not indicate success: 500 (Internal Server Error). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()

Webserver logs: 2022-10-28 08:40:18.766766 ERRR TId 12084 CoreWebServer> Webserver: Error (/controls): Internal Error: Cannot open file "C:\Program Files (x86)\PRTG Network Monitor\snmplibs\". The system cannot find the path specified, URL: /controls/addsensor3.htm?id=50532&tmpid=566& 2022-10-28 08:41:30.141993 ERRR TId 8448 CoreWebServer> Webserver: Error (/controls): Internal Error: Cannot open file "C:\Program Files (x86)\PRTG Network Monitor\snmplibs\". The system cannot find the path specified, URL: /controls/addsensor3.htm?id=50532&tmpid=568&

Both the folder exists, and the file "BGP-FULL.oidlib" exists. It would seem something is missing in the query, so the webserver does not recieve the oidlib name? Adding manually with GUI works fine.

schoenm1 commented 2 years ago

Does the very specific path C:\Program Files (x86)\PRTG Network Monitor\snmplibs\ exist? i.e. if you copy and paste that path into Windows Explorer and navigate to it (don't type it as there may be spelling differences) on the probe you attempted to add the folder to, does it work?

Yes, the path exist on PRTG Core Server. I can open (copy/paste) on Windows Explorer and Windows-R (Run) copy/paste

lordmilko commented 2 years ago

Can you run Process Monitor while attempting to create the sensor using PrtgAPI and filter for all entries where the path contains snmplibs

Based on this, we may see some specific error messages - e.g. items with status NAME NOT FOUND or ACCESS DENIED which could give clues as to what's going on here

schoenm1 commented 2 years ago

With running Process Monitor on PRTG Core Server, one new line is shown, when process following command:

$sensor = $dev | Add-Sensor $param

grafik

grafik

Where should I see a NAME NOT FOUND or ACCESS DENIED ?

schoenm1 commented 2 years ago

I opened a Paessler case. Answer from Paessler Support:

Paessler tested my scenario and was able to reprocude the issue in browser (not in PRTG GUI, but API Calls). Example Paessler: Manual creating a sensor, the request is: addsensor2.htm (POST Request) with Payload &id=2445&sensortype=snmplibrary_nolist&preselection_snmplibrary_nolist=Host_Resources_mib.oidlib".

If API query is changed and https://server.domain.com/controls/addsensor2.htm?id=2445&sensortype=snmplibrary&id=2445&sensortype=snmplibrary_nolist&preselection_snmplibrary_nolist=Host_Resources_mib.oidlib&username=prtgadmin&password=prtgadmin is used (in Browser), it is working.

As a result Paessler Support suspect an error / missing update in the API and recommend to report this to @lordmilko

If I compare the Paessler API call with mine from debug output https://myserver.domain.com/controls/addsensor2.htm?id=61884&sensortype=snmplibrary&username=user123&passhash=****, there is missing the part _nolist&preselection_snmplibrary_nolist=Host_Resources_mib.oidlib. Does this help to reproduce the issue?

lordmilko commented 2 years ago

Please be advised I have managed to reproduce this issue and can confirm this is a bug in PrtgAPI

If you specify -Verbose to New-SensorParameters, you'll observe that PrtgAPI does actually do the right thing in that scenario. The issue is, once you've got your DynamicSensorParameters object and actually try and add it, you actually have to go through the whole addsensor2/3/4 dance again. PrtgAPI is not holding on to and re-specifying the sensor query target object that was previously specified; previous versions of PRTG let PrtgAPI get away with this incorrect behavior, however that is no longer the case.

runnane commented 2 years ago

Aha, is this fixable without breaking too much?

lordmilko commented 2 years ago

Hi all,

Please be advised a fix for this has now been pushed

Can you please follow the Manual installation instructions and advise whether PrtgAPI 0.9.18-preview.8 resolves your issue?

runnane commented 2 years ago

I, atleast, can confirm that this worked for me with the latest .net lib and additionally setting the DynamicType to true.

dynamicSensorParameters["interfacenumber__check"] = genericSensorTargets;
dynamicSensorParameters.DynamicType = true;
client.AddSensor(device.Id, dynamicSensorParameters);

Thank you for excellent following up (again), I have been stuck with this issue for quite some time :)

schoenm1 commented 2 years ago

The fix with 'PrtgAPI 0.9.18-preview.8' is working well in my case. thank a lot @lordmilko for your high-speed fix.