Created
June 30, 2016 16:52
-
-
Save varesa/2c473b70ffd771e6ffa071654c970aaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import os | |
import subprocess | |
import time | |
hostname = os.getenv("COLLECTD_HOSTNAME", subprocess.check_output(["hostname", "-f"]).strip()) | |
interval = os.getenv("COLLECTD_INTERVAL", "10") | |
def gettype(name): | |
type = name.split(" ")[0] | |
if type == "Temp": return "temperature" | |
if type == "Fan": return "fanspeed" | |
if type == "Power": return "power" | |
return "gauge" | |
while True: | |
out = subprocess.check_output(["ipmitool", "sdr"]) | |
for line in out.split("\n"): | |
try: | |
name, value, status = line.split("|") | |
name = name.strip() | |
value = value.strip() | |
status = status.strip() | |
if status == "ok": | |
for word in value.split(" "): | |
try: | |
float(word) | |
print("PUTVAL \"{0}/ipmi/{1}-{2}\" interval={3} N:{4}".format(hostname, gettype(name), name, interval, word)) | |
continue | |
except ValueError: | |
pass # Not a number | |
except ValueError: | |
pass # Skip invalid lines | |
time.sleep(int(interval)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment