robbiet480 / go.nut

A Golang library for interacting with NUT (Network UPS Tools)
https://godoc.org/github.com/robbiet480/go.nut
MIT License
31 stars 15 forks source link

Coax strings that are obvious numbers to float and integer #2

Closed DRuggeri closed 4 years ago

DRuggeri commented 4 years ago

Hi there, @robbiet480. Would you consider this acceptable functionality for this library? I am building a prometheus exporter on top of the library and discovered that my UPS seems a little... silly.

There are things coming back from NUT that are NUMBERs, but related variables coming back as STRINGs.

Example:

GET TYPE ups battery.charge.low
TYPE ups battery.charge.low RW STRING:10
GET VAR ups battery.charge.low
VAR ups battery.charge.low "10"

GET TYPE ups battery.charge.warning
TYPE ups battery.charge.warning NUMBER
GET VAR ups battery.charge.warning
VAR ups battery.charge.warning "50"

This pull request examines the STRING types that are returned and coaxes them to integer or float64 as is done for UNKNOWN and NUMBER types. This could be considered a breaking change, so I could wrap this in a static configuration param (or parameter to GetVariables) if that would be preferred.

DRuggeri commented 4 years ago

I've also incorporated a bugfix into this PR. At least for my silly UPS, some of the values are returned with trailing spaces within the quotes.

DRuggeri commented 4 years ago

Will rework this a bit to streamline, and will reopen PR