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

Alternative with jq #8

Open
jose1711 opened this issue Jun 17, 2022 · 1 comment
Open

Alternative with jq #8

jose1711 opened this issue Jun 17, 2022 · 1 comment

Comments

@jose1711
Copy link

jose1711 commented Jun 17, 2022

Thank you for sharing the idea of a LLD script. I am not a huge fan of JSON hacks though so I modified the script that it uses jq to do all the parsing. This way it is guaranteed that the output is always a valid and nicely formatted json. Feel free to reuse or perhaps provide as an alternative where jq is installed.

sensors -j | \
  jq '{"data": [to_entries[]|.key as $chip | .value |
                to_entries[]|.key as $group | .value | 
                select(type == "object") |  # discard scalars
                to_entries[]|.key as $sensor|
                select($sensor|test(".*input"))|
                if ($sensor|test("temp.*")) then .units="°C"
                  elif ($sensor|test("power.*")) then .units="W"
                  elif ($sensor|test("fan.*")) then .units="RPM"
                  elif ($sensor|test("in.*")) then .units="V"
                  else .units=""
                end | 
                {"{#CHIP}":$chip, "{#SENSOR}":($sensor|sub("_input";"")), "{#UNITS}":.units}]}'

@guillerg86
Copy link

I think it's a good idea, because jq will escape some special chars if they appear.

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

No branches or pull requests

2 participants