Compare commits

...

6 Commits

7 changed files with 42 additions and 23 deletions

View File

@ -1,5 +1,24 @@
# Changelog # Changelog
## 2025-03-26 - 2.6.11 - fix(cli, systemd)
Adjust log formatting for consistent output in CLI and systemd commands
- Fixed spacing issues in service installation and status log messages in the systemd module.
- Revised output formatting in the CLI to improve message clarity.
## 2025-03-26 - 2.6.10 - fix(daemon)
Adjust console log box formatting for consistent output in daemon status messages
- Updated closing box borders to align properly in configuration error, periodic updates, and UPS status logs
- Improved visual consistency in log messages
## 2025-03-26 - 2.6.9 - fix(cli)
Improve console output formatting for status banners and logging messages
- Standardize banner messages in daemon status updates
- Refine version information banner in nupst logging
- Update UPS connection and status banners in systemd
## 2025-03-26 - 2.6.8 - fix(cli) ## 2025-03-26 - 2.6.8 - fix(cli)
Improve CLI formatting, refine debug option filtering, and remove unused dgram import in SNMP manager Improve CLI formatting, refine debug option filtering, and remove unused dgram import in SNMP manager

View File

@ -1,6 +1,6 @@
{ {
"name": "@serve.zone/nupst", "name": "@serve.zone/nupst",
"version": "2.6.8", "version": "2.6.11",
"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.6.8', version: '2.6.11',
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
} }

View File

