Skip to content

Commit

Permalink
Fix powerdns integer parse error handling
Browse files Browse the repository at this point in the history
closes #1751
  • Loading branch information
sparrc committed Sep 23, 2016
1 parent 17e6496 commit 077a70a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [#1530](https://github.com/influxdata/telegraf/issues/1530): Fix prometheus_client reload panic
- [#1764](https://github.com/influxdata/telegraf/issues/1764): Fix kafka consumer panic when nil error is returned down errs channel.
- [#1768](https://github.com/influxdata/telegraf/pull/1768): Speed up statsd parsing.
- [#1751](https://github.com/influxdata/telegraf/issues/1751): Fix powerdns integer parse error handling.

## v1.0.1 [unreleased]

Expand Down
17 changes: 10 additions & 7 deletions plugins/inputs/powerdns/powerdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io"
"log"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -86,10 +87,7 @@ func (p *Powerdns) gatherServer(address string, acc telegraf.Accumulator) error
metrics := string(buf)

// Process data
fields, err := parseResponse(metrics)
if err != nil {
return err
}
fields := parseResponse(metrics)

// Add server socket as a tag
tags := map[string]string{"server": address}
Expand All @@ -99,22 +97,27 @@ func (p *Powerdns) gatherServer(address string, acc telegraf.Accumulator) error
return nil
}

func parseResponse(metrics string) (map[string]interface{}, error) {
func parseResponse(metrics string) map[string]interface{} {
values := make(map[string]interface{})

s := strings.Split(metrics, ",")

for _, metric := range s[:len(s)-1] {
m := strings.Split(metric, "=")
if len(m) < 2 {
continue
}

i, err := strconv.ParseInt(m[1], 10, 64)
if err != nil {
return values, err
log.Printf("powerdns: Error parsing integer for metric [%s]: %s",
metric, err)
continue
}
values[m[0]] = i
}

return values, nil
return values
}

func init() {
Expand Down

0 comments on commit 077a70a

Please sign in to comment.