/*
* SysDeck - Sensors Panel (v0.0.11)
* Author: Jeremy Anderson (https://dcos.net)
*
* Hardware sensor readings from lm_sensors. Attributes the
* cockpit-sensors plugin (MIT, ocristopfer) whose standalone plugin
* lives at https://github.com/ocristopfer/cockpit-sensors.
*
* This panel invokes `sensors -j` via cockpit.spawn as a separate
* process — no cockpit-sensors code is bundled.
*
* Shows temperature, fan speed, and voltage readings grouped by
* hardware adapter.
*
* v0.1.4 SECURITY: adapter names and sensor keys come from `sensors -j`
* output (driver-controlled chip labels — a malicious/things driver or
* SMBus device controls them) and error messages from spawn — all now
* escaped before innerHTML (0.3.0 audit).
*/
function escapeHtml(s) {
return String(s == null ? '' : s)
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
export async function mount(panel, { bridge, EventBus }) {
panel.innerHTML = renderSkeleton();
let data = {};
try {
data = await bridge.sensors.summary();
} catch (err) {
panel.innerHTML = renderError(err);
return;
}
const temps = filterSensors(data, (key) => /temp|core|tctl/i.test(key));
const fans = filterSensors(data, (key) => /fan/i.test(key));
const voltages = filterSensors(data, (key) => /^in|vcore|vbat/i.test(key));
panel.innerHTML = `
lm_sensors + cockpit-sensors integrationHardware Sensors
| Adapter | Sensor | Value | Critical |
|---|---|---|---|
| ${escapeHtml(adapter)} | ${escapeHtml(key)} | ${escapeHtml(sensorVal(val, 'temp'))}°C | ${escapeHtml(sensorCrit(val))} |
| No temperature sensors. | |||
| Adapter | Sensor | RPM |
|---|---|---|
| ${escapeHtml(adapter)} | ${escapeHtml(key)} | ${escapeHtml(sensorVal(val, 'fan'))} RPM |
| No fan sensors. | ||
| Adapter | Sensor | Volts |
|---|---|---|
| ${escapeHtml(adapter)} | ${escapeHtml(key)} | ${escapeHtml(sensorVal(val, 'in'))} V |
| No voltage sensors. | ||
${escapeHtml(err.message || err)}. Install lm_sensors (pacman -S lm_sensors) and ensure sensors-detect has been run.
cockpit-sensors (MIT) by ocristopfer — https://github.com/ocristopfer/cockpit-sensors