feat: Allow specifying the ALPN
This commit is contained in:
parent
1e7e2ad81d
commit
52af228ce7
17
main.go
17
main.go
@ -22,15 +22,17 @@ import (
|
||||
type CertificateMetrics struct {
|
||||
Domain string
|
||||
Port int
|
||||
ALPN []string
|
||||
|
||||
ExpiryIn prometheus.Gauge
|
||||
IsValid prometheus.Gauge
|
||||
}
|
||||
|
||||
func NewCertificateMetrics(domain string, port int) CertificateMetrics {
|
||||
func NewCertificateMetrics(domain string, port int, alpn []string) CertificateMetrics {
|
||||
metrics := CertificateMetrics{
|
||||
Domain: domain,
|
||||
Port: port,
|
||||
ALPN: alpn,
|
||||
ExpiryIn: prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "cert_status_expiry_in",
|
||||
@ -59,8 +61,11 @@ func (c *CertificateMetrics) register(registry *prometheus.Registry) {
|
||||
}
|
||||
|
||||
func (c *CertificateMetrics) checkTls() {
|
||||
conn, err := tls.Dial("tcp", c.Domain+":"+fmt.Sprint(c.Port), &tls.Config{})
|
||||
conn, err := tls.Dial("tcp", c.Domain+":"+fmt.Sprint(c.Port), &tls.Config{
|
||||
NextProtos: c.ALPN,
|
||||
})
|
||||
if err != nil {
|
||||
log.Debugf("Failed to dial %s:%d@%s using ALPN %v: %v", c.Domain, c.Port, "tcp", c.ALPN, err)
|
||||
c.IsValid.Set(0)
|
||||
return
|
||||
}
|
||||
@ -107,9 +112,9 @@ func run(ctx *cli.Context) error {
|
||||
for _, d := range domains {
|
||||
log.Debugf("Parsing '%s'...", d)
|
||||
parts := strings.Split(d, ":")
|
||||
if len(parts) != 2 {
|
||||
if len(parts) != 3 {
|
||||
log.Errorf("Invalid domain format for '%s'", d)
|
||||
return errors.New("Invalid domain format: Expects <domain>:<port>")
|
||||
return errors.New("Invalid domain format: Expects <domain>:<port>:<alpn>")
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(parts[1])
|
||||
@ -119,9 +124,13 @@ func run(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
// Create the metric, and register it
|
||||
// TODO: Make this prettier
|
||||
alpn := strings.Split(parts[2], ";")
|
||||
log.Debugf("Using ALPNs: %v", alpn)
|
||||
metric := NewCertificateMetrics(
|
||||
parts[0],
|
||||
port,
|
||||
alpn,
|
||||
)
|
||||
metric.register(registry)
|
||||
metrics = append(metrics, metric)
|
||||
|
Loading…
Reference in New Issue
Block a user