Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
992a776fd2 | |||
3e15a2d52f | |||
d1a3576d31 | |||
1ca05e879b | |||
9c6fa37eb8 | |||
ff433b2256 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@serve.zone/nupst",
|
"name": "@serve.zone/nupst",
|
||||||
"version": "4.2.5",
|
"version": "4.3.2",
|
||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"dev": "deno run --allow-all mod.ts",
|
"dev": "deno run --allow-all mod.ts",
|
||||||
|
65
ts/cli.ts
65
ts/cli.ts
@@ -72,6 +72,7 @@ export class NupstCli {
|
|||||||
const upsHandler = this.nupst.getUpsHandler();
|
const upsHandler = this.nupst.getUpsHandler();
|
||||||
const groupHandler = this.nupst.getGroupHandler();
|
const groupHandler = this.nupst.getGroupHandler();
|
||||||
const serviceHandler = this.nupst.getServiceHandler();
|
const serviceHandler = this.nupst.getServiceHandler();
|
||||||
|
const actionHandler = this.nupst.getActionHandler();
|
||||||
|
|
||||||
// Handle service subcommands
|
// Handle service subcommands
|
||||||
if (command === 'service') {
|
if (command === 'service') {
|
||||||
@@ -193,6 +194,38 @@ export class NupstCli {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle action subcommands
|
||||||
|
if (command === 'action') {
|
||||||
|
const subcommand = commandArgs[0] || 'list';
|
||||||
|
const subcommandArgs = commandArgs.slice(1);
|
||||||
|
|
||||||
|
switch (subcommand) {
|
||||||
|
case 'add': {
|
||||||
|
const upsId = subcommandArgs[0];
|
||||||
|
await actionHandler.add(upsId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'remove':
|
||||||
|
case 'rm': // Alias
|
||||||
|
case 'delete': { // Backward compatibility
|
||||||
|
const upsId = subcommandArgs[0];
|
||||||
|
const actionIndex = subcommandArgs[1];
|
||||||
|
await actionHandler.remove(upsId, actionIndex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'list':
|
||||||
|
case 'ls': { // Alias
|
||||||
|
const upsId = subcommandArgs[0];
|
||||||
|
await actionHandler.list(upsId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
this.showActionHelp();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle config subcommand
|
// Handle config subcommand
|
||||||
if (command === 'config') {
|
if (command === 'config') {
|
||||||
const subcommand = commandArgs[0] || 'show';
|
const subcommand = commandArgs[0] || 'show';
|
||||||
@@ -499,6 +532,7 @@ export class NupstCli {
|
|||||||
this.printCommand('service <subcommand>', 'Manage systemd service');
|
this.printCommand('service <subcommand>', 'Manage systemd service');
|
||||||
this.printCommand('ups <subcommand>', 'Manage UPS devices');
|
this.printCommand('ups <subcommand>', 'Manage UPS devices');
|
||||||
this.printCommand('group <subcommand>', 'Manage UPS groups');
|
this.printCommand('group <subcommand>', 'Manage UPS groups');
|
||||||
|
this.printCommand('action <subcommand>', 'Manage UPS actions');
|
||||||
this.printCommand('config [show]', 'Display current configuration');
|
this.printCommand('config [show]', 'Display current configuration');
|
||||||
this.printCommand('update', 'Update NUPST from repository', theme.dim('(requires root)'));
|
this.printCommand('update', 'Update NUPST from repository', theme.dim('(requires root)'));
|
||||||
this.printCommand('uninstall', 'Completely remove NUPST', theme.dim('(requires root)'));
|
this.printCommand('uninstall', 'Completely remove NUPST', theme.dim('(requires root)'));
|
||||||
@@ -535,6 +569,13 @@ export class NupstCli {
|
|||||||
this.printCommand('nupst group list (or ls)', 'List all UPS groups');
|
this.printCommand('nupst group list (or ls)', 'List all UPS groups');
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|
||||||
|
// Action subcommands
|
||||||
|
logger.log(theme.info('Action Subcommands:'));
|
||||||
|
this.printCommand('nupst action add <target-id>', 'Add a new action to a UPS or group');
|
||||||
|
this.printCommand('nupst action remove <target-id> <index>', 'Remove an action by index');
|
||||||
|
this.printCommand('nupst action list [target-id]', 'List all actions (optionally for specific target)');
|
||||||
|
console.log('');
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
logger.log(theme.info('Options:'));
|
logger.log(theme.info('Options:'));
|
||||||
this.printCommand('--debug, -d', 'Enable debug mode for detailed SNMP logging');
|
this.printCommand('--debug, -d', 'Enable debug mode for detailed SNMP logging');
|
||||||
@@ -639,6 +680,30 @@ Examples:
|
|||||||
nupst group add - Create a new group
|
nupst group add - Create a new group
|
||||||
nupst group edit dc-1 - Edit group with ID 'dc-1'
|
nupst group edit dc-1 - Edit group with ID 'dc-1'
|
||||||
nupst group remove dc-1 - Remove group with ID 'dc-1'
|
nupst group remove dc-1 - Remove group with ID 'dc-1'
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
private showActionHelp(): void {
|
||||||
|
logger.log(`
|
||||||
|
NUPST - Action Management Commands
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
nupst action <subcommand> [arguments]
|
||||||
|
|
||||||
|
Subcommands:
|
||||||
|
add <ups-id|group-id> - Add a new action to a UPS or group interactively
|
||||||
|
remove <ups-id|group-id> <index> - Remove an action by index (alias: rm, delete)
|
||||||
|
list [ups-id|group-id] - List all actions (optionally for specific target) (alias: ls)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--debug, -d - Enable debug mode for detailed logging
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
nupst action list - List actions for all UPS devices and groups
|
||||||
|
nupst action list default - List actions for UPS or group with ID 'default'
|
||||||
|
nupst action add default - Add a new action to UPS or group 'default'
|
||||||
|
nupst action remove default 0 - Remove action at index 0 from UPS or group 'default'
|
||||||
|
nupst action add dc-rack-1 - Add a new action to group 'dc-rack-1'
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
357
ts/cli/action-handler.ts
Normal file
357
ts/cli/action-handler.ts
Normal file
@@ -0,0 +1,357 @@
|
|||||||
|
import process from 'node:process';
|
||||||
|
import { Nupst } from '../nupst.ts';
|
||||||
|
import { logger, type ITableColumn } from '../logger.ts';
|
||||||
|
import { theme, symbols } from '../colors.ts';
|
||||||
|
import type { IActionConfig } from '../actions/base-action.ts';
|
||||||
|
import type { IUpsConfig, IGroupConfig } from '../daemon.ts';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for handling action-related CLI commands
|
||||||
|
* Provides interface for managing UPS actions
|
||||||
|
*/
|
||||||
|
export class ActionHandler {
|
||||||
|
private readonly nupst: Nupst;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new action handler
|
||||||
|
* @param nupst Reference to the main Nupst instance
|
||||||
|
*/
|
||||||
|
constructor(nupst: Nupst) {
|
||||||
|
this.nupst = nupst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new action to a UPS or group
|
||||||
|
*/
|
||||||
|
public async add(targetId?: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!targetId) {
|
||||||
|
logger.error('Target ID is required');
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('Usage:')} ${theme.command('nupst action add <ups-id|group-id>')}`,
|
||||||
|
);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(` ${theme.dim('List UPS devices:')} ${theme.command('nupst ups list')}`);
|
||||||
|
logger.log(` ${theme.dim('List groups:')} ${theme.command('nupst group list')}`);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = await this.nupst.getDaemon().loadConfig();
|
||||||
|
|
||||||
|
// Check if it's a UPS
|
||||||
|
const ups = config.upsDevices.find((u) => u.id === targetId);
|
||||||
|
// Check if it's a group
|
||||||
|
const group = config.groups?.find((g) => g.id === targetId);
|
||||||
|
|
||||||
|
if (!ups && !group) {
|
||||||
|
logger.error(`UPS or Group with ID '${targetId}' not found`);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(` ${theme.dim('List available UPS devices:')} ${theme.command('nupst ups list')}`);
|
||||||
|
logger.log(` ${theme.dim('List available groups:')} ${theme.command('nupst group list')}`);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const target = ups || group;
|
||||||
|
const targetType = ups ? 'UPS' : 'Group';
|
||||||
|
const targetName = ups ? ups.name : group!.name;
|
||||||
|
|
||||||
|
const readline = await import('node:readline');
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout,
|
||||||
|
});
|
||||||
|
|
||||||
|
const prompt = (question: string): Promise<string> => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
rl.question(question, (answer: string) => {
|
||||||
|
resolve(answer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.log('');
|
||||||
|
logger.info(`Add Action to ${targetType} ${theme.highlight(targetName)}`);
|
||||||
|
logger.log('');
|
||||||
|
|
||||||
|
// Action type (currently only shutdown is supported)
|
||||||
|
const type = 'shutdown';
|
||||||
|
logger.log(` ${theme.dim('Action type:')} ${theme.highlight('shutdown')}`);
|
||||||
|
|
||||||
|
// Battery threshold
|
||||||
|
const batteryStr = await prompt(
|
||||||
|
` ${theme.dim('Battery threshold')} ${theme.dim('(%):')} `,
|
||||||
|
);
|
||||||
|
const battery = parseInt(batteryStr, 10);
|
||||||
|
if (isNaN(battery) || battery < 0 || battery > 100) {
|
||||||
|
logger.error('Invalid battery threshold. Must be 0-100.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runtime threshold
|
||||||
|
const runtimeStr = await prompt(
|
||||||
|
` ${theme.dim('Runtime threshold')} ${theme.dim('(minutes):')} `,
|
||||||
|
);
|
||||||
|
const runtime = parseInt(runtimeStr, 10);
|
||||||
|
if (isNaN(runtime) || runtime < 0) {
|
||||||
|
logger.error('Invalid runtime threshold. Must be >= 0.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger mode
|
||||||
|
logger.log('');
|
||||||
|
logger.log(` ${theme.dim('Trigger mode:')}`);
|
||||||
|
logger.log(` ${theme.dim('1)')} onlyPowerChanges - Trigger only when power status changes`);
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('2)')} onlyThresholds - Trigger only when thresholds are violated`,
|
||||||
|
);
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('3)')} powerChangesAndThresholds - Trigger on power change AND thresholds`,
|
||||||
|
);
|
||||||
|
logger.log(` ${theme.dim('4)')} anyChange - Trigger on any status change`);
|
||||||
|
const triggerChoice = await prompt(` ${theme.dim('Choice')} ${theme.dim('[2]:')} `);
|
||||||
|
const triggerModeMap: Record<string, string> = {
|
||||||
|
'1': 'onlyPowerChanges',
|
||||||
|
'2': 'onlyThresholds',
|
||||||
|
'3': 'powerChangesAndThresholds',
|
||||||
|
'4': 'anyChange',
|
||||||
|
'': 'onlyThresholds', // Default
|
||||||
|
};
|
||||||
|
const triggerMode = triggerModeMap[triggerChoice] || 'onlyThresholds';
|
||||||
|
|
||||||
|
// Shutdown delay
|
||||||
|
const delayStr = await prompt(
|
||||||
|
` ${theme.dim('Shutdown delay')} ${theme.dim('(seconds) [5]:')} `,
|
||||||
|
);
|
||||||
|
const shutdownDelay = delayStr ? parseInt(delayStr, 10) : 5;
|
||||||
|
if (isNaN(shutdownDelay) || shutdownDelay < 0) {
|
||||||
|
logger.error('Invalid shutdown delay. Must be >= 0.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the action
|
||||||
|
const newAction: IActionConfig = {
|
||||||
|
type,
|
||||||
|
thresholds: {
|
||||||
|
battery,
|
||||||
|
runtime,
|
||||||
|
},
|
||||||
|
triggerMode: triggerMode as IActionConfig['triggerMode'],
|
||||||
|
shutdownDelay,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add to target (UPS or group)
|
||||||
|
if (!target!.actions) {
|
||||||
|
target!.actions = [];
|
||||||
|
}
|
||||||
|
target!.actions.push(newAction);
|
||||||
|
|
||||||
|
await this.nupst.getDaemon().saveConfig(config);
|
||||||
|
|
||||||
|
logger.log('');
|
||||||
|
logger.success(`Action added to ${targetType} ${targetName}`);
|
||||||
|
logger.log(` ${theme.dim('Changes saved and will be applied automatically')}`);
|
||||||
|
logger.log('');
|
||||||
|
} finally {
|
||||||
|
rl.close();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to add action: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an action from a UPS or group
|
||||||
|
*/
|
||||||
|
public async remove(targetId?: string, actionIndexStr?: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (!targetId || !actionIndexStr) {
|
||||||
|
logger.error('Target ID and action index are required');
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('Usage:')} ${theme.command('nupst action remove <ups-id|group-id> <action-index>')}`,
|
||||||
|
);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(` ${theme.dim('List actions:')} ${theme.command('nupst action list')}`);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionIndex = parseInt(actionIndexStr, 10);
|
||||||
|
if (isNaN(actionIndex) || actionIndex < 0) {
|
||||||
|
logger.error('Invalid action index. Must be >= 0.');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = await this.nupst.getDaemon().loadConfig();
|
||||||
|
|
||||||
|
// Check if it's a UPS
|
||||||
|
const ups = config.upsDevices.find((u) => u.id === targetId);
|
||||||
|
// Check if it's a group
|
||||||
|
const group = config.groups?.find((g) => g.id === targetId);
|
||||||
|
|
||||||
|
if (!ups && !group) {
|
||||||
|
logger.error(`UPS or Group with ID '${targetId}' not found`);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(` ${theme.dim('List available UPS devices:')} ${theme.command('nupst ups list')}`);
|
||||||
|
logger.log(` ${theme.dim('List available groups:')} ${theme.command('nupst group list')}`);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const target = ups || group;
|
||||||
|
const targetType = ups ? 'UPS' : 'Group';
|
||||||
|
const targetName = ups ? ups.name : group!.name;
|
||||||
|
|
||||||
|
if (!target!.actions || target!.actions.length === 0) {
|
||||||
|
logger.error(`No actions configured for ${targetType} '${targetName}'`);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionIndex >= target!.actions.length) {
|
||||||
|
logger.error(
|
||||||
|
`Invalid action index. ${targetType} '${targetName}' has ${target!.actions.length} action(s) (index 0-${target!.actions.length - 1})`,
|
||||||
|
);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('List actions:')} ${theme.command(`nupst action list ${targetId}`)}`,
|
||||||
|
);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedAction = target!.actions[actionIndex];
|
||||||
|
target!.actions.splice(actionIndex, 1);
|
||||||
|
|
||||||
|
await this.nupst.getDaemon().saveConfig(config);
|
||||||
|
|
||||||
|
logger.log('');
|
||||||
|
logger.success(`Action removed from ${targetType} ${targetName}`);
|
||||||
|
logger.log(` ${theme.dim('Type:')} ${removedAction.type}`);
|
||||||
|
if (removedAction.thresholds) {
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('Thresholds:')} Battery: ${removedAction.thresholds.battery}%, Runtime: ${removedAction.thresholds.runtime}min`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
logger.log(` ${theme.dim('Changes saved and will be applied automatically')}`);
|
||||||
|
logger.log('');
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to remove action: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all actions for a specific UPS/group or all devices
|
||||||
|
*/
|
||||||
|
public async list(targetId?: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const config = await this.nupst.getDaemon().loadConfig();
|
||||||
|
|
||||||
|
if (targetId) {
|
||||||
|
// List actions for specific UPS or group
|
||||||
|
const ups = config.upsDevices.find((u) => u.id === targetId);
|
||||||
|
const group = config.groups?.find((g) => g.id === targetId);
|
||||||
|
|
||||||
|
if (!ups && !group) {
|
||||||
|
logger.error(`UPS or Group with ID '${targetId}' not found`);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(` ${theme.dim('List available UPS devices:')} ${theme.command('nupst ups list')}`);
|
||||||
|
logger.log(` ${theme.dim('List available groups:')} ${theme.command('nupst group list')}`);
|
||||||
|
logger.log('');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ups) {
|
||||||
|
this.displayTargetActions(ups, 'UPS');
|
||||||
|
} else {
|
||||||
|
this.displayTargetActions(group!, 'Group');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// List actions for all UPS devices and groups
|
||||||
|
logger.log('');
|
||||||
|
logger.info('Actions for All UPS Devices and Groups');
|
||||||
|
logger.log('');
|
||||||
|
|
||||||
|
let hasAnyActions = false;
|
||||||
|
|
||||||
|
// Display UPS actions
|
||||||
|
for (const ups of config.upsDevices) {
|
||||||
|
if (ups.actions && ups.actions.length > 0) {
|
||||||
|
hasAnyActions = true;
|
||||||
|
this.displayTargetActions(ups, 'UPS');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display Group actions
|
||||||
|
for (const group of config.groups || []) {
|
||||||
|
if (group.actions && group.actions.length > 0) {
|
||||||
|
hasAnyActions = true;
|
||||||
|
this.displayTargetActions(group, 'Group');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasAnyActions) {
|
||||||
|
logger.log(` ${theme.dim('No actions configured')}`);
|
||||||
|
logger.log('');
|
||||||
|
logger.log(
|
||||||
|
` ${theme.dim('Add an action:')} ${theme.command('nupst action add <ups-id|group-id>')}`,
|
||||||
|
);
|
||||||
|
logger.log('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to list actions: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display actions for a single UPS or Group
|
||||||
|
*/
|
||||||
|
private displayTargetActions(
|
||||||
|
target: IUpsConfig | IGroupConfig,
|
||||||
|
targetType: 'UPS' | 'Group',
|
||||||
|
): void {
|
||||||
|
logger.log(
|
||||||
|
`${symbols.info} ${targetType} ${theme.highlight(target.name)} ${theme.dim(`(${target.id})`)}`,
|
||||||
|
);
|
||||||
|
logger.log('');
|
||||||
|
|
||||||
|
if (!target.actions || target.actions.length === 0) {
|
||||||
|
logger.log(` ${theme.dim('No actions configured')}`);
|
||||||
|
logger.log('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ITableColumn[] = [
|
||||||
|
{ header: 'Index', key: 'index', align: 'right' },
|
||||||
|
{ header: 'Type', key: 'type', align: 'left' },
|
||||||
|
{ header: 'Battery', key: 'battery', align: 'right' },
|
||||||
|
{ header: 'Runtime', key: 'runtime', align: 'right' },
|
||||||
|
{ header: 'Trigger Mode', key: 'triggerMode', align: 'left' },
|
||||||
|
{ header: 'Delay', key: 'delay', align: 'right' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const rows = target.actions.map((action, index) => ({
|
||||||
|
index: theme.dim(index.toString()),
|
||||||
|
type: theme.highlight(action.type),
|
||||||
|
battery: action.thresholds ? `${action.thresholds.battery}%` : theme.dim('N/A'),
|
||||||
|
runtime: action.thresholds ? `${action.thresholds.runtime}min` : theme.dim('N/A'),
|
||||||
|
triggerMode: theme.dim(action.triggerMode || 'onlyThresholds'),
|
||||||
|
delay: `${action.shutdownDelay || 5}s`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
logger.logTable(columns, rows);
|
||||||
|
logger.log('');
|
||||||
|
}
|
||||||
|
}
|
10
ts/nupst.ts
10
ts/nupst.ts
@@ -6,6 +6,7 @@ import { logger } from './logger.ts';
|
|||||||
import { UpsHandler } from './cli/ups-handler.ts';
|
import { UpsHandler } from './cli/ups-handler.ts';
|
||||||
import { GroupHandler } from './cli/group-handler.ts';
|
import { GroupHandler } from './cli/group-handler.ts';
|
||||||
import { ServiceHandler } from './cli/service-handler.ts';
|
import { ServiceHandler } from './cli/service-handler.ts';
|
||||||
|
import { ActionHandler } from './cli/action-handler.ts';
|
||||||
import * as https from 'node:https';
|
import * as https from 'node:https';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +20,7 @@ export class Nupst {
|
|||||||
private readonly upsHandler: UpsHandler;
|
private readonly upsHandler: UpsHandler;
|
||||||
private readonly groupHandler: GroupHandler;
|
private readonly groupHandler: GroupHandler;
|
||||||
private readonly serviceHandler: ServiceHandler;
|
private readonly serviceHandler: ServiceHandler;
|
||||||
|
private readonly actionHandler: ActionHandler;
|
||||||
private updateAvailable: boolean = false;
|
private updateAvailable: boolean = false;
|
||||||
private latestVersion: string = '';
|
private latestVersion: string = '';
|
||||||
|
|
||||||
@@ -36,6 +38,7 @@ export class Nupst {
|
|||||||
this.upsHandler = new UpsHandler(this);
|
this.upsHandler = new UpsHandler(this);
|
||||||
this.groupHandler = new GroupHandler(this);
|
this.groupHandler = new GroupHandler(this);
|
||||||
this.serviceHandler = new ServiceHandler(this);
|
this.serviceHandler = new ServiceHandler(this);
|
||||||
|
this.actionHandler = new ActionHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +83,13 @@ export class Nupst {
|
|||||||
return this.serviceHandler;
|
return this.serviceHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Action handler for action management
|
||||||
|
*/
|
||||||
|
public getActionHandler(): ActionHandler {
|
||||||
|
return this.actionHandler;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current version of NUPST
|
* Get the current version of NUPST
|
||||||
* @returns The current version string
|
* @returns The current version string
|
||||||
|
Reference in New Issue
Block a user