Fix postgres extensible text (#1601)

* convert postgresql_extensible byte slice values to strings

* code cleanup in postgresql_extensible
This commit is contained in:
Patrick Hemmer 2016-08-09 03:25:59 -04:00 committed by Cameron Sparr
parent c99c22534b
commit 53e31cf1b5
2 changed files with 20 additions and 15 deletions

View File

@ -125,6 +125,7 @@ consistent with the behavior of `collection_jitter`.
- [#1323](https://github.com/influxdata/telegraf/issues/1323): Processes plugin: fix potential error with /proc/net/stat directory. - [#1323](https://github.com/influxdata/telegraf/issues/1323): Processes plugin: fix potential error with /proc/net/stat directory.
- [#1322](https://github.com/influxdata/telegraf/issues/1322): Fix rare RHEL 5.2 panic in gopsutil diskio gathering function. - [#1322](https://github.com/influxdata/telegraf/issues/1322): Fix rare RHEL 5.2 panic in gopsutil diskio gathering function.
- [#1586](https://github.com/influxdata/telegraf/pull/1586): Remove IF NOT EXISTS from influxdb output database creation. - [#1586](https://github.com/influxdata/telegraf/pull/1586): Remove IF NOT EXISTS from influxdb output database creation.
- [#1600](https://github.com/influxdata/telegraf/issues/1600): Fix quoting with text values in postgresql_extensible plugin.
## v0.13.1 [2016-05-24] ## v0.13.1 [2016-05-24]

View File

@ -266,29 +266,33 @@ func (p *Postgresql) accRow(meas_name string, row scanner, acc telegraf.Accumula
tags := map[string]string{} tags := map[string]string{}
tags["server"] = tagAddress tags["server"] = tagAddress
tags["db"] = dbname.String() tags["db"] = dbname.String()
var isATag int
fields := make(map[string]interface{}) fields := make(map[string]interface{})
COLUMN:
for col, val := range columnMap { for col, val := range columnMap {
if acc.Debug() { if acc.Debug() {
log.Printf("postgresql_extensible: column: %s = %T: %s\n", col, *val, *val) log.Printf("postgresql_extensible: column: %s = %T: %s\n", col, *val, *val)
} }
_, ignore := ignoredColumns[col] _, ignore := ignoredColumns[col]
if !ignore && *val != nil { if ignore || *val == nil {
isATag = 0 continue
for tag := range p.AdditionalTags { }
if col == p.AdditionalTags[tag] { for _, tag := range p.AdditionalTags {
isATag = 1 if col != tag {
value_type_p := fmt.Sprintf(`%T`, *val) continue
if value_type_p == "[]uint8" {
tags[col] = fmt.Sprintf(`%s`, *val)
} else if value_type_p == "int64" {
tags[col] = fmt.Sprintf(`%v`, *val)
}
}
} }
if isATag == 0 { switch v := (*val).(type) {
fields[col] = *val case []byte:
tags[col] = string(v)
case int64:
tags[col] = fmt.Sprintf("%d", v)
} }
continue COLUMN
}
if v, ok := (*val).([]byte); ok {
fields[col] = string(v)
} else {
fields[col] = *val
} }
} }
acc.AddFields(meas_name, fields, tags) acc.AddFields(meas_name, fields, tags)