Add UPS status card

This commit is contained in:
josh committed 2026-04-19 22:40:26 -04:00
1 parent e6d2945b7b
commit b78fb9469e
2 files changed
+91

No files matched your search

+41
View File
@@ -166,6 +166,43 @@ def read_virtual_machines
end
end
def read_ups
out = `apcaccess 2>/dev/null`
return nil unless $?.success? && !out.empty?
raw = {}
out.each_line do |line|
next unless line.include?(":")
key, value = line.split(":", 2).map(&:strip)
raw[key] = value
end
result = { "type" => "ups" }
result["model"] = raw["MODEL"] if raw["MODEL"]
result["status"] = raw["STATUS"] if raw["STATUS"]
if raw["BCHARGE"]
result["charge"] = raw["BCHARGE"].to_f
end
if raw["TIMELEFT"]
result["timeleft"] = raw["TIMELEFT"].to_f
end
if raw["LINEV"]
result["line_voltage"] = raw["LINEV"].to_f
end
if raw["LOADPCT"]
result["load"] = raw["LOADPCT"].to_f
end
if raw["NOMBATTV"]
result["battery_voltage_nom"] = raw["NOMBATTV"].to_f
end
if raw["BATTV"]
result["battery_voltage"] = raw["BATTV"].to_f
end
result
end
def handle_info(conn)
info = []
@@ -195,6 +232,10 @@ def handle_info(conn)
info.concat(read_filesystems)
info.concat(read_virtual_machines)
if (ups = read_ups)
info << ups
end
if conn
conn.puts JSON.generate(info)
else