-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix(inputs.upsd): Enforce string type for vendor and product IDs #18626
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
Open
majiayu000
wants to merge
3
commits into
influxdata:master
Choose a base branch
from
majiayu000:fix/upsd-vendorid-productid-string-type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
plugins/inputs/upsd/testcases/CyberPowerSystems_CP900EPFCLCD_full/expected.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| upsd,model=CP900EPFCLCD,serial=0,status_OL=true,ups_name=fake battery_charge_low=10i,battery_charge_percent=100i,battery_charge_warning=20i,battery_mfr_date="CPS",battery_runtime=4020i,battery_runtime_low=300i,battery_type="PbAcid",battery_voltage=24,device_mfr="CPS",device_model="CP900EPFCLCD",device_serial=0i,device_type="ups",driver_debug=0i,driver_flag_allow_killpower=0i,driver_name="usbhid-ups",driver_parameter_pollfreq=30i,driver_parameter_pollinterval=2i,driver_parameter_port="auto",driver_parameter_product="CP900EPFCLCD",driver_parameter_productid=501i,driver_parameter_serial=0i,driver_parameter_synchronous="auto",driver_parameter_vendor="CPS",driver_parameter_vendorid=764i,driver_state="quiet",driver_version="2.8.1",driver_version_data="CyberPower HID 0.8",driver_version_internal=0.52,driver_version_usb="libusb-1.0.26 (API: 0x1000109)",firmware="",input_transfer_high=260i,input_transfer_low=170i,input_voltage=228,load_percent=13i,nominal_battery_voltage=24i,nominal_input_voltage=230i,nominal_power=540i,output_voltage=228,status_flags=8u,time_left_ns=4020000000000i,ups_beeper_status=true,ups_delay_shutdown=20i,ups_delay_start=30i,ups_mfr="CPS",ups_model="CP900EPFCLCD",ups_productid=501i,ups_serial=0i,ups_status="OL",ups_test_result="No test initiated",ups_timer_shutdown=-60i,ups_timer_start=-60i,ups_vendorid=764i | ||
| upsd,model=CP900EPFCLCD,serial=0,status_OL=true,ups_name=fake battery_charge_low=10i,battery_charge_percent=100i,battery_charge_warning=20i,battery_mfr_date="CPS",battery_runtime=4020i,battery_runtime_low=300i,battery_type="PbAcid",battery_voltage=24,device_mfr="CPS",device_model="CP900EPFCLCD",device_serial=0i,device_type="ups",driver_debug=0i,driver_flag_allow_killpower=0i,driver_name="usbhid-ups",driver_parameter_pollfreq=30i,driver_parameter_pollinterval=2i,driver_parameter_port="auto",driver_parameter_product="CP900EPFCLCD",driver_parameter_productid="501",driver_parameter_serial=0i,driver_parameter_synchronous="auto",driver_parameter_vendor="CPS",driver_parameter_vendorid="764",driver_state="quiet",driver_version="2.8.1",driver_version_data="CyberPower HID 0.8",driver_version_internal=0.52,driver_version_usb="libusb-1.0.26 (API: 0x1000109)",firmware="",input_transfer_high=260i,input_transfer_low=170i,input_voltage=228,load_percent=13i,nominal_battery_voltage=24i,nominal_input_voltage=230i,nominal_power=540i,output_voltage=228,status_flags=8u,time_left_ns=4020000000000i,ups_beeper_status=true,ups_delay_shutdown=20i,ups_delay_start=30i,ups_mfr="CPS",ups_model="CP900EPFCLCD",ups_productid="501",ups_serial=0i,ups_status="OL",ups_test_result="No test initiated",ups_timer_shutdown=-60i,ups_timer_start=-60i,ups_vendorid="764" |
1 change: 1 addition & 0 deletions
1
plugins/inputs/upsd/testcases/CyberPowerSystems_CP900EPFCLCD_full_mixed_ids/expected.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| upsd,model=CP900EPFCLCD,serial=0,status_OL=true,ups_name=fake battery_charge_low=10i,battery_charge_percent=100i,battery_charge_warning=20i,battery_mfr_date="CPS",battery_runtime=4020i,battery_runtime_low=300i,battery_type="PbAcid",battery_voltage=24,device_mfr="CPS",device_model="CP900EPFCLCD",device_serial=0i,device_type="ups",driver_debug=0i,driver_flag_allow_killpower=0i,driver_name="usbhid-ups",driver_parameter_pollfreq=30i,driver_parameter_pollinterval=2i,driver_parameter_port="auto",driver_parameter_product="CP900EPFCLCD",driver_parameter_productid="ABCD",driver_parameter_serial=0i,driver_parameter_synchronous="auto",driver_parameter_vendor="CPS",driver_parameter_vendorid="EFGH",driver_state="quiet",driver_version="2.8.1",driver_version_data="CyberPower HID 0.8",driver_version_internal=0.52,driver_version_usb="libusb-1.0.26 (API: 0x1000109)",firmware="",input_transfer_high=260i,input_transfer_low=170i,input_voltage=228,load_percent=13i,nominal_battery_voltage=24i,nominal_input_voltage=230i,nominal_power=540i,output_voltage=228,status_flags=8u,time_left_ns=4020000000000i,ups_beeper_status=true,ups_delay_shutdown=20i,ups_delay_start=30i,ups_mfr="CPS",ups_model="CP900EPFCLCD",ups_productid="WXYZ",ups_serial=0i,ups_status="OL",ups_test_result="No test initiated",ups_timer_shutdown=-60i,ups_timer_start=-60i,ups_vendorid="IJKL" |
2 changes: 2 additions & 0 deletions
2
plugins/inputs/upsd/testcases/CyberPowerSystems_CP900EPFCLCD_full_mixed_ids/telegraf.conf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [[inputs.upsd]] | ||
| additional_fields = ["*"] |
49 changes: 49 additions & 0 deletions
49
plugins/inputs/upsd/testcases/CyberPowerSystems_CP900EPFCLCD_full_mixed_ids/types.dev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| battery.charge: NUMBER | ||
| battery.charge.low: STRING | ||
| battery.charge.warning: NUMBER | ||
| battery.mfr.date: NUMBER | ||
| battery.runtime: NUMBER | ||
| battery.runtime.low: STRING | ||
| battery.type: NUMBER | ||
| battery.voltage: NUMBER | ||
| battery.voltage.nominal: NUMBER | ||
| device.mfr: NUMBER | ||
| device.model: NUMBER | ||
| device.serial: NUMBER | ||
| device.type: NUMBER | ||
| driver.debug: NUMBER | ||
| driver.flag.allow_killpower: NUMBER | ||
| driver.name: NUMBER | ||
| driver.parameter.pollfreq: NUMBER | ||
| driver.parameter.pollinterval: NUMBER | ||
| driver.parameter.port: NUMBER | ||
| driver.parameter.product: NUMBER | ||
| driver.parameter.productid: NUMBER | ||
| driver.parameter.serial: NUMBER | ||
| driver.parameter.synchronous: NUMBER | ||
| driver.parameter.vendor: NUMBER | ||
| driver.parameter.vendorid: NUMBER | ||
| driver.state: NUMBER | ||
| driver.version: | ||
| driver.version.data: NUMBER | ||
| driver.version.internal: NUMBER | ||
| driver.version.usb: NUMBER | ||
| input.transfer.high: STRING | ||
| input.transfer.low: STRING | ||
| input.voltage: NUMBER | ||
| input.voltage.nominal: NUMBER | ||
| output.voltage: NUMBER | ||
| ups.beeper.status: NUMBER | ||
| ups.delay.shutdown: STRING | ||
| ups.delay.start: STRING | ||
| ups.load: NUMBER | ||
| ups.mfr: NUMBER | ||
| ups.model: NUMBER | ||
| ups.productid: NUMBER | ||
| ups.realpower.nominal: NUMBER | ||
| ups.serial: NUMBER | ||
| ups.status: NUMBER | ||
| ups.test.result: NUMBER | ||
| ups.timer.shutdown: NUMBER | ||
| ups.timer.start: NUMBER | ||
| ups.vendorid: NUMBER | ||
49 changes: 49 additions & 0 deletions
49
plugins/inputs/upsd/testcases/CyberPowerSystems_CP900EPFCLCD_full_mixed_ids/variables.dev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| battery.charge: 100 | ||
| battery.charge.low: 10 | ||
| battery.charge.warning: 20 | ||
| battery.mfr.date: CPS | ||
| battery.runtime: 4020 | ||
| battery.runtime.low: 300 | ||
| battery.type: PbAcid | ||
| battery.voltage: 24.0 | ||
| battery.voltage.nominal: 24 | ||
| device.mfr: CPS | ||
| device.model: CP900EPFCLCD | ||
| device.serial: 000000000000 | ||
| device.type: ups | ||
| driver.debug: 0 | ||
| driver.flag.allow_killpower: 0 | ||
| driver.name: usbhid-ups | ||
| driver.parameter.pollfreq: 30 | ||
| driver.parameter.pollinterval: 2 | ||
| driver.parameter.port: auto | ||
| driver.parameter.product: CP900EPFCLCD | ||
| driver.parameter.productid: ABCD | ||
| driver.parameter.serial: 000000000000 | ||
| driver.parameter.synchronous: auto | ||
| driver.parameter.vendor: CPS | ||
| driver.parameter.vendorid: EFGH | ||
| driver.state: quiet | ||
| driver.version: 2.8.1 | ||
| driver.version.data: CyberPower HID 0.8 | ||
| driver.version.internal: 0.52 | ||
| driver.version.usb: libusb-1.0.26 (API: 0x1000109) | ||
| input.transfer.high: 260 | ||
| input.transfer.low: 170 | ||
| input.voltage: 228.0 | ||
| input.voltage.nominal: 230 | ||
| output.voltage: 228.0 | ||
| ups.beeper.status: enabled | ||
| ups.delay.shutdown: 20 | ||
| ups.delay.start: 30 | ||
| ups.load: 13 | ||
| ups.mfr: CPS | ||
| ups.model: CP900EPFCLCD | ||
| ups.productid: WXYZ | ||
| ups.realpower.nominal: 540 | ||
| ups.serial: 000000000000 | ||
| ups.status: OL | ||
| ups.test.result: No test initiated | ||
| ups.timer.shutdown: -60 | ||
| ups.timer.start: -60 | ||
| ups.vendorid: IJKL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,17 @@ import ( | |
| var sampleConfig string | ||
|
|
||
| var ( | ||
| // Fields that must always be emitted as strings to avoid type conflicts. | ||
| // The go.nut library auto-detects numeric-looking values (e.g. "0764") | ||
| // and converts them to int64, but IDs like vendorid/productid should | ||
| // remain strings regardless of their content. | ||
| stringFieldSet = map[string]bool{ | ||
| "ups.vendorid": true, | ||
| "ups.productid": true, | ||
| "driver.parameter.vendorid": true, | ||
| "driver.parameter.productid": true, | ||
| } | ||
|
|
||
| // Define the default field set to add if existing | ||
| defaultFieldSet = map[string]string{ | ||
| "battery.charge": "battery_charge_percent", | ||
|
|
@@ -168,8 +179,14 @@ func (u *Upsd) gatherUps(acc telegraf.Accumulator, upsname string, variables []n | |
| continue | ||
| } | ||
|
|
||
| // Force expected float values to actually being float (e.g. if delivered as int) | ||
| if u.ForceFloat { | ||
| // Force ID fields to always be strings to avoid type conflicts | ||
| if stringFieldSet[varname] { | ||
| str, err := internal.ToString(v) | ||
| if err == nil { | ||
| v = str | ||
| } | ||
| } else if u.ForceFloat { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep the stringify/force-float comments in the same position relative to their |
||
| // Force expected float values to actually being float (e.g. if delivered as int) | ||
| float, err := internal.ToFloat64(v) | ||
| if err == nil { | ||
| v = float | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types.dev inconsistency: the sibling _full_stringify_ids/types.dev:27 has driver.version: (trailing space, no type) while this file has driver.version: (no trailing space). Make them identical, pick one and apply everywhere.