fix bot events

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-01 10:20:27 +01:00
parent 94614f1217
commit 4cc2f7a329
2 changed files with 6 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
if (bot) { if (bot) {
const path = (req.body?.properties?.__path || const path = (req.body?.properties?.__path ||
req.body?.properties?.path) as string | undefined; req.body?.properties?.path) as string | undefined;
reply.log.warn({ ...req.headers, bot }, 'Bot detected (event)'); req.log.warn({ ...req.headers, bot }, 'Bot detected (event)');
await createBotEvent({ await createBotEvent({
...bot, ...bot,
projectId, projectId,
@@ -36,7 +36,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
reply.status(202).send('OK'); reply.status(202).send('OK');
} }
} catch (e) { } catch (e) {
reply.log.warn(e, 'Érror'); req.log.error(e, 'Failed to create bot event');
reply.status(401).send(); reply.status(401).send();
return; return;
} }

View File

@@ -320,6 +320,7 @@ export async function getEventsCount({
interface CreateBotEventPayload { interface CreateBotEventPayload {
name: string; name: string;
type: string; type: string;
path: string;
projectId: string; projectId: string;
createdAt: Date; createdAt: Date;
} }
@@ -329,14 +330,17 @@ export function createBotEvent({
type, type,
projectId, projectId,
createdAt, createdAt,
path,
}: CreateBotEventPayload) { }: CreateBotEventPayload) {
return ch.insert({ return ch.insert({
table: 'events_bots', table: 'events_bots',
format: 'JSONEachRow',
values: [ values: [
{ {
name, name,
type, type,
project_id: projectId, project_id: projectId,
path,
created_at: formatClickhouseDate(createdAt), created_at: formatClickhouseDate(createdAt),
}, },
], ],