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

Handle trailing linefeed in NetSNMP output adding 1 to the error count #398

Merged
merged 2 commits into from
Apr 8, 2019
Merged

Handle trailing linefeed in NetSNMP output adding 1 to the error count #398

merged 2 commits into from
Apr 8, 2019

Conversation

gebn
Copy link
Contributor

@gebn gebn commented Apr 7, 2019

When non-empty, NetSNMP's output string is terminated with \n. Splitting this string by \n produces a slice of the number of errors + 1, however this is not being compensated for, resulting in e + 1 errors being reported when e > 0.

Before:

$ ./generator parse_errors
INFO[0000] Loading MIBs from $HOME/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp  source="net_snmp.go:141"
WARN[0000] NetSNMP reported 2 parse errors               source="main.go:105"
Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU

$ 

After:

$ ./generator parse_errors
INFO[0000] Loading MIBs from $HOME/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp  source="net_snmp.go:141"
WARN[0000] NetSNMP reported 1 parse error(s)             source="main.go:105"
Bad operator (INTEGER): At line 73 in /usr/share/snmp/mibs/ietf/SNMPv2-PDU
$

@brian-brazil

gebn added 2 commits April 7, 2019 19:03
This referred to the length of the output string, not the number
of errors it contained.

Signed-off-by: George Brighton <[email protected]>
Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Nice improvement.

@SuperQ SuperQ requested a review from brian-brazil April 7, 2019 20:55
@brian-brazil brian-brazil merged commit a622a79 into prometheus:master Apr 8, 2019
@brian-brazil
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants