feat(check): MQTT, Kafka and RabbitMQ checks

MQTT signs in and, with a topic, waits for a message (retained ones
count) that may have to contain a text. Kafka fetches cluster metadata
from one or more brokers, checks that a topic exists with a leader for
every partition and can produce a message, with SASL PLAIN or SCRAM.
RabbitMQ signs in over AMQP, opens a channel and checks that a queue
exists. All connect through the network guard with optional TLS, and
the TLS modes and error redaction are now shared with the database
checks. Tested against an in-process MQTT broker and real Kafka and
RabbitMQ.

Refs #94

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 16:43:51 +01:00
1 parent fb03b28df7
commit 8ca56635cd
8 files changed
+545 -20

No files matched your search

+4 -19
View File
@@ -9,7 +9,6 @@ import (
"net"
"net/url"
"strconv"
"strings"
"sync"
"time"
@@ -53,7 +52,7 @@ type DBConfig struct {
// SecretFields lists the settings of t the API stores sealed.
func SecretFields(t Type) []string {
switch t {
case Postgres, MySQL, MSSQL, MongoDB, Redis:
case Postgres, MySQL, MSSQL, MongoDB, Redis, MQTT, Kafka, RabbitMQ:
return []string{"password"}
}
return nil
@@ -73,7 +72,7 @@ func (d dbCheck) validate(target string, config json.RawMessage) (json.RawMessag
if c.TLS == "" {
c.TLS = "require"
}
if c.TLS != "disable" && c.TLS != "require" && c.TLS != "verify" {
if !validTLSMode(c.TLS) {
return nil, invalid("invalid_config")
}
if len(c.User) > 200 || len(c.Password) > 500 || len(c.Database) > 200 || len(c.Query) > 2000 || len(c.Expect) > 500 {
@@ -96,11 +95,7 @@ func (d dbCheck) run(ctx context.Context, s Spec) Outcome {
return Outcome{Error: "invalid configuration"}
}
dialer := netguard.Dialer(s.AllowPrivate, s.Timeout)
host, _, _ := net.SplitHostPort(s.Target)
var tlsConfig *tls.Config
if c.TLS != "disable" {
tlsConfig = &tls.Config{ServerName: host, InsecureSkipVerify: c.TLS == "require"} //nolint:gosec // "require" encrypts without verifying, as chosen per monitor
}
tlsConfig := tlsFor(c.TLS, s.Target)
var got string
switch d.typ {
case Postgres:
@@ -115,7 +110,7 @@ func (d dbCheck) run(ctx context.Context, s Spec) Outcome {
err = pingRedis(ctx, s.Target, c, dialer, tlsConfig)
}
if err != nil {
return Outcome{Error: describeDBErr(err, c.Password)}
return Outcome{Error: redact(err, c.Password)}
}
if c.Expect != "" && got != c.Expect {
return Outcome{Error: fmt.Sprintf("query returned %q, expected %q", truncate(got, 100), truncate(c.Expect, 100))}
@@ -123,16 +118,6 @@ func (d dbCheck) run(ctx context.Context, s Spec) Outcome {
return Outcome{OK: true}
}
// describeDBErr shortens driver errors and makes sure they never repeat the
// password, which some drivers include in connection errors.
func describeDBErr(err error, password string) string {
msg := err.Error()
if password != "" {
msg = strings.ReplaceAll(msg, password, "***")
}
return truncate(msg, 300)
}
func queryPostgres(ctx context.Context, target string, c DBConfig, d *net.Dialer, tlsConfig *tls.Config) (string, error) {
u := url.URL{Scheme: "postgres", Host: target, Path: "/" + c.Database}
if c.User != "" {