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

support monitoring of an explicit dialed target #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="https://banner.mux.dev/?text=TLS%20Expiry%20Monitor" />

Utility that exposes the expiry of TLS certificates as Prometheus metrics
Utility that exposes the expiry of TLS certificates as Prometheus metrics.

## Building
To build the Docker image, simply run `docker build`:
Expand All @@ -13,6 +13,10 @@ Run the Docker image using the executable at `/app`:
```
→ docker run muxinc/certificate-expiry-monitor:latest /app --help
Usage of ./certificate-expiry-monitor:
-dial_target_addr string
If provided, dials this address directly rather than resolving pods
-dial_target_name string
Must be provided if dial_target_addr is set, identifies the explicitly configured target in the monitoring labels (still uses the pod label).
-domains string
Comma-separated SNI domains to query
-frequency duration
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var (
domains = flag.String("domains", "", "Comma-separated SNI domains to query")
ignoredDomains = flag.String("ignoredDomains", "", "Comma-separated list of domains to exclude from the discovered set. This can be a regex if the string is wrapped in forward-slashes like /.*\\.domain\\.com$/ which would exclude all domain.com subdomains.")
hostIP = flag.Bool("hostIP", false, "If true, then connect to the host that the pod is running on rather than to the pod itself.")
dialTargetAddr = flag.String("dial_target_addr", "", "If provided, dials this address directly rather than resolving pods")
dialTargetName = flag.String("dial_target_name", "", "Must be provided if dial_target_addr is set, identifies the explicitly configured target in the monitoring labels (still uses the pod label).")
port = flag.Int("port", 443, "TCP port to connect to each pod on")
loglevel = flag.String("loglevel", "error", "Log-level threshold for logging messages (debug, info, warn, error, fatal, or panic)")
logFormat = flag.String("logformat", "text", "Log format (text or json)")
Expand All @@ -56,6 +58,10 @@ func main() {
log.Fatalf("Error creating Kubernetes client, exiting: %v", err)
}

if len(*dialTargetAddr) > 0 && len(*dialTargetName) == 0 {
log.Fatalf("got a dial target address but not a name. must set -dial_target_name")
}

// start monitor
monitor := &monitor.CertExpiryMonitor{
Logger: logger,
Expand All @@ -67,6 +73,8 @@ func main() {
Domains: strings.Split(*domains, ","),
IgnoredDomains: strings.Split(*ignoredDomains, ","),
HostIP: *hostIP,
DialTargetAddr: *dialTargetAddr,
DialTargetName: *dialTargetName,
Port: *port,
InsecureSkipVerify: *insecureSkipVerify,
}
Expand Down
6 changes: 6 additions & 0 deletions monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type CertExpiryMonitor struct {
Domains []string
IgnoredDomains []string
HostIP bool
DialTargetAddr string
DialTargetName string
Port int
InsecureSkipVerify bool
}
Expand Down Expand Up @@ -94,6 +96,10 @@ func (m *CertExpiryMonitor) Run(ctx context.Context, wg *sync.WaitGroup) error {
m.Domains = discoveredDomains
}

if len(m.DialTargetAddr) > 0 {
m.checkCertificates(&sync.WaitGroup{}, "DialTarget", m.DialTargetName, m.DialTargetAddr)
}

// iterate over namespaces to monitor
for _, ns := range m.Namespaces {
// list pods matching the labels in this namespace
Expand Down