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:
49
ts/protocol/resolver.ts
Normal file
49
ts/protocol/resolver.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* ProtocolResolver - Routes UPS status queries to the correct protocol implementation
|
||||
*
|
||||
* Abstracts away SNMP vs UPSD differences so the daemon is protocol-agnostic.
|
||||
* Both protocols return the same IUpsStatus interface from ts/snmp/types.ts.
|
||||
*/
|
||||
|
||||
import type { NupstSnmp } from '../snmp/manager.ts';
|
||||
import type { NupstUpsd } from '../upsd/client.ts';
|
||||
import type { ISnmpConfig, IUpsStatus } from '../snmp/types.ts';
|
||||
import type { IUpsdConfig } from '../upsd/types.ts';
|
||||
import type { TProtocol } from './types.ts';
|
||||
|
||||
export class ProtocolResolver {
|
||||
private snmp: NupstSnmp;
|
||||
private upsd: NupstUpsd;
|
||||
|
||||
constructor(snmp: NupstSnmp, upsd: NupstUpsd) {
|
||||
this.snmp = snmp;
|
||||
this.upsd = upsd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UPS status using the specified protocol
|
||||
* @param protocol Protocol to use ('snmp' or 'upsd')
|
||||
* @param snmpConfig SNMP configuration (required for 'snmp' protocol)
|
||||
* @param upsdConfig UPSD configuration (required for 'upsd' protocol)
|
||||
* @returns UPS status
|
||||
*/
|
||||
public getUpsStatus(
|
||||
protocol: TProtocol,
|
||||
snmpConfig?: ISnmpConfig,
|
||||
upsdConfig?: IUpsdConfig,
|
||||
): Promise<IUpsStatus> {
|
||||
switch (protocol) {
|
||||
case 'upsd':
|
||||
if (!upsdConfig) {
|
||||
throw new Error('UPSD configuration required for UPSD protocol');
|
||||
}
|
||||
return this.upsd.getUpsStatus(upsdConfig);
|
||||
case 'snmp':
|
||||
default:
|
||||
if (!snmpConfig) {
|
||||
throw new Error('SNMP configuration required for SNMP protocol');
|
||||
}
|
||||
return this.snmp.getUpsStatus(snmpConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user