-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create the 'dockercontainer' sensor? #118
Comments
I tested your code on my own Docker instance and it worked fine. Are you sure the ID your Docker server's PRTG device is 1754? I only get the error you get when I target a server that is not running the Docker Daemon My Docker Daemon runs on Windows; the contents of my {
"hosts": ["tcp://0.0.0.0:2376", "npipe://"],
"data-root": "d:\\docker",
"experimental": true,
"tlsverify": false,
"tlscacert": "D:\\docker\\certs.d\\ca.pem",
"tlscert": "D:\\docker\\certs.d\\server-cert.pem",
"tlskey": "D:\\docker\\certs.d\\server-key.pem"
} |
Well, the device ID is not 1754 because I just entered a random number in the code excerpt. I think I had some encoding issues with the key and cert string but this should be fixed now. I guess this was the reason the connection to the docker-daemon failed. I also noticed that I haven't used the most recent version. (I used 0.9.7) Now I tried to send the requests ( But now I'm getting the following Error after the
Adding other sensors is still possible. I have tried it with other hosts/device IDs as well and it did not work. The code I'm using now:
The debug output:
I really appreciate your help. |
Are you potentially able to elaborate on the "encoding issues" you're referring to? In my test I simply copied and pasted the details from my *.pem files; I'm not sure if your certificates include some random characters that potentially caused issues? PrtgAPI uses the following flow to implement the logic required by this API
When you execute requests using the PRTG UI, generally speaking PRTG uses POST in conjunction with cookies and implements appropriate systems to always keep your cookies "active". Based on my testing, using POST in conjunction with the standard username/passhash fields does not work. As evidence has shown we can get away with using GET for almost all requests, we use GET almost everywhere in PrtgAPI, and haven't needed to develop our own cookie management system. As it happens Some questions:
|
Also interesting is that my certificate key begins with These are the commands I used to generate the required *.pem files from my domain's wildcard SSL PFX
(obviously you'll want to backup your existing certs and adjust the filenames/daemon.json paths appropriately) |
Okay, so first I tried to get the certificate and the key directly from the files via I'm using PRTG Version 19.2.50.2842 I used GET requests only in Postman without touching the cookie tab (maybe postman does something automatically?). My results from trying to debugg the HTTPS traffic to the PRTG-server via Fiddler:
All there requests returned a HTTP 200 status The last request returned:
A request to I then copied the requests from Fiddler and tried sending the requests via Postman. I got the same result from the
which worked just fine and returned a table with the containers running on the host. |
I think I may have solved it! Are you doing this in PowerShell or the PowerShell ISE? If PowerShell, can you try using the ISE instead? I noticed when I type everything up in the ISE and hit F5 it runs without issue. When I save that script, open a regular PowerShell and then run the script, I get the same error as you! How can the same script generate different results in different circumstances? The answer is that the response URI returned in PowerShell contains newlines ( The solution to this is to simply modify the tmpid extraction regex to treat the input string as a single line. I'm not sure whether you need to be running your code in a script automatically all the time or whether this is just a one time thing, however are you able to advise if using the ISE resolves the issue? Regards, |
Yesss, via the ISE it works :) The plan was to start it automatically. What do I have to do for it? I didn't quite understand that part. Thank you for your efforts. |
Well, I haven't figured that out yet :P Every workaround I've tried so far doesn't work; the only way around it appears to be to fix it properly, internally. I'm not yet ready to release the next version of PrtgAPI, however in the meantime you can potentially clone the repo, apply the fix and then recompile it yourself
internal static PrtgResponse GetSensorTargetTmpId(HttpResponseMessage message) => Regex.Replace(message.RequestMessage.RequestUri.ToString(), "(.+tmpid=)(\\d+)(.*)", "$2"); to internal static PrtgResponse GetSensorTargetTmpId(HttpResponseMessage message) => Regex.Replace(message.RequestMessage.RequestUri.ToString(), "(.+tmpid=)(\\d+)(.*)", "$2", RegexOptions.Singleline);
|
Hi @H0wi, Please be advised PrtgAPI 0.9.10 has been released, which includes a fix for this issue. To update to the latest version of PrtgAPI run the command Update-Module PrtgAPI and then close and reopen PowerShell. Regards, |
Hey.
I'm trying to add the sensor for dockercontainers via the Powershell CLI
My code so far:
And I get the following error
New-SensorParameters : An unspecified error occurred while trying to resolve sensor targets. Specified sensor type may not be valid on this device, or sensor query target parameters may be incorrect. Check the Device 'Host' is still valid or try adding sensor with the PRTG UI.
I tried some variations and debugging the script and the creation process via the PRTG UI and noticed that the UI sends a
POST
request toaddsensor3.htm
but with my code aGET
request will be sent.Does anyone have any idea what I'm doing wrong or has a hint?
I feel like I'm missing something.
Thanks for your Help.
The text was updated successfully, but these errors were encountered: