feat(daemon): Add UPSD (NUT) protocol support, Proxmox VM shutdown action, pause/resume monitoring, and network-loss/unreachable handling; bump config version to 4.2
This commit is contained in:
@@ -346,13 +346,24 @@ WantedBy=multi-user.target
|
||||
*/
|
||||
private async displaySingleUpsStatus(ups: IUpsConfig, snmp: NupstSnmp): Promise<void> {
|
||||
try {
|
||||
// Create a test config with a short timeout
|
||||
const testConfig = {
|
||||
...ups.snmp,
|
||||
timeout: Math.min(ups.snmp.timeout, 10000), // Use at most 10 seconds for status check
|
||||
};
|
||||
const protocol = ups.protocol || 'snmp';
|
||||
let status;
|
||||
|
||||
const status = await snmp.getUpsStatus(testConfig);
|
||||
if (protocol === 'upsd' && ups.upsd) {
|
||||
const testConfig = {
|
||||
...ups.upsd,
|
||||
timeout: Math.min(ups.upsd.timeout, 10000),
|
||||
};
|
||||
status = await this.daemon.getNupstUpsd().getUpsStatus(testConfig);
|
||||
} else if (ups.snmp) {
|
||||
const testConfig = {
|
||||
...ups.snmp,
|
||||
timeout: Math.min(ups.snmp.timeout, 10000),
|
||||
};
|
||||
status = await snmp.getUpsStatus(testConfig);
|
||||
} else {
|
||||
throw new Error('No protocol configuration found');
|
||||
}
|
||||
|
||||
// Determine status symbol based on power status
|
||||
let statusSymbol = symbols.unknown;
|
||||
@@ -396,7 +407,12 @@ WantedBy=multi-user.target
|
||||
);
|
||||
|
||||
// Display host info
|
||||
logger.log(` ${theme.dim(`Host: ${ups.snmp.host}:${ups.snmp.port}`)}`);
|
||||
const hostInfo = protocol === 'upsd' && ups.upsd
|
||||
? `${ups.upsd.host}:${ups.upsd.port} (UPSD)`
|
||||
: ups.snmp
|
||||
? `${ups.snmp.host}:${ups.snmp.port} (SNMP)`
|
||||
: 'N/A';
|
||||
logger.log(` ${theme.dim(`Host: ${hostInfo}`)}`);
|
||||
|
||||
// Display groups if any
|
||||
if (ups.groups && ups.groups.length > 0) {
|
||||
@@ -434,11 +450,16 @@ WantedBy=multi-user.target
|
||||
logger.log('');
|
||||
} catch (error) {
|
||||
// Display error for this UPS
|
||||
const errorHostInfo = (ups.protocol || 'snmp') === 'upsd' && ups.upsd
|
||||
? `${ups.upsd.host}:${ups.upsd.port} (UPSD)`
|
||||
: ups.snmp
|
||||
? `${ups.snmp.host}:${ups.snmp.port} (SNMP)`
|
||||
: 'N/A';
|
||||
logger.log(
|
||||
` ${symbols.error} ${theme.highlight(ups.name)} - ${theme.error('Connection failed')}`,
|
||||
);
|
||||
logger.log(` ${theme.dim(error instanceof Error ? error.message : String(error))}`);
|
||||
logger.log(` ${theme.dim(`Host: ${ups.snmp.host}:${ups.snmp.port}`)}`);
|
||||
logger.log(` ${theme.dim(`Host: ${errorHostInfo}`)}`);
|
||||
logger.log('');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user