Feat : Log recorder
This commit is contained in:
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
|
||||
import type { IncomingMessage } from 'node:http';
|
||||
import type { RawData, WebSocket } from 'ws';
|
||||
import type { AgentToServer, ServerToAgent } from '@stream-control/shared';
|
||||
import { PROTOCOL_VERSION, detectPlatform, safeJsonParse } from '@stream-control/shared';
|
||||
import { PROTOCOL_VERSION, detectPlatform, isAgentEvent, safeJsonParse } from '@stream-control/shared';
|
||||
import { config } from './config.ts';
|
||||
import { extractBearer, generateToken, hashToken, safeEqual } from './auth.ts';
|
||||
import { agentsRepo, type AgentRecord } from './db.ts';
|
||||
@@ -88,7 +88,13 @@ export function handleAgentConnection(
|
||||
platform,
|
||||
agentVersion: message.agentVersion,
|
||||
});
|
||||
hub.log(record.id, 'info', `Nouvel agent enrôlé depuis ${remoteAddress}`);
|
||||
hub.log(
|
||||
record.id,
|
||||
'info',
|
||||
`Nouvel agent enrôlé depuis ${remoteAddress}`,
|
||||
Date.now(),
|
||||
'agent.enrolled',
|
||||
);
|
||||
} else {
|
||||
record = auth.record;
|
||||
agentsRepo.updateIdentity(record.id, {
|
||||
@@ -101,7 +107,13 @@ export function handleAgentConnection(
|
||||
|
||||
agentId = record.id;
|
||||
hub.attachAgent(record.id, socket);
|
||||
hub.log(record.id, 'info', `Agent connecté (${platform}, ${remoteAddress})`);
|
||||
hub.log(
|
||||
record.id,
|
||||
'info',
|
||||
`Agent connecté (${platform}, ${remoteAddress})`,
|
||||
Date.now(),
|
||||
'agent.connected',
|
||||
);
|
||||
|
||||
send(socket, {
|
||||
type: 'welcome',
|
||||
@@ -132,7 +144,13 @@ export function handleAgentConnection(
|
||||
}
|
||||
|
||||
case 'log': {
|
||||
hub.log(agentId, message.level, message.message, message.ts || Date.now());
|
||||
hub.log(
|
||||
agentId,
|
||||
message.level,
|
||||
message.message,
|
||||
message.ts || Date.now(),
|
||||
isAgentEvent(message.event) ? message.event : null,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -147,7 +165,7 @@ export function handleAgentConnection(
|
||||
clearTimeout(helloTimer);
|
||||
if (agentId) {
|
||||
hub.detachAgent(agentId, socket);
|
||||
hub.log(agentId, 'info', 'Agent déconnecté');
|
||||
hub.log(agentId, 'info', 'Agent déconnecté', Date.now(), 'agent.disconnected');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user