1
0
mirror of https://github.com/ribbybibby/ssl_exporter.git synced 2025-07-12 23:50:14 +02:00
Files
ssl_exporter/prober/file.go

38 lines
796 B
Go
Raw Permalink Normal View History

2020-11-09 12:57:28 +00:00
package prober
import (
"context"
"fmt"
"github.com/bmatcuk/doublestar/v2"
"github.com/go-kit/log"
2020-11-09 12:57:28 +00:00
"github.com/prometheus/client_golang/prometheus"
2022-05-07 09:31:08 +01:00
"github.com/ribbybibby/ssl_exporter/v2/config"
2020-11-09 12:57:28 +00:00
)
2020-11-16 00:48:15 +00:00
// ProbeFile collects certificate metrics from local files
func ProbeFile(ctx context.Context, logger log.Logger, target string, module config.Module, registry *prometheus.Registry) error {
2020-11-09 12:57:28 +00:00
errCh := make(chan error, 1)
go func() {
files, err := doublestar.Glob(target)
if err != nil {
errCh <- err
return
}
if len(files) == 0 {
errCh <- fmt.Errorf("No files found")
} else {
errCh <- collectFileMetrics(logger, files, registry)
2020-11-09 12:57:28 +00:00
}
}()
select {
case <-ctx.Done():
return fmt.Errorf("context timeout, ran out of time")
case err := <-errCh:
return err
}
}