Fix panic if pool_mode column does not exist (#6000)

This commit is contained in:
Daniel Nelson 2019-06-20 11:51:41 -07:00 committed by GitHub
parent 791ea5e38e
commit 049d364917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 8 deletions

View File

@ -2,14 +2,12 @@ package pgbouncer
import (
"bytes"
"github.com/influxdata/telegraf/plugins/inputs/postgresql"
// register in driver.
_ "github.com/jackc/pgx/stdlib"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/inputs/postgresql"
_ "github.com/jackc/pgx/stdlib" // register driver
)
type PgBouncer struct {
@ -98,12 +96,16 @@ func (p *PgBouncer) Gather(acc telegraf.Accumulator) error {
return err
}
if s, ok := (*columnMap["user"]).(string); ok && s != "" {
tags["user"] = s
if user, ok := columnMap["user"]; ok {
if s, ok := (*user).(string); ok && s != "" {
tags["user"] = s
}
}
if s, ok := (*columnMap["pool_mode"]).(string); ok && s != "" {
tags["pool_mode"] = s
if poolMode, ok := columnMap["pool_mode"]; ok {
if s, ok := (*poolMode).(string); ok && s != "" {
tags["pool_mode"] = s
}
}
fields := make(map[string]interface{})