Skip to content

Commit

Permalink
plugins/inputs/dovecot: Add support for unix domain sockets
Browse files Browse the repository at this point in the history
It's safer for dovecot to export metrics via a UDS instead of tcp port,
this will add support for that option.
  • Loading branch information
isodude committed Apr 29, 2021
1 parent c0d5af1 commit 2a62f0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions plugins/inputs/dovecot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ the [upgrading steps][upgrading].
## specify dovecot servers via an address:port list
## e.g.
## localhost:24242
## or as an UDS socket
## e.g.
## /var/run/dovecot/old-stats
##
## If no servers are specified, then localhost is used as the host.
servers = ["localhost:24242"]
Expand Down
18 changes: 13 additions & 5 deletions plugins/inputs/dovecot/dovecot.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ func (d *Dovecot) Gather(acc telegraf.Accumulator) error {
}

func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype string, filter string) error {
_, _, err := net.SplitHostPort(addr)
if err != nil {
return fmt.Errorf("%q on url %s", err.Error(), addr)
}
var proto string

if strings.HasPrefix(addr, "/") {
proto = "unix"
} else {
proto = "tcp"

c, err := net.DialTimeout("tcp", addr, defaultTimeout)
_, _, err := net.SplitHostPort(addr)
if err != nil {
return fmt.Errorf("%q on url %s", err.Error(), addr)
}
}

c, err := net.DialTimeout(proto, addr, defaultTimeout)
if err != nil {
return fmt.Errorf("enable to connect to dovecot server '%s': %s", addr, err)
}
Expand Down

0 comments on commit 2a62f0b

Please sign in to comment.