Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef3d3f3fa3 | |||
34e6e850ad | |||
992a776fd2 | |||
3e15a2d52f |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@serve.zone/nupst",
|
"name": "@serve.zone/nupst",
|
||||||
"version": "4.3.1",
|
"version": "4.3.3",
|
||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"dev": "deno run --allow-all mod.ts",
|
"dev": "deno run --allow-all mod.ts",
|
||||||
|
@@ -152,10 +152,7 @@ export class ActionHandler {
|
|||||||
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
logger.success(`Action added to ${targetType} ${targetName}`);
|
logger.success(`Action added to ${targetType} ${targetName}`);
|
||||||
logger.log('');
|
logger.log(` ${theme.dim('Changes saved and will be applied automatically')}`);
|
||||||
logger.log(
|
|
||||||
` ${theme.dim('Restart service to apply changes:')} ${theme.command('nupst service restart')}`,
|
|
||||||
);
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
} finally {
|
} finally {
|
||||||
rl.close();
|
rl.close();
|
||||||
@@ -241,10 +238,7 @@ export class ActionHandler {
|
|||||||
` ${theme.dim('Thresholds:')} Battery: ${removedAction.thresholds.battery}%, Runtime: ${removedAction.thresholds.runtime}min`,
|
` ${theme.dim('Thresholds:')} Battery: ${removedAction.thresholds.battery}%, Runtime: ${removedAction.thresholds.runtime}min`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
logger.log('');
|
logger.log(` ${theme.dim('Changes saved and will be applied automatically')}`);
|
||||||
logger.log(
|
|
||||||
` ${theme.dim('Restart service to apply changes:')} ${theme.command('nupst service restart')}`,
|
|
||||||
);
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@@ -277,6 +277,9 @@ WantedBy=multi-user.target
|
|||||||
for (const ups of config.upsDevices) {
|
for (const ups of config.upsDevices) {
|
||||||
await this.displaySingleUpsStatus(ups, snmp);
|
await this.displaySingleUpsStatus(ups, snmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display groups after UPS devices
|
||||||
|
this.displayGroupsStatus();
|
||||||
} else if (config.snmp) {
|
} else if (config.snmp) {
|
||||||
// Legacy single UPS configuration (v1/v2 format)
|
// Legacy single UPS configuration (v1/v2 format)
|
||||||
logger.info('UPS Devices (1):');
|
logger.info('UPS Devices (1):');
|
||||||
@@ -365,6 +368,27 @@ WantedBy=multi-user.target
|
|||||||
logger.log(` ${theme.dim(`Groups: ${groupNames.join(', ')}`)}`);
|
logger.log(` ${theme.dim(`Groups: ${groupNames.join(', ')}`)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Display actions if any
|
||||||
|
if (ups.actions && ups.actions.length > 0) {
|
||||||
|
for (const action of ups.actions) {
|
||||||
|
let actionDesc = `${action.type}`;
|
||||||
|
if (action.thresholds) {
|
||||||
|
actionDesc += ` (${action.triggerMode || 'onlyThresholds'}: battery<${action.thresholds.battery}%, runtime<${action.thresholds.runtime}min`;
|
||||||
|
if (action.shutdownDelay) {
|
||||||
|
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||||
|
}
|
||||||
|
actionDesc += ')';
|
||||||
|
} else {
|
||||||
|
actionDesc += ` (${action.triggerMode || 'onlyPowerChanges'}`;
|
||||||
|
if (action.shutdownDelay) {
|
||||||
|
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||||
|
}
|
||||||
|
actionDesc += ')';
|
||||||
|
}
|
||||||
|
logger.log(` ${theme.dim('Action:')} ${theme.info(actionDesc)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.log('');
|
logger.log('');
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -376,6 +400,69 @@ WantedBy=multi-user.target
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display status of all groups
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private displayGroupsStatus(): void {
|
||||||
|
const config = this.daemon.getConfig();
|
||||||
|
|
||||||
|
if (!config.groups || config.groups.length === 0) {
|
||||||
|
return; // No groups to display
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log('');
|
||||||
|
logger.info(`Groups (${config.groups.length}):`);
|
||||||
|
|
||||||
|
for (const group of config.groups) {
|
||||||
|
// Display group name and mode
|
||||||
|
const modeColor = group.mode === 'redundant' ? theme.success : theme.warning;
|
||||||
|
logger.log(
|
||||||
|
` ${symbols.info} ${theme.highlight(group.name)} ${theme.dim(`(${modeColor(group.mode)})`)}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Display description if present
|
||||||
|
if (group.description) {
|
||||||
|
logger.log(` ${theme.dim(group.description)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display UPS devices in this group
|
||||||
|
const upsInGroup = config.upsDevices.filter((ups) =>
|
||||||
|
ups.groups && ups.groups.includes(group.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (upsInGroup.length > 0) {
|
||||||
|
const upsNames = upsInGroup.map((ups) => ups.name).join(', ');
|
||||||
|
logger.log(` ${theme.dim(`UPS Devices (${upsInGroup.length}):`)} ${upsNames}`);
|
||||||
|
} else {
|
||||||
|
logger.log(` ${theme.dim('UPS Devices: None')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display actions if any
|
||||||
|
if (group.actions && group.actions.length > 0) {
|
||||||
|
for (const action of group.actions) {
|
||||||
|
let actionDesc = `${action.type}`;
|
||||||
|
if (action.thresholds) {
|
||||||
|
actionDesc += ` (${action.triggerMode || 'onlyThresholds'}: battery<${action.thresholds.battery}%, runtime<${action.thresholds.runtime}min`;
|
||||||
|
if (action.shutdownDelay) {
|
||||||
|
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||||
|
}
|
||||||
|
actionDesc += ')';
|
||||||
|
} else {
|
||||||
|
actionDesc += ` (${action.triggerMode || 'onlyPowerChanges'}`;
|
||||||
|
if (action.shutdownDelay) {
|
||||||
|
actionDesc += `, delay=${action.shutdownDelay}s`;
|
||||||
|
}
|
||||||
|
actionDesc += ')';
|
||||||
|
}
|
||||||
|
logger.log(` ${theme.dim('Action:')} ${theme.info(actionDesc)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable and uninstall the systemd service
|
* Disable and uninstall the systemd service
|
||||||
* @throws Error if disabling fails
|
* @throws Error if disabling fails
|
||||||
|
Reference in New Issue
Block a user