From 42c9d030e06da3c54d2147d2cf7f3cc0797f0727 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Thu, 20 Jun 2019 11:51:41 -0700 Subject: [PATCH] Fix panic if pool_mode column does not exist (#6000) (cherry picked from commit 049d364917a651ed41f3008f4daa4dee73bc5536) --- plugins/inputs/pgbouncer/pgbouncer.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/inputs/pgbouncer/pgbouncer.go b/plugins/inputs/pgbouncer/pgbouncer.go index 722648c48edc1..edff10509916c 100644 --- a/plugins/inputs/pgbouncer/pgbouncer.go +++ b/plugins/inputs/pgbouncer/pgbouncer.go @@ -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{})