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

fix(inputs.snmp_trap): Handle octet strings #14619

Merged
merged 1 commit into from Jan 30, 2024

Conversation

JuhaKS
Copy link
Contributor

@JuhaKS JuhaKS commented Jan 24, 2024

Summary

As discussed in #9113, any octetString data that goes beyond valid UTF-8 values will first be converted to a Golang string as the data is instantiated as a Metric. This step changes the presentation of the data but doesn't yet destroy anything, but the following json.Marshal that happens in use cases where the desired output format is JSON, the non-UTF characters get replaced with Unicode replacement characters, overwriting data octets in the process

This fix adds a check for SNMP data of type OctetString, that validates whether the data can be converted into valid UTF-8 or not. If yes, the data is passed unchanged. If not, the data is considered hex and processed with hex.EncodeToString. The end result with our test material is that the hex format timestamp is then passed correctly through processing, preserving both the data and its original presentation unchanged

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #9113

@telegraf-tiger
Copy link
Contributor

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@telegraf-tiger telegraf-tiger bot added fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Jan 24, 2024
@JuhaKS
Copy link
Contributor Author

JuhaKS commented Jan 24, 2024

!signed-cla as CCLA

@telegraf-tiger
Copy link
Contributor

@powersj
Copy link
Contributor

powersj commented Jan 24, 2024

@JuhaKS,

!signed-cla as CCLA

When did you send in the signed CCLA? Trying to ensure you get added to the right list.

@powersj powersj self-assigned this Jan 24, 2024
@JuhaKS
Copy link
Contributor Author

JuhaKS commented Jan 25, 2024

@JuhaKS,

!signed-cla as CCLA

When did you send in the signed CCLA? Trying to ensure you get added to the right list.

It was sent to community@influxdata.com on 24.01.2024 11:53 EET

@powersj
Copy link
Contributor

powersj commented Jan 25, 2024

It was sent to community@influxdata.com on 24.01.2024 11:53 EET

Thanks! I'll follow up with folks internally.

@powersj
Copy link
Contributor

powersj commented Jan 29, 2024

!signed-cla

Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

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

Thanks!

@powersj powersj added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jan 29, 2024
@powersj powersj assigned srebhan and unassigned powersj Jan 29, 2024
@srebhan srebhan changed the title fix(inputs.snmp_trap): correctly handle hex strings in octetStrings fix(inputs.snmp_trap): Handle octet strings Jan 30, 2024
Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution @JuhaKS!

@srebhan srebhan merged commit 4c6df8d into influxdata:master Jan 30, 2024
27 checks passed
@github-actions github-actions bot added this to the v1.29.4 milestone Jan 30, 2024
@JuhaKS JuhaKS deleted the preserveOctetstrings branch January 30, 2024 12:22
powersj pushed a commit that referenced this pull request Jan 31, 2024
hhiroshell pushed a commit to hhiroshell/telegraf that referenced this pull request Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/snmp fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SNMP Trap input does not properly handle non-string data
4 participants