dovecot: enable global, user and ip queries

This commit is contained in:
Miki 2016-04-08 10:17:15 +02:00 committed by Michele Fadda
parent 00c777da05
commit 113d49fa5d
1 changed files with 9 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
// "log"
"net" "net"
"strconv" "strconv"
"strings" "strings"
@ -64,6 +65,10 @@ func (d *Dovecot) Gather(acc telegraf.Accumulator) error {
var outerr error var outerr error
if len(d.Filters) <= 0 {
d.Filters = append(d.Filters, "")
}
for _, serv := range d.Servers { for _, serv := range d.Servers {
for _, filter := range d.Filters { for _, filter := range d.Filters {
wg.Add(1) wg.Add(1)
@ -80,6 +85,7 @@ func (d *Dovecot) Gather(acc telegraf.Accumulator) error {
} }
func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype string, filter string) error { func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, qtype string, filter string) error {
_, _, err := net.SplitHostPort(addr) _, _, err := net.SplitHostPort(addr)
if err != nil { if err != nil {
return fmt.Errorf("Error: %s on url %s\n", err, addr) return fmt.Errorf("Error: %s on url %s\n", err, addr)
@ -120,12 +126,11 @@ func gatherStats(buf *bytes.Buffer, acc telegraf.Accumulator, host string, qtype
continue continue
} }
val := strings.Split(vals[i], "\t") val := strings.Split(vals[i], "\t")
fields := make(map[string]interface{}) fields := make(map[string]interface{})
tags := map[string]string{"server": host, "type": qtype} tags := map[string]string{"server": host, "type": qtype}
switch qtype {
case "global": if qtype != "global" {
continue
default:
tags[qtype] = val[0] tags[qtype] = val[0]
} }