saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.18k stars 5.48k forks source link

Sensors module should use the -j (JSON) flag for more useful information #60459

Open darkpixel opened 3 years ago

darkpixel commented 3 years ago

The current output of the sensors module is string data wrapped into a dictionary.

Screenshot from 2021-06-29 08-56-40

The sensors application has support for the -j flag which returns data in JSON format. Using that data returns a more structured result.

Screenshot from 2021-06-29 08-56-49

A small change to the modules/sensors.py file returns the latter output:

    extra_args = ""
    if fahrenheit is True:
        extra_args = "-f"
    extra_args += ' -j'
    sensors = __salt__["cmd.run"](
        "/usr/bin/sensors {0} {1}".format(chip, extra_args), python_shell=False
    )
    ret = json.loads(sensors)
    return ret
sagetherage commented 3 years ago

@darkpixel thank you, you may open a Pull Request with this and we will review!

darkpixel commented 3 years ago

Hmm...when calling sensors -f you can get the output in fahrenheit. Without the -f flag you get the results in Celsius....but if you call sensors -j the JSON output always returns Celsius. Even if you pass the -f flag. So this change would possibly break stuff.

sagetherage commented 3 years ago

ok, well, I have to put this into blocked - maybe you want to file an upstream bug?

darkpixel commented 3 years ago

Maybe a second module would work? Something like sensorsjson?