@ -919,7 +919,7 @@ Options:
if (isActive) { if (isActive) {
// Service is running, restart it // Service is running, restart it
console.log('┌─ Service Update ─────────────────────────┐'); console.log('┌─ Service Update ─────────────────────────┐');
console.log('│ Configuration has changed.'); console.log('│ Configuration has changed.');
console.log('│ Restarting NUPST service to apply changes...'); console.log('│ Restarting NUPST service to apply changes...');
@ -939,7 +939,7 @@ Options:
console.log('│ sudo systemctl restart nupst.service'); console.log('│ sudo systemctl restart nupst.service');
} }
console.log('└──────────────────────────────────────────┘'); console.log('└──────────────────────────────────────────┘');
} }
} catch (error) { } catch (error) {
// Ignore errors checking service status // Ignore errors checking service status

View File

@ -125,7 +125,7 @@ export class NupstDaemon {
console.error('┌─ Configuration Error ─────────────────────┐'); console.error('┌─ Configuration Error ─────────────────────┐');
console.error(`${message}`); console.error(`${message}`);
console.error('│ Please run \'nupst setup\' first to create a configuration.'); console.error('│ Please run \'nupst setup\' first to create a configuration.');
console.error('└──────────────────────────────────────────┘'); console.error('└──────────────────────────────────────────┘');
} }
/** /**
@ -196,7 +196,7 @@ export class NupstDaemon {
console.log(`│ Battery: ${this.config.thresholds.battery}%`); console.log(`│ Battery: ${this.config.thresholds.battery}%`);
console.log(`│ Runtime: ${this.config.thresholds.runtime} minutes`); console.log(`│ Runtime: ${this.config.thresholds.runtime} minutes`);
console.log(`│ Check Interval: ${this.config.checkInterval / 1000} seconds`); console.log(`│ Check Interval: ${this.config.checkInterval / 1000} seconds`);
console.log('└──────────────────────────────────────────┘'); console.log('└────────────────────────────────────────────┘');
} }
/** /**
@ -226,20 +226,20 @@ export class NupstDaemon {
// Log status changes // Log status changes
if (status.powerStatus !== lastStatus) { if (status.powerStatus !== lastStatus) {
console.log('┌──────────────────────────────────────────┐'); console.log('┌─ Power Status Change ─────────────────────┐');
console.log(`Power status changed: ${lastStatus}${status.powerStatus}`); console.log(`Status changed: ${lastStatus}${status.powerStatus}`);
console.log('└──────────────────────────────────────────┘'); console.log('└──────────────────────────────────────────┘');
lastStatus = status.powerStatus; lastStatus = status.powerStatus;
lastLogTime = currentTime; // Reset log timer when status changes lastLogTime = currentTime; // Reset log timer when status changes
} }
// Log status periodically (at least every 5 minutes) // Log status periodically (at least every 5 minutes)
else if (shouldLogStatus) { else if (shouldLogStatus) {
const timestamp = new Date().toISOString(); const timestamp = new Date().toISOString();
console.log('┌──────────────────────────────────────────┐'); console.log('┌─ Periodic Status Update ──────────────────┐');
console.log(`[${timestamp}] Periodic Status Update`); console.log(`Timestamp: ${timestamp}`);
console.log(`│ Power Status: ${status.powerStatus}`); console.log(`│ Power Status: ${status.powerStatus}`);
console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`); console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`);
console.log('└──────────────────────────────────────────┘'); console.log('└──────────────────────────────────────────┘');
lastLogTime = currentTime; lastLogTime = currentTime;
} }
@ -267,8 +267,8 @@ export class NupstDaemon {
batteryCapacity: number, batteryCapacity: number,
batteryRuntime: number batteryRuntime: number
}): Promise<void> { }): Promise<void> {
console.log('┌─ UPS Status ───────────────────────────────┐'); console.log('┌─ UPS Status ─────────────────────────────┐');
console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`); console.log(`│ Battery: ${status.batteryCapacity}% | Runtime: ${status.batteryRuntime} min`);
console.log('└──────────────────────────────────────────┘'); console.log('└──────────────────────────────────────────┘');
// Check battery threshold // Check battery threshold

View File

@ -162,7 +162,7 @@ export class Nupst {
*/ */
public logVersionInfo(checkForUpdates: boolean = true): void { public logVersionInfo(checkForUpdates: boolean = true): void {
const version = this.getVersion(); const version = this.getVersion();
console.log('┌─ NUPST Version ────────────────────────┐'); console.log('┌─ NUPST Version ────────────────────────────┐');
console.log(`│ Current Version: ${version}`); console.log(`│ Current Version: ${version}`);
if (this.updateAvailable && this.latestVersion) { if (this.updateAvailable && this.latestVersion) {

View File

@ -66,7 +66,7 @@ WantedBy=multi-user.target
// Write the service file // Write the service file
await fs.writeFile(this.serviceFilePath, this.serviceTemplate); await fs.writeFile(this.serviceFilePath, this.serviceTemplate);
console.log('┌─ Service Installation ─────────────────────┐'); console.log('┌─ Service Installation ─────────────────────┐');
console.log(`│ Service file created at ${this.serviceFilePath}`); console.log(`│ Service file created at ${this.serviceFilePath}`);
// Reload systemd daemon // Reload systemd daemon
@ -76,7 +76,7 @@ WantedBy=multi-user.target
// Enable the service // Enable the service
execSync('systemctl enable nupst.service'); execSync('systemctl enable nupst.service');
console.log('│ Service enabled to start on boot'); console.log('│ Service enabled to start on boot');
console.log('└──────────────────────────────────────────┘'); console.log('└─────────────────────────────────────────────┘');
} catch (error) { } catch (error) {
if (error.message === 'Configuration not found') { if (error.message === 'Configuration not found') {
// Just rethrow the error as the message has already been displayed // Just rethrow the error as the message has already been displayed
@ -97,9 +97,9 @@ WantedBy=multi-user.target
await this.checkConfigExists(); await this.checkConfigExists();
execSync('systemctl start nupst.service'); execSync('systemctl start nupst.service');
console.log('┌─ Service Status ─────────────────────────┐'); console.log('┌─ Service Status ───────────────────────────┐');
console.log('│ NUPST service started successfully'); console.log('│ NUPST service started successfully');
console.log('└──────────────────────────────────────────┘'); console.log('└────────────────────────────────────────────┘');
} catch (error) { } catch (error) {
if (error.message === 'Configuration not found') { if (error.message === 'Configuration not found') {
// Exit with error code since configuration is required // Exit with error code since configuration is required
@ -190,20 +190,20 @@ WantedBy=multi-user.target
timeout: Math.min(config.snmp.timeout, 10000) // Use at most 10 seconds for status check timeout: Math.min(config.snmp.timeout, 10000) // Use at most 10 seconds for status check
}; };
console.log('┌─ Connecting to UPS... ────────────────────┐'); console.log('┌─ Connecting to UPS... ────────────────────┐');
console.log(`│ Host: ${config.snmp.host}:${config.snmp.port}`); console.log(`│ Host: ${config.snmp.host}:${config.snmp.port}`);
console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`); console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`);
console.log('└──────────────────────────────────────────┘'); console.log('└────────────────────────────────────────────┘');
const status = await snmp.getUpsStatus(snmpConfig); const status = await snmp.getUpsStatus(snmpConfig);
console.log('┌─ UPS Status ───────────────────────────────┐'); console.log('┌─ UPS Status ─────────────────────────────┐');
console.log(`│ Power Status: ${status.powerStatus}`); console.log(`│ Power Status: ${status.powerStatus}`);
console.log(`│ Battery Capacity: ${status.batteryCapacity}%`); console.log(`│ Battery Capacity: ${status.batteryCapacity}%`);
console.log(`│ Runtime Remaining: ${status.batteryRuntime} minutes`); console.log(`│ Runtime Remaining: ${status.batteryRuntime} minutes`);
console.log('└──────────────────────────────────────────┘'); console.log('└──────────────────────────────────────────┘');
} catch (error) { } catch (error) {
console.error('┌─ UPS Status ───────────────────────────────┐'); console.error('┌─ UPS Status ─────────────────────────────┐');
console.error(`│ Failed to retrieve UPS status: ${error.message}`); console.error(`│ Failed to retrieve UPS status: ${error.message}`);
console.error('└──────────────────────────────────────────┘'); console.error('└──────────────────────────────────────────┘');
} }