Skip to content

Commit

Permalink
Remove options
Browse files Browse the repository at this point in the history
  • Loading branch information
lawliet89 committed Nov 26, 2019
1 parent dc22d65 commit e3c39f9
Showing 1 changed file with 16 additions and 35 deletions.
51 changes: 16 additions & 35 deletions plugins/inputs/x509_cert/x509_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ const sampleConfig = `
## Timeout for SSL connection
# timeout = "5s"
## Include Certificate Issuer information in tags
# include_issuer = false
## Include Certificate SAN in tag
# include_san = false
## Separator between each SAN in tag
# san_separator = ","
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
Expand All @@ -42,12 +34,9 @@ const description = "Reads metrics from a SSL certificate"

// X509Cert holds the configuration of the plugin.
type X509Cert struct {
Sources []string `toml:"sources"`
Timeout internal.Duration `toml:"timeout"`
IncludeIssuer bool `toml:"include_issuer"`
IncludeSAN bool `toml:"include_san"`
SANSeperator string `toml:"san_separator"`
tlsCfg *tls.Config
Sources []string `toml:"sources"`
Timeout internal.Duration `toml:"timeout"`
tlsCfg *tls.Config
_tls.ClientConfig
}

Expand Down Expand Up @@ -139,7 +128,7 @@ func getFields(cert *x509.Certificate, now time.Time) map[string]interface{} {
return fields
}

func (c *X509Cert) getTags(cert *x509.Certificate, location string) map[string]string {
func getTags(cert *x509.Certificate, location string) map[string]string {
tags := map[string]string{
"source": location,
"common_name": cert.Subject.CommonName,
Expand All @@ -164,22 +153,17 @@ func (c *X509Cert) getTags(cert *x509.Certificate, location string) map[string]s
tags["locality"] = cert.Subject.Locality[0]
}

if c.IncludeIssuer {
issuer := cert.Issuer
tags["issuer_common_name"] = issuer.CommonName
tags["issuer_serial_number"] = issuer.SerialNumber
}
tags["issuer_common_name"] = cert.Issuer.CommonName
tags["issuer_serial_number"] = cert.Issuer.SerialNumber

if c.IncludeSAN {
san := append(cert.DNSNames, cert.EmailAddresses...)
for _, ip := range cert.IPAddresses {
san = append(san, ip.String())
}
for _, uri := range cert.URIs {
san = append(san, uri.String())
}
tags["san"] = strings.Join(san, c.SANSeperator)
san := append(cert.DNSNames, cert.EmailAddresses...)
for _, ip := range cert.IPAddresses {
san = append(san, ip.String())
}
for _, uri := range cert.URIs {
san = append(san, uri.String())
}
tags["san"] = strings.Join(san, ",")

return tags
}
Expand All @@ -202,7 +186,7 @@ func (c *X509Cert) Gather(acc telegraf.Accumulator) error {

for i, cert := range certs {
fields := getFields(cert, now)
tags := c.getTags(cert, location)
tags := getTags(cert, location)

// The first certificate is the leaf/end-entity certificate which needs DNS
// name validation against the URL hostname.
Expand Down Expand Up @@ -255,11 +239,8 @@ func (c *X509Cert) Init() error {
func init() {
inputs.Add("x509_cert", func() telegraf.Input {
return &X509Cert{
Sources: []string{},
Timeout: internal.Duration{Duration: 5},
IncludeIssuer: false,
IncludeSAN: false,
SANSeperator: ",",
Sources: []string{},
Timeout: internal.Duration{Duration: 5},
}
})
}

0 comments on commit e3c39f9

Please sign in to comment.