From 896233914fa2d418500707708677958595c25876 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 25 Mar 2025 14:47:57 +0000 Subject: [PATCH] fix(snmp): Fix Eaton UPS support by updating power status OID and adjusting battery runtime conversion. --- changelog.md | 6 ++++++ ts/00_commitinfo_data.ts | 2 +- ts/snmp/manager.ts | 19 +++++++++++++++++-- ts/snmp/oid-sets.ts | 6 +++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index cc5f456..98f9084 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-03-25 - 2.5.1 - fix(snmp) +Fix Eaton UPS support by updating power status OID and adjusting battery runtime conversion. + +- Updated Eaton UPS power status OID to '1.3.6.1.4.1.534.1.4.4.0' to correctly detect online/battery status. +- Added conversion for Eaton UPS battery runtime from seconds to minutes in SNMP manager. + ## 2025-03-25 - 2.5.0 - feat(cli) Automatically restart running NUPST service after configuration changes in interactive setup diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 2b36426..051bf93 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@serve.zone/nupst', - version: '2.5.0', + version: '2.5.1', description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' } diff --git a/ts/snmp/manager.ts b/ts/snmp/manager.ts index 6d03922..05654ab 100644 --- a/ts/snmp/manager.ts +++ b/ts/snmp/manager.ts @@ -348,6 +348,14 @@ export class NupstSnmp { } else if (powerStatusValue === 3) { powerStatus = 'onBattery'; } + } else if (config.upsModel === 'eaton') { + // Eaton UPS: xupsOutputSource values + // 3=normal/mains, 5=battery, etc. + if (powerStatusValue === 3) { + powerStatus = 'online'; + } else if (powerStatusValue === 5) { + powerStatus = 'onBattery'; + } } else { // Default interpretation for other UPS models if (powerStatusValue === 1) { @@ -357,14 +365,21 @@ export class NupstSnmp { } } - // Convert TimeTicks to minutes for CyberPower runtime (value is in 1/100 seconds) + // Convert to minutes for UPS models with different time units let processedRuntime = batteryRuntime; + if (config.upsModel === 'cyberpower' && batteryRuntime > 0) { - // TimeTicks is in 1/100 seconds, convert to minutes + // CyberPower: TimeTicks is in 1/100 seconds, convert to minutes processedRuntime = Math.floor(batteryRuntime / 6000); // 6000 ticks = 1 minute if (this.debug) { console.log(`Converting CyberPower runtime from ${batteryRuntime} ticks to ${processedRuntime} minutes`); } + } else if (config.upsModel === 'eaton' && batteryRuntime > 0) { + // Eaton: Runtime is in seconds, convert to minutes + processedRuntime = Math.floor(batteryRuntime / 60); + if (this.debug) { + console.log(`Converting Eaton runtime from ${batteryRuntime} seconds to ${processedRuntime} minutes`); + } } const result = { diff --git a/ts/snmp/oid-sets.ts b/ts/snmp/oid-sets.ts index cf6deb9..cb6174a 100644 --- a/ts/snmp/oid-sets.ts +++ b/ts/snmp/oid-sets.ts @@ -25,9 +25,9 @@ export class UpsOidSets { // Eaton OIDs eaton: { - POWER_STATUS: '1.3.6.1.4.1.534.1.1.2.0', // Power status - BATTERY_CAPACITY: '1.3.6.1.4.1.534.1.2.4.0', // Battery capacity in percentage - BATTERY_RUNTIME: '1.3.6.1.4.1.534.1.2.1.0', // Remaining runtime in minutes + POWER_STATUS: '1.3.6.1.4.1.534.1.4.4.0', // xupsOutputSource (3=normal/mains, 5=battery) + BATTERY_CAPACITY: '1.3.6.1.4.1.534.1.2.4.0', // xupsBatCapacity (percentage) + BATTERY_RUNTIME: '1.3.6.1.4.1.534.1.2.1.0', // xupsBatTimeRemaining (seconds) }, // TrippLite OIDs