Skip to content
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

Add basic auth support to InfluxDB connection #1

Merged
merged 8 commits into from
Jun 16, 2020

Conversation

rloomans
Copy link

In theory, this is all that's needed to add Basic Auth support for the InfluxDB connections, but I won't get a chance to test it until tomorrow.

@mad-ady
Copy link
Owner

mad-ady commented Jun 15, 2020

I'm going to wait for you to try it first. I'm not 100% sure it will work. You're setting authentication for LWP, but InfluxDB::HTTP doesn't necessarily inherit the same parameters.
When you do test, please try different credentials for InfluxDB than Smokeping uses for user auth.

@rloomans
Copy link
Author

@mad-ady InfluxDB::HTTP reuses the same LWP::UA object for it's connection, so pulling that out and setting the authentication details with the credentials method works fine.

I've tested it now and I have measurements in my smokeping Influx database :)

@rloomans
Copy link
Author

@mad-ady You may want to do a squash commit when you merge: I accidentally included a commit where my Vim setup did a bunch of clean ups on the file. I've reversed that, but the commit history is a little ugly.

@mad-ady mad-ady merged commit c2034a8 into mad-ady:master Jun 16, 2020
@mad-ady
Copy link
Owner

mad-ady commented Jun 16, 2020

Thank you for your contribution

@rloomans
Copy link
Author

@mad-ady I've also sent you a couple of pull requests for the docker image... One that speeds it up a lot, and another that makes it a bit more user friendly.

@rloomans rloomans deleted the influxdb-auth branch November 24, 2020 07:24
mad-ady pushed a commit that referenced this pull request Dec 17, 2020
@rloomans: add basic auth support to influx db connection
rloomans added a commit to rloomans/SmokePing that referenced this pull request Jan 10, 2021
* Add debugging to see how configuration gets parsed

* Add configuration parsing support for InfluxDB section

* Load InfluxDB modules if the config demands it

* Add support for writing to influxdb, if configured

* Ignore debugging logs

* Add missing variable declaration

* Add missing commits

* Forgot to add the influxdb initialization code

* Add slave name as a Influx tag. Log influx insert errors

* Send to influxdb probe parameters prefixed with influx_, as tags

* Load InfluxDB modules unconditionally

* Refactor foreach -> for

Co-Authored-By: Tobias Oetiker <[email protected]>

* Whitespace and or changes

Co-Authored-By: Tobias Oetiker <[email protected]>

* Whitespace

Co-Authored-By: Tobias Oetiker <[email protected]>

* Whitespace

Co-Authored-By: Tobias Oetiker <[email protected]>

* Whitespace

Co-Authored-By: Tobias Oetiker <[email protected]>

* Cosmetic changes

Co-Authored-By: Tobias Oetiker <[email protected]>

* Cosmetic changes

Co-Authored-By: Tobias Oetiker <[email protected]>

* Count from zero

Co-Authored-By: Tobias Oetiker <[email protected]>

* Adjust index since counting from zero

Co-Authored-By: Tobias Oetiker <[email protected]>

* Adjust index since counting from zero

Co-Authored-By: Tobias Oetiker <[email protected]>

* Adjust index since counting from zero

Co-Authored-By: Tobias Oetiker <[email protected]>

* Adjust index since counting from zero

Co-Authored-By: Tobias Oetiker <[email protected]>

* Whitespace

Co-Authored-By: Tobias Oetiker <[email protected]>

* Cosmetic changes

Co-Authored-By: Tobias Oetiker <[email protected]>

* Whitespace

Co-Authored-By: Tobias Oetiker <[email protected]>

* Cosmetic changes

Co-Authored-By: Tobias Oetiker <[email protected]>

* Refactor foreach -> for

Co-Authored-By: Tobias Oetiker <[email protected]>

* Add support for generic influxdb tags

* Add more debugging for failed inserts, fix function definition

* Tag the master when exporting to InfluxDB

* Add basic auth support to InfluxDB connection (mad-ady#1)

@rloomans: add basic auth support to influx db connection

* Send the timestamp received from the slave instead of the current time (to support playback of slave cached data)

* Remove generic tags and allow any names for tags

Co-authored-by: Tobias Oetiker <[email protected]>
Co-authored-by: Robert Loomans <[email protected]>
rloomans pushed a commit to rloomans/SmokePing that referenced this pull request Oct 5, 2021
@thalla2
Copy link

thalla2 commented Apr 4, 2024

I'm not sure this still works, or perhaps it was initially designed for Influx 1, which doesn't work with influx 2. As I'm not a developer by any means, I've been hacking the code with the help of ChatGPT and I think I got it working with Authorized keys, but really not sure. Wanted to pass along the code, if you wanted to take a look and submit a MR if correct.

/opt/smokeping/lib/InfluxDB/HTTP.pm

Remove this line:

my $response = $self->{lwp_user_agent}->post($uri->canonical(), Content => $measurement);

And add:

my $token = 'YourInfluxDBTokenHere'; # Replace with your actual InfluxDB token

my $response = $self->{lwp_user_agent}->post(
$uri->canonical(),
'Content' => $measurement,
'Authorization' => "Token $token",
);`

@mad-ady
Copy link
Owner

mad-ady commented May 20, 2024

I'm not sure this still works, or perhaps it was initially designed for Influx 1, which doesn't work with influx 2. As I'm not a developer by any means, I've been hacking the code with the help of ChatGPT and I think I got it working with Authorized keys, but really not sure. Wanted to pass along the code, if you wanted to take a look and submit a MR if correct.

/opt/smokeping/lib/InfluxDB/HTTP.pm

Remove this line:

my $response = $self->{lwp_user_agent}->post($uri->canonical(), Content => $measurement);

And add:

my $token = 'YourInfluxDBTokenHere'; # Replace with your actual InfluxDB token

my $response = $self->{lwp_user_agent}->post( $uri->canonical(), 'Content' => $measurement, 'Authorization' => "Token $token", );`

Sorry, I haven't been following this repo. Yes, I was using an older influxdb version. Didn't know it changed.

My suggestion is to push this change upstream (to Influxdb::HTTP maintainer), because I'm no longer involved in Smokeping development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants