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

feat: Implement byte matching in TCP query responses #1112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tacho
Copy link

@tacho tacho commented Aug 18, 2023

Currently the exporter only supports lines, which breaks byte-oriented protocols such as the PostgreSQL StartTLS handshake.

We also give a working example for Postgres in the sample configuration.

Fixes: #801

@tacho tacho force-pushed the fix-postgres-tls-probes branch from 21d61c5 to ac9bb34 Compare August 18, 2023 07:43
@Raymondmax
Copy link

Is there any ETA for this PR merge?

@tacho
Copy link
Author

tacho commented Oct 27, 2023

I was wondering the same - it's been two months without any reaction. Is this project dead, or abandoned?

@rj-home
Copy link

rj-home commented Dec 5, 2023

+1 on this PR, we have the same issue which will be fixed after the merge

@freeyoung
Copy link

+1 on this PR too, would be nice to have this builtin

@sonman
Copy link

sonman commented May 27, 2024

+1 if we can use blackbox exporter also for postgres

@SuperQ SuperQ requested review from mem and electron0zero May 27, 2024 09:48
@Raymondmax
Copy link

FYI, here's a demo code to get Postgres cert info via TrustManager when connecting to the server

https://github.com/Raymondmax/PostgresCert/blob/main/main.java

prober/tcp_test.go Outdated Show resolved Hide resolved
Currently the exporter only supports lines, which breaks byte-oriented
protocols such as the PostgreSQL StartTLS handshake.

We also give a working example for Postgres in the sample configuration.

Signed-off-by: Stanislav Grozev <[email protected]>
@tacho tacho force-pushed the fix-postgres-tls-probes branch from ac9bb34 to 6cd70e8 Compare July 23, 2024 11:24
@electron0zero electron0zero requested a review from SuperQ July 23, 2024 15:59
@@ -159,6 +160,31 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
probeFailedDueToRegex.Set(0)
send = string(qr.Expect.Regexp.Expand(nil, []byte(send), scanner.Bytes(), match))
}
if qr.ExpectBytes != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks OK to me.

I would prefer to have stronger validation in the configuration, because as this section of the code shows, it's possible to specify both a regular expression and the sequence of bytes to be read, and I'm not sure how that's going to play together. If you think specifying both at the same time makes sense, I would like to see an example (and also a test).

My hunch is that it has to be either the regular expression or the specific sequence of bytes, but not both at the same time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense it would be one or the other - protocols are either line oriented or not. I'll adjust the patch soon.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be awesome if we get this MR merged and release :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also want expect and expect_bytes to be mutually exclusive.

protocols are either line oriented or not. I'll adjust the patch soon.

@tacho is this done? I am happy to give it another review once the comments are addressed.

@gartemiev
Copy link

Any update on this?

@dtseiler
Copy link

dtseiler commented Dec 5, 2024

+1 would be great to be able to check my PG cert expiry via blackbox_exporter

@@ -159,6 +160,31 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
probeFailedDueToRegex.Set(0)
send = string(qr.Expect.Regexp.Expand(nil, []byte(send), scanner.Bytes(), match))
}
if qr.ExpectBytes != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also want expect and expect_bytes to be mutually exclusive.

protocols are either line oriented or not. I'll adjust the patch soon.

@tacho is this done? I am happy to give it another review once the comments are addressed.

@@ -182,9 +182,11 @@ regexp: <regex>,
[ source_ip_address: <string> ]

# The query sent in the TCP probe and the expected associated response.
# expect_bytes does exact byte-by-byte match.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we mention that expect and expect_bytes are mutually exclusive?

we do mention it for body and body_file in http_probe, and few other places.

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.

Unable to scrape Postgres cert metrics
10 participants