Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipmi_sensor does not correctly parse negative values #7468

Closed
tarrychk opened this issue May 6, 2020 · 0 comments · Fixed by #7541
Closed

ipmi_sensor does not correctly parse negative values #7468

tarrychk opened this issue May 6, 2020 · 0 comments · Fixed by #7541
Assignees
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@tarrychk
Copy link

tarrychk commented May 6, 2020

ipmi_sensor plugin with metric version 2 does not parse negative values in the description field correctly:

# ipmitool sdr elist
[...]
DIMM Thrm Mrgn 1 | B0h | ok  |  8.1 | -55 degrees C
DIMM Thrm Mrgn 2 | B1h | ok  |  8.2 | -55 degrees C
DIMM Thrm Mrgn 3 | B2h | ok  |  8.3 | -53 degrees C
DIMM Thrm Mrgn 4 | B3h | ok  |  8.4 | -57 degrees C
[...]

Relevant telegraf.conf:

[[inputs.ipmi_sensor]]
  interval = "120s"
  timeout = "20s"
  metric_version = 2

System info:

telegraf v1.14.2
Ubuntu 18.04
ipmitool 1.8.18-5ubuntu0.1

Steps to reproduce:

  1. Configure ipmi_sensor plugin on a host where ipmitool supports sensor values that yield negative values.

Expected behavior:

ipmi_sensor plugin should convert
DIMM Thrm Mrgn 1 | B0h | ok | 8.1 | -55 degrees C
to
ipmi_sensor,entity_id=8.1,status_code=ok,unit=degrees_c dimm_thrm_mrgn_1=-55 1588753149000000000

Actual behavior:

DIMM Thrm Mrgn 1 | B0h | ok | 8.1 | -55 degrees C
gets converted to
ipmi_sensor,entity_id=8.1,status_code=ok,status_desc=-55_degrees_c dimm_thrm_mrgn_1=0 1588753050000000000

Additional info:

I found that patching re_v2_parse_description regexp in ipmi.go to allow an optional minus-sign before the analog value resolves the issue for me.

diff --git a/plugins/inputs/ipmi_sensor/ipmi.go b/plugins/inputs/ipmi_sensor/ipmi.go
index 9ac842b8..fb53e1bc 100644
--- a/plugins/inputs/ipmi_sensor/ipmi.go
+++ b/plugins/inputs/ipmi_sensor/ipmi.go
@@ -21,7 +21,7 @@ var (
        execCommand             = exec.Command // execCommand is used to mock commands in tests.
        re_v1_parse_line        = regexp.MustCompile(`^(?P<name>[^|]*)\|(?P<description>[^|]*)\|(?P<status_code>.*)`)
        re_v2_parse_line        = regexp.MustCompile(`^(?P<name>[^|]*)\|[^|]+\|(?P<status_code>[^|]*)\|(?P<entity_id>[^|]*)\|(?:(?P<description>[^|]+))?`)
-       re_v2_parse_description = regexp.MustCompile(`^(?P<analogValue>[0-9.]+)\s(?P<analogUnit>.*)|(?P<status>.+)|^$`)
+       re_v2_parse_description = regexp.MustCompile(`^(?P<analogValue>-?[0-9.]+)\s(?P<analogUnit>.*)|(?P<status>.+)|^$`)
        re_v2_parse_unit        = regexp.MustCompile(`^(?P<realAnalogUnit>[^,]+)(?:,\s*(?P<statusDesc>.*))?`)
 )

--
@danielnelson danielnelson added this to the 1.14.3 milestone May 14, 2020
@danielnelson danielnelson added the bug unexpected problem or unintended behavior label May 14, 2020
@danielnelson danielnelson self-assigned this May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants