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:
2026-02-20 11:51:59 +00:00
parent 782c8c9555
commit 42b8eaf6d2
30 changed files with 2183 additions and 697 deletions

View File

@@ -1,7 +1,7 @@
import * as http from 'node:http';
import { URL } from 'node:url';
import { logger } from './logger.ts';
import type { IUpsStatus } from './daemon.ts';
import type { IPauseState, IUpsStatus } from './daemon.ts';
/**
* HTTP Server for exposing UPS status as JSON
@@ -13,6 +13,7 @@ export class NupstHttpServer {
private path: string;
private authToken: string;
private getUpsStatus: () => Map<string, IUpsStatus>;
private getPauseState: () => IPauseState | null;
/**
* Create a new HTTP server instance
@@ -20,17 +21,20 @@ export class NupstHttpServer {
* @param path URL path for the endpoint
* @param authToken Authentication token required for access
* @param getUpsStatus Function to retrieve cached UPS status
* @param getPauseState Function to retrieve current pause state
*/
constructor(
port: number,
path: string,
authToken: string,
getUpsStatus: () => Map<string, IUpsStatus>,
getPauseState: () => IPauseState | null,
) {
this.port = port;
this.path = path;
this.authToken = authToken;
this.getUpsStatus = getUpsStatus;
this.getPauseState = getPauseState;
}
/**
@@ -79,12 +83,18 @@ export class NupstHttpServer {
// Get cached status (no refresh)
const statusMap = this.getUpsStatus();
const statusArray = Array.from(statusMap.values());
const pauseState = this.getPauseState();
const response = {
upsDevices: statusArray,
...(pauseState ? { paused: true, pauseState } : { paused: false }),
};
res.writeHead(200, {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
});
res.end(JSON.stringify(statusArray, null, 2));
res.end(JSON.stringify(response, null, 2));
} else {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Not Found' }));