feat(cli): Add config command to display current configuration and update CLI help
This commit is contained in:
parent
ebc6f65fa9
commit
bbb8f4a22c
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-03-25 - 2.2.0 - feat(cli)
|
||||||
|
Add 'config' command to display current configuration and update CLI help
|
||||||
|
|
||||||
|
- Introduce new 'config' command to show SNMP settings, thresholds, and configuration file location
|
||||||
|
- Update help text to include details for 'nupst config' command
|
||||||
|
|
||||||
## 2025-03-25 - 2.1.0 - feat(cli)
|
## 2025-03-25 - 2.1.0 - feat(cli)
|
||||||
Add uninstall command to CLI and update shutdown delay for graceful VM shutdown
|
Add uninstall command to CLI and update shutdown delay for graceful VM shutdown
|
||||||
|
|
||||||
|
21
license
Normal file
21
license
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Task Venture Capital GmbH
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@serve.zone/nupst',
|
name: '@serve.zone/nupst',
|
||||||
version: '2.1.0',
|
version: '2.2.0',
|
||||||
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
|
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices'
|
||||||
}
|
}
|
||||||
|
91
ts/cli.ts
91
ts/cli.ts
@ -101,6 +101,10 @@ export class NupstCli {
|
|||||||
case 'uninstall':
|
case 'uninstall':
|
||||||
await this.uninstall();
|
await this.uninstall();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'config':
|
||||||
|
await this.showConfig();
|
||||||
|
break;
|
||||||
|
|
||||||
case 'help':
|
case 'help':
|
||||||
default:
|
default:
|
||||||
@ -372,6 +376,7 @@ Usage:
|
|||||||
nupst status - Show status of the systemd service and UPS status
|
nupst status - Show status of the systemd service and UPS status
|
||||||
nupst setup - Run the interactive setup to configure SNMP settings
|
nupst setup - Run the interactive setup to configure SNMP settings
|
||||||
nupst test - Test the current configuration by connecting to the UPS
|
nupst test - Test the current configuration by connecting to the UPS
|
||||||
|
nupst config - Display the current configuration
|
||||||
nupst update - Update NUPST from repository and refresh systemd service (requires root)
|
nupst update - Update NUPST from repository and refresh systemd service (requires root)
|
||||||
nupst uninstall - Completely uninstall NUPST from the system (requires root)
|
nupst uninstall - Completely uninstall NUPST from the system (requires root)
|
||||||
nupst help - Show this help message
|
nupst help - Show this help message
|
||||||
@ -843,6 +848,92 @@ Options:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the current configuration
|
||||||
|
*/
|
||||||
|
private async showConfig(): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Try to load configuration
|
||||||
|
try {
|
||||||
|
await this.nupst.getDaemon().loadConfig();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('┌─ Configuration Error ─────────────────────┐');
|
||||||
|
console.error('│ No configuration found.');
|
||||||
|
console.error('│ Please run \'nupst setup\' first to create a configuration.');
|
||||||
|
console.error('└──────────────────────────────────────────┘');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current configuration
|
||||||
|
const config = this.nupst.getDaemon().getConfig();
|
||||||
|
|
||||||
|
console.log('┌─ NUPST Configuration ──────────────────────┐');
|
||||||
|
|
||||||
|
// SNMP Settings
|
||||||
|
console.log('│ SNMP Settings:');
|
||||||
|
console.log(`│ Host: ${config.snmp.host}`);
|
||||||
|
console.log(`│ Port: ${config.snmp.port}`);
|
||||||
|
console.log(`│ Version: ${config.snmp.version}`);
|
||||||
|
console.log(`│ UPS Model: ${config.snmp.upsModel || 'cyberpower'}`);
|
||||||
|
|
||||||
|
if (config.snmp.version === 1 || config.snmp.version === 2) {
|
||||||
|
console.log(`│ Community: ${config.snmp.community}`);
|
||||||
|
} else if (config.snmp.version === 3) {
|
||||||
|
console.log(`│ Security Level: ${config.snmp.securityLevel}`);
|
||||||
|
console.log(`│ Username: ${config.snmp.username}`);
|
||||||
|
|
||||||
|
// Show auth and privacy details based on security level
|
||||||
|
if (config.snmp.securityLevel === 'authNoPriv' || config.snmp.securityLevel === 'authPriv') {
|
||||||
|
console.log(`│ Auth Protocol: ${config.snmp.authProtocol || 'None'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.snmp.securityLevel === 'authPriv') {
|
||||||
|
console.log(`│ Privacy Protocol: ${config.snmp.privProtocol || 'None'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show timeout value
|
||||||
|
console.log(`│ Timeout: ${config.snmp.timeout / 1000} seconds`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show OIDs if custom model is selected
|
||||||
|
if (config.snmp.upsModel === 'custom' && config.snmp.customOIDs) {
|
||||||
|
console.log('│ Custom OIDs:');
|
||||||
|
console.log(`│ Power Status: ${config.snmp.customOIDs.POWER_STATUS || 'Not set'}`);
|
||||||
|
console.log(`│ Battery Capacity: ${config.snmp.customOIDs.BATTERY_CAPACITY || 'Not set'}`);
|
||||||
|
console.log(`│ Battery Runtime: ${config.snmp.customOIDs.BATTERY_RUNTIME || 'Not set'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thresholds
|
||||||
|
console.log('│ Thresholds:');
|
||||||
|
console.log(`│ Battery: ${config.thresholds.battery}%`);
|
||||||
|
console.log(`│ Runtime: ${config.thresholds.runtime} minutes`);
|
||||||
|
console.log(`│ Check Interval: ${config.checkInterval / 1000} seconds`);
|
||||||
|
|
||||||
|
// Configuration file location
|
||||||
|
console.log('│');
|
||||||
|
console.log('│ Configuration File Location:');
|
||||||
|
console.log('│ /etc/nupst/config.json');
|
||||||
|
|
||||||
|
console.log('└──────────────────────────────────────────┘');
|
||||||
|
|
||||||
|
// Show service status
|
||||||
|
try {
|
||||||
|
const isActive = execSync('systemctl is-active nupst.service || true').toString().trim() === 'active';
|
||||||
|
const isEnabled = execSync('systemctl is-enabled nupst.service || true').toString().trim() === 'enabled';
|
||||||
|
|
||||||
|
console.log('┌─ Service Status ─────────────────────────┐');
|
||||||
|
console.log(`│ Service Active: ${isActive ? 'Yes' : 'No'}`);
|
||||||
|
console.log(`│ Service Enabled: ${isEnabled ? 'Yes' : 'No'}`);
|
||||||
|
console.log('└──────────────────────────────────────────┘');
|
||||||
|
} catch (error) {
|
||||||
|
// Ignore errors checking service status
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to display configuration: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completely uninstall NUPST from the system
|
* Completely uninstall NUPST from the system
|
||||||
|
Loading…
x
Reference in New Issue
Block a user