Update ups-exporter.js

This commit is contained in:
Zakary Timson 2024-07-22 15:21:10 -04:00
parent 7ee803dc10
commit e916ca7ab7

View File

@ -12,24 +12,31 @@ async function scrape() {
map[found[1]] = found[2]; map[found[1]] = found[2];
return { return {
ups_model: map["Model Name"], model: map["Model Name"],
ups_vendor: map["Power Supply by"], vendor: map["Power Supply by"],
ups_state: map["State"], state: map["State"],
ups_charge: Number(/\d+/g.exec(map["Battery Capacity"])[0]) / 100, charge: Number(/\d+/g.exec(map["Battery Capacity"])[0]) / 100,
ups_remaining: map["Remaining Runtime"], remaining: map["Remaining Runtime"],
ups_rated_voltage: Number(/\d+/g.exec(map["Rating Voltage"])[0]), rated_voltage: Number(/\d+/g.exec(map["Rating Voltage"])[0]),
ups_rated_wattage: Number(/\d+/g.exec(map["Rating Power"])[0]), rated_wattage: Number(/\d+/g.exec(map["Rating Power"])[0]),
ups_input_voltage: Number(/\d+/g.exec(map["Utility Voltage"])[0]), input_voltage: Number(/\d+/g.exec(map["Utility Voltage"])[0]),
ups_output_voltage: Number(/\d+/g.exec(map["Output Voltage"])[0]), output_voltage: Number(/\d+/g.exec(map["Output Voltage"])[0]),
ups_load_wattage: Number(/\d+/g.exec(map["Load"])[0]), load_wattage: Number(/\d+/g.exec(map["Load"])[0]),
ups_load_percentage: Number(/(\d+) %/g.exec(map["Load"])[1]) / 100, load_percentage: Number(/(\d+) %/g.exec(map["Load"])[1]) / 100,
ups_last_test: map["Test Result"], // last_test: map["Test Result"],
ups_last_outage: map["Last Power Event"], // last_outage: map["Last Power Event"],
}; };
} }
function format(a) { function format(a) {
return Object.entries(a).map(([key, value]) => `${key} ${typeof value == 'string' ? `"${value}"` : value}`).join('\n'); let labels = Object.entries(a).filter(([key, value]) => typeof value == 'string')
.map(([key, value]) => `${key}="${value}"`)
.join(', ');
if(labels) labels = `{${labels}}`;
return Object.entries(a).filter(([key, value]) => typeof value != 'string')
.map(([key, value]) => `${key}${labels} ${value}`)
.join('\n');
} }
http.createServer(async (req, res) => { http.createServer(async (req, res) => {