I got some requests and I need your help. We would like to add a few http endpoint collectors but in order to get the results I have first to pass the proper login. This is a 3 step process and from bash I can do that as below example:
@ilyam8 I believe we could add support for cookie-based authentication.
If the go library can’t do exactly what’s described here (which is a bit tricky admittedly), we can split the task. As long as the library can send the cookie along, the step related to getting a valid cookie to use could be up to users to complete.
e.g.
Each job accepts a cookie filename as authentication method (full path, readable by the netdata user).
Users ensure that they produce and refresh these filenames via cron jobs running before the cookies expire.
If a configured cookie isn’t there or the response fails, we log the issue.
I was sure that somehow I can read the cookie, but yet, I can’t find an example or info how to read from go.d/httpcheck.conf , let’s say I have a file cookie.txt under /tmp or any other folder, how I will point my go.d collector to use that file as variable or use it as header within job?
I think we can try to add proper cookie auth support, but I need to set up a lab to test it. @pgro can you suggest an app with cookie auth so I can test it locally?
For now that’s perfectly fine, I just need a way to load the file to my job collector. Is there a way I can load the cookie from external file? Paypal also using same mechanism. I can generate the cookie with Curl and save it to a temp file, then I can use that file periodically in order to perform my http checks.
No, it is not possible now, but it is easy to add this functionality. Will you be able to help me to test that? You will need to compile go.d.plugin (needs golang installed or Docker) and replace the existing version with updated.
git clone https://github.com/ilyam8/go.d.plugin
cd go.d.plugin
git checkout http_cookie_file_option
hack/go-build.sh
sudo systemctl stop netdata
# adjust the path depends on your install prefix, could be `/opt/netdata/usr/libexec/netdata/plugins.d/go.d.plugin`
sudo cp bin/godplugin /usr/libexec/netdata/plugins.d/go.d.plugin
The updated version has cookie_file config option. Set it and start netdata (sudo systemctl start netdata) or better run the plugin in the debug mode.
You have a pretty old version of golang. You need either to compile on a server with new version or, if you have Docker engine installed, compile in a Docker container:
DEBUG ] httpcheck[http://10_1_1_1/vma/mail/msgs] httpcheck.go:90 using accepted HTTP statuses [200]
[ WARN ] httpcheck[http://10_1_1_1/vma/mail/msgs] collect.go:40 Get "http://10.1.1.1/vma/mail/msgs": net/http: invalid header field value for "Cookie"
[ INFO ] httpcheck[http://10_1_1_1/vma/mail/msgs] job.go:208 check success
[ INFO ] httpcheck[http://10_1_1_1/vma/mail/msgs] job.go:228 started, data collection interval 5s
[ DEBUG ] run[manager] run.go:43 tick 0
[ WARN ] httpcheck[http://10_1_1_1/vma/mail/msgs] collect.go:40 Get "http://10.1.1.1/vma/mail/msgs": net/http: invalid header field value for "Cookie"
CHART 'netdata.execution_time_of_httpcheck_http://10_1_1_1/vma/mail/msgs' '' 'Execution time' 'ms' 'go.d' 'netdata.go_plugin_execution_time' 'line' '145000' '5' '' 'go.d' 'httpcheck
'
My cookie file is structured as below
# HTTP Cookie File
# Generated by Wget on 2023-03-20 21:38:07.
# Edit at your own risk.
10.1.1.1.1 FALSE /vma FALSE 0 JSESSIONID 23B508B767344EA167A4EB9B4DA4E59F