Compare commits

..

4 Commits

6 changed files with 75 additions and 7 deletions

View File

@ -1,5 +1,17 @@
# Changelog # 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
- Added restartServiceIfRunning() to check and restart the service if it's active.
- Invoked the restart function post-setup to apply configuration changes immediately.
## 2025-03-25 - 2.4.8 - fix(installer) ## 2025-03-25 - 2.4.8 - fix(installer)
Improve Git dependency handling and repository cloning in install.sh Improve Git dependency handling and repository cloning in install.sh

View File

@ -1,6 +1,6 @@
{ {
"name": "@serve.zone/nupst", "name": "@serve.zone/nupst",
"version": "2.4.8", "version": "2.5.1",
"description": "Node.js UPS Shutdown Tool for SNMP-enabled UPS devices", "description": "Node.js UPS Shutdown Tool for SNMP-enabled UPS devices",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@serve.zone/nupst', name: '@serve.zone/nupst',
version: '2.4.8', version: '2.5.1',
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
} }

View File

@ -533,6 +533,9 @@ Options:
// Test the connection if requested // Test the connection if requested
await this.optionallyTestConnection(config, prompt); await this.optionallyTestConnection(config, prompt);
// Check if service is running and restart it if needed
await this.restartServiceIfRunning();
console.log('\nSetup complete!'); console.log('\nSetup complete!');
await this.optionallyEnableService(prompt); await this.optionallyEnableService(prompt);
} }
@ -833,6 +836,44 @@ Options:
} }
} }
/**
* Check if the systemd service is running and restart it if it is
* This is useful after configuration changes
*/
private async restartServiceIfRunning(): Promise<void> {
try {
// Check if the service is active
const isActive = execSync('systemctl is-active nupst.service || true').toString().trim() === 'active';
if (isActive) {
// Service is running, restart it
console.log('┌─ Service Update ─────────────────────────┐');
console.log('│ Configuration has changed.');
console.log('│ Restarting NUPST service to apply changes...');
try {
if (process.getuid && process.getuid() === 0) {
// We have root access, restart directly
execSync('systemctl restart nupst.service');
console.log('│ Service restarted successfully.');
} else {
// No root access, show instructions
console.log('│ Please restart the service with:');
console.log('│ sudo systemctl restart nupst.service');
}
} catch (error) {
console.log(`│ Error restarting service: ${error.message}`);
console.log('│ You may need to restart the service manually:');
console.log('│ sudo systemctl restart nupst.service');
}
console.log('└──────────────────────────────────────────┘');
}
} catch (error) {
// Ignore errors checking service status
}
}
/** /**
* Optionally enable and start systemd service * Optionally enable and start systemd service
* @param prompt Function to prompt for user input * @param prompt Function to prompt for user input

View File

@ -348,6 +348,14 @@ export class NupstSnmp {
} else if (powerStatusValue === 3) { } else if (powerStatusValue === 3) {
powerStatus = 'onBattery'; 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 { } else {
// Default interpretation for other UPS models // Default interpretation for other UPS models
if (powerStatusValue === 1) { 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; let processedRuntime = batteryRuntime;
if (config.upsModel === 'cyberpower' && batteryRuntime > 0) { 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 processedRuntime = Math.floor(batteryRuntime / 6000); // 6000 ticks = 1 minute
if (this.debug) { if (this.debug) {
console.log(`Converting CyberPower runtime from ${batteryRuntime} ticks to ${processedRuntime} minutes`); 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 = { const result = {

View File

@ -25,9 +25,9 @@ export class UpsOidSets {
// Eaton OIDs // Eaton OIDs
eaton: { eaton: {
POWER_STATUS: '1.3.6.1.4.1.534.1.1.2.0', // Power status 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', // Battery capacity in percentage 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', // Remaining runtime in minutes BATTERY_RUNTIME: '1.3.6.1.4.1.534.1.2.1.0', // xupsBatTimeRemaining (seconds)
}, },
// TrippLite OIDs // TrippLite OIDs