2024-02-05 21:57:52 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Read Yocto sensor.')
|
|
|
|
parser.add_argument('metric', type=str,
|
|
|
|
help='Metric name.')
|
|
|
|
parser.add_argument('binary', type=str,
|
|
|
|
help='Yocto binary.')
|
|
|
|
parser.add_argument('sensor', type=str,
|
|
|
|
help='Sensor name.')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
try:
|
2024-06-09 06:59:13 +00:00
|
|
|
returned_output = subprocess.check_output(["/root/YoctoLib.cmdline.24497/Binaries/linux/32bits/"+args.binary, "-r", "localhost", "-f", "[result]", args.sensor, "get_currentValue"])
|
2024-02-05 21:57:52 +00:00
|
|
|
try:
|
|
|
|
value = round(float(returned_output.decode("utf-8").strip().strip("'")), 1)
|
|
|
|
except ValueError:
|
2024-06-09 05:18:22 +00:00
|
|
|
print("Got garbage: "+returned_output)
|
2024-02-05 21:57:52 +00:00
|
|
|
sys.exit(1)
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
data[args.metric] = value
|
|
|
|
print(json.dumps(data))
|