Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
0e7bcab499 | |||
7bf65d8495 | |||
f2ce0180d3 | |||
8c1be6555f | |||
1a5558e91f | |||
611a9ddd19 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@serve.zone/nupst",
|
"name": "@serve.zone/nupst",
|
||||||
"version": "4.2.0",
|
"version": "4.2.3",
|
||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"dev": "deno run --allow-all mod.ts",
|
"dev": "deno run --allow-all mod.ts",
|
||||||
|
@@ -123,9 +123,6 @@ export class UpsHandler {
|
|||||||
// Gather SNMP settings
|
// Gather SNMP settings
|
||||||
await this.gatherSnmpSettings(newUps.snmp, prompt);
|
await this.gatherSnmpSettings(newUps.snmp, prompt);
|
||||||
|
|
||||||
// Gather threshold settings
|
|
||||||
await this.gatherThresholdSettings(newUps.thresholds, prompt);
|
|
||||||
|
|
||||||
// Gather UPS model settings
|
// Gather UPS model settings
|
||||||
await this.gatherUpsModelSettings(newUps.snmp, prompt);
|
await this.gatherUpsModelSettings(newUps.snmp, prompt);
|
||||||
|
|
||||||
@@ -820,39 +817,6 @@ export class UpsHandler {
|
|||||||
snmpConfig.privKey = privKey.trim() || defaultPrivKey;
|
snmpConfig.privKey = privKey.trim() || defaultPrivKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gather threshold settings
|
|
||||||
* @param thresholds Thresholds configuration object to update
|
|
||||||
* @param prompt Function to prompt for user input
|
|
||||||
*/
|
|
||||||
private async gatherThresholdSettings(
|
|
||||||
thresholds: any,
|
|
||||||
prompt: (question: string) => Promise<string>,
|
|
||||||
): Promise<void> {
|
|
||||||
logger.log('');
|
|
||||||
logger.info('Shutdown Thresholds:');
|
|
||||||
|
|
||||||
// Battery threshold
|
|
||||||
const defaultBatteryThreshold = thresholds.battery || 60;
|
|
||||||
const batteryThresholdInput = await prompt(
|
|
||||||
`Battery percentage threshold [${defaultBatteryThreshold}%]: `,
|
|
||||||
);
|
|
||||||
const batteryThreshold = parseInt(batteryThresholdInput, 10);
|
|
||||||
thresholds.battery = batteryThresholdInput.trim() && !isNaN(batteryThreshold)
|
|
||||||
? batteryThreshold
|
|
||||||
: defaultBatteryThreshold;
|
|
||||||
|
|
||||||
// Runtime threshold
|
|
||||||
const defaultRuntimeThreshold = thresholds.runtime || 20;
|
|
||||||
const runtimeThresholdInput = await prompt(
|
|
||||||
`Runtime minutes threshold [${defaultRuntimeThreshold} minutes]: `,
|
|
||||||
);
|
|
||||||
const runtimeThreshold = parseInt(runtimeThresholdInput, 10);
|
|
||||||
thresholds.runtime = runtimeThresholdInput.trim() && !isNaN(runtimeThreshold)
|
|
||||||
? runtimeThreshold
|
|
||||||
: defaultRuntimeThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather UPS model settings
|
* Gather UPS model settings
|
||||||
* @param snmpConfig SNMP configuration object to update
|
* @param snmpConfig SNMP configuration object to update
|
||||||
|
@@ -19,7 +19,7 @@ export class MigrationRunner {
|
|||||||
new MigrationV1ToV2(),
|
new MigrationV1ToV2(),
|
||||||
new MigrationV3ToV4(),
|
new MigrationV3ToV4(),
|
||||||
new MigrationV4_0ToV4_1(),
|
new MigrationV4_0ToV4_1(),
|
||||||
// Add future migrations here (v4.2, v4.3, etc.)
|
// Add future migrations here (v4.3, v4.4, etc.)
|
||||||
];
|
];
|
||||||
|
|
||||||
// Sort by version order to ensure they run in sequence
|
// Sort by version order to ensure they run in sequence
|
||||||
|
@@ -10,7 +10,7 @@ import { logger } from '../logger.ts';
|
|||||||
* 3. Adds empty actions array to UPS devices without actions
|
* 3. Adds empty actions array to UPS devices without actions
|
||||||
* 4. Adds empty actions array to groups
|
* 4. Adds empty actions array to groups
|
||||||
*
|
*
|
||||||
* Transforms v4.0 format:
|
* Transforms v4.0 format (with UPS-level thresholds):
|
||||||
* {
|
* {
|
||||||
* version: "4.0",
|
* version: "4.0",
|
||||||
* upsDevices: [
|
* upsDevices: [
|
||||||
@@ -24,7 +24,7 @@ import { logger } from '../logger.ts';
|
|||||||
* ]
|
* ]
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* To v4.1 format:
|
* To v4.1 format (with action-level thresholds):
|
||||||
* {
|
* {
|
||||||
* version: "4.1",
|
* version: "4.1",
|
||||||
* upsDevices: [
|
* upsDevices: [
|
||||||
@@ -37,7 +37,7 @@ import { logger } from '../logger.ts';
|
|||||||
* {
|
* {
|
||||||
* type: "shutdown",
|
* type: "shutdown",
|
||||||
* thresholds: { battery: 60, runtime: 20 },
|
* thresholds: { battery: 60, runtime: 20 },
|
||||||
* onlyOnThresholdViolation: true,
|
* triggerMode: "onlyThresholds",
|
||||||
* shutdownDelay: 5
|
* shutdownDelay: 5
|
||||||
* }
|
* }
|
||||||
* ]
|
* ]
|
||||||
@@ -50,7 +50,7 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
|
|||||||
readonly toVersion = '4.1';
|
readonly toVersion = '4.1';
|
||||||
|
|
||||||
async shouldRun(config: any): Promise<boolean> {
|
async shouldRun(config: any): Promise<boolean> {
|
||||||
// Run if config is version 4.0 or missing version with v4 structure
|
// Run if config is version 4.0
|
||||||
if (config.version === '4.0') {
|
if (config.version === '4.0') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
|
|||||||
if (config.upsDevices && config.upsDevices.length > 0) {
|
if (config.upsDevices && config.upsDevices.length > 0) {
|
||||||
const firstDevice = config.upsDevices[0];
|
const firstDevice = config.upsDevices[0];
|
||||||
// v4.0 has thresholds at UPS level, v4.1 has them in actions
|
// v4.0 has thresholds at UPS level, v4.1 has them in actions
|
||||||
return firstDevice.thresholds !== undefined && firstDevice.actions === undefined;
|
return firstDevice.thresholds !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user