Skip to content

Trim spaces from values#344

Open
vaionicle wants to merge 1 commit into
prometheus-community:masterfrom
vaionicle:trim_values
Open

Trim spaces from values#344
vaionicle wants to merge 1 commit into
prometheus-community:masterfrom
vaionicle:trim_values

Conversation

@vaionicle
Copy link
Copy Markdown

@vaionicle vaionicle commented Nov 21, 2024

Adding the ability to trim spaces in values.

I got a json response from an Iot device with almost all numeric values contain spaces before or after the value. I trim the spaces to parse them correctly.

{
    "OVERVIEW": {
        "LOCAL_TIME": "Thu, 21 Nov 2024 22:02:09",
        "AKZ": "                                ",
        "OKZ": "                      ",
        "Import_T1": {
            "value": "    13441.23",
            "unit": "kWh"
        },
        "Import_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "Export_T1": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "Export_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "TODAY_T1": {
            "value": "        7.98",
            "unit": "kWh"
        },
        "TODAY_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "THISMONTH_T1": {
            "value": "      296.04",
            "unit": "kWh"
        },
        "THISMONTH_T2": {
            "value": "        0.00",
            "unit": "kWh"
        },
        "P_L1": {
            "value": "0.39",
            "unit": "kW"
        },
        "P_L2": {
            "value": "0.03",
            "unit": "kW"
        },
        "P_L3": {
            "value": "0.03",
            "unit": "kW"
        },
        "P_SUM": {
            "value": "0.45",
            "unit": "kW"
        },
        "VA_SUM": {
            "value": "0.62",
            "unit": "kVA"
        },
        "VARQ1_SUM": {
            "value": "-0.19",
            "unit": "kvar"
        },
        "PF_SUM": {
            "value": "0.727",
            "unit": "     "
        }
    }
}

@vaionicle vaionicle force-pushed the trim_values branch 7 times, most recently from fec07c8 to 04655fe Compare November 21, 2024 21:42
Signed-off-by: Vasileios Tsaknis <tsaknis_vasilios@hotmail.com>
@vaionicle
Copy link
Copy Markdown
Author

Hello, can someone have a look on this PR?

Comment thread exporter/collector.go
}

return buf.String(), nil
return strings.TrimSpace(buf.String()), nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we always trim? Or add a boolean flag for trimming whitespace. 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1 for boolean, someone may rely on space.

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