From edce110c8a8cb10e98949af070a0078cf00a3c67 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 25 Mar 2025 10:27:08 +0000 Subject: [PATCH] fix(cli/systemd): Fix status command to pass debug flag and improve systemd status logging output --- changelog.md | 6 ++++++ ts/00_commitinfo_data.ts | 2 +- ts/cli.ts | 4 +++- ts/systemd.ts | 18 +++++++++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 4a05342..49ef9ca 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-03-25 - 2.0.1 - fix(cli/systemd) +Fix status command to pass debug flag and improve systemd status logging output + +- ts/cli.ts: Now extracts debug options from process arguments and passes debug mode to getStatus. +- ts/systemd.ts: Updated getStatus to accept a debugMode parameter, enabling detailed SNMP debug logging, explicitly reloading configuration, and printing connection details. + ## 2025-03-25 - 2.0.0 - BREAKING CHANGE(snmp) refactor: update SNMP type definitions and interface names for consistency diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 74dbcd4..8351ac9 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.0.0', + version: '2.0.1', description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices' } diff --git a/ts/cli.ts b/ts/cli.ts index 6bfdf61..a130a3d 100644 --- a/ts/cli.ts +++ b/ts/cli.ts @@ -182,7 +182,9 @@ export class NupstCli { * Show status of the systemd service and UPS */ private async status(): Promise { - await this.nupst.getSystemd().getStatus(); + // Extract debug options from args array + const debugOptions = this.extractDebugOptions(process.argv); + await this.nupst.getSystemd().getStatus(debugOptions.debugMode); } /** diff --git a/ts/systemd.ts b/ts/systemd.ts index bd802fa..81dccc8 100644 --- a/ts/systemd.ts +++ b/ts/systemd.ts @@ -126,9 +126,18 @@ WantedBy=multi-user.target /** * Get status of the systemd service and UPS + * @param debugMode Whether to enable debug mode for SNMP */ - public async getStatus(): Promise { + public async getStatus(debugMode: boolean = false): Promise { try { + // Enable debug mode if requested + if (debugMode) { + console.log('┌─ Debug Mode ─────────────────────────────┐'); + console.log('│ SNMP debugging enabled - detailed logs will be shown'); + console.log('└──────────────────────────────────────────┘'); + this.daemon.getNupstSnmp().enableDebug(); + } + // Display version information this.daemon.getNupstSnmp().getNupst().logVersionInfo(); @@ -170,6 +179,8 @@ WantedBy=multi-user.target */ private async displayUpsStatus(): Promise { try { + // Explicitly load the configuration first to ensure it's up-to-date + await this.daemon.loadConfig(); const config = this.daemon.getConfig(); const snmp = this.daemon.getNupstSnmp(); @@ -179,6 +190,11 @@ WantedBy=multi-user.target timeout: Math.min(config.snmp.timeout, 10000) // Use at most 10 seconds for status check }; + console.log('┌─ Connecting to UPS... ────────────────────┐'); + console.log(`│ Host: ${config.snmp.host}:${config.snmp.port}`); + console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`); + console.log('└──────────────────────────────────────────┘'); + const status = await snmp.getUpsStatus(snmpConfig); console.log('┌─ UPS Status ───────────────────────────────┐');