feat(monitoring,inspector,metrics): fix rollup/probe bugs, add net/disk/probe history, TLS expiry & Prometheus /metrics

This commit is contained in:
tyuXX 2026-11-27 22:53:15 +00:00
parent ca67c85fbf
commit dbf7144c5d
11 changed files with 954 additions and 174 deletions

View file

@ -1,8 +1,9 @@
import crypto from 'node:crypto';
import { Router, type RequestHandler } from 'express';
import { ZodError, z } from 'zod';
import type { ConfigManager } from '../../config/config-manager.js';
import type { AuditService } from '../../security/audit.js';
import type { AuthService } from '../../security/auth.js';
import { sha256Hex, type AuthService } from '../../security/auth.js';
import {
enforceSafeMode,
requireAuth,
@ -237,5 +238,50 @@ export function createConfigRouter(deps: ConfigRouterDeps): Router {
},
);
router.post(
'/prometheus-token',
requireAuth(authService),
requireCsrf,
enforceSafeMode,
stepUpGuard,
(req, res) => {
const parsed = z
.object({ enable: z.boolean().optional() })
.safeParse(req.body ?? {});
if (!parsed.success) {
res.status(400).json({ error: 'VALIDATION_ERROR', issues: parsed.error.issues });
return;
}
const token = crypto.randomBytes(32).toString('base64url');
const tokenHash = sha256Hex(token);
const next = structuredClone(configManager.getSettings());
next.metrics.prometheusTokenHash = tokenHash;
if (parsed.data.enable !== undefined) {
next.metrics.prometheusEnabled = parsed.data.enable;
} else {
next.metrics.prometheusEnabled = true;
}
configManager.saveConfigText(
'settings.json',
JSON.stringify(next, null, 2),
'ui',
'Rotate Prometheus metrics Bearer token',
);
auditService.log({
action: 'metrics.prometheus_token_rotate',
actorIp: req.clientIp ?? 'unknown',
sessionIdHash: req.authSession!.idHash,
target: 'settings.json',
status: 'ok',
details: { prometheusEnabled: next.metrics.prometheusEnabled },
});
res.json({
token,
tokenHash,
prometheusEnabled: next.metrics.prometheusEnabled,
});
},
);
return router;
}