Skip to content

Commit 180234b

Browse files
fix(alerts): add meta to alert object and improve logging (#74)
* fix(alerts): add meta to alert object and improve logging - XForwardedForChecker: Add 'meta' to the alert payload. - HTTPEnricher: Enrich alert metadata in addition to event metadata. - CrowdSecHTTPWatcherMiddleware: Log alert creation as a warning. * ci: update pnpm action to v4 to fix installation issues with newer node versions * chore: require node >= 24 and update ci matrix * chore: require node >= 24 and update ci matrix * ci: limit sonarqube scan to main branch * fix pkg * chore(deps): update lock --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Thibaut SEVERAC <thib3113@gmail.com>
1 parent ac9c5ab commit 180234b

17 files changed

Lines changed: 930 additions & 388 deletions

File tree

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Install Node.js
2929
uses: actions/setup-node@v4
3030
with:
31-
node-version: lts/*
31+
node-version: 24
3232

3333
- uses: pnpm/action-setup@v4
3434
name: Install pnpm
@@ -78,7 +78,7 @@ jobs:
7878
fail-fast: false
7979
matrix:
8080
package: ${{ fromJson(needs.list-packages.outputs.matrix) }}
81-
node-version: [ lts/*, 18, 20, 21, 22, 23, latest ]
81+
node-version: [ 24, latest ]
8282
# The type of runner that the job will run on
8383
runs-on: ubuntu-latest
8484

@@ -138,7 +138,7 @@ jobs:
138138
- name: Install Node.js
139139
uses: actions/setup-node@v4
140140
with:
141-
node-version: lts/*
141+
node-version: 24
142142

143143
- uses: pnpm/action-setup@v4
144144
name: Install pnpm

.github/workflows/build_and_test/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ runs:
3434
id: pnpm-install
3535
with:
3636
run_install: true
37-
version: 9.15.9
3837

3938
- name: Get pnpm store directory
4039
id: pnpm-cache

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Install Node.js
2424
uses: actions/setup-node@v4
2525
with:
26-
node-version: lts/*
26+
node-version: 24
2727

2828
- uses: pnpm/action-setup@v4
2929
name: Install pnpm

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install Node.js
2727
uses: actions/setup-node@v4
2828
with:
29-
node-version: lts/*
29+
node-version: 24
3030

3131
- uses: pnpm/action-setup@v4
3232
name: Install pnpm

package.json

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
{
2-
"name": "node-crowdsec-client-root",
3-
"engines": {
4-
"node": ">=18.12",
5-
"pnpm": ">=9"
6-
},
7-
"license": "UNLICENSED",
8-
"scripts": {
9-
"generate:documentation": "typedoc"
10-
},
11-
"devDependencies": {
12-
"@eslint/eslintrc": "^3.3.5",
13-
"@eslint/js": "^10.0.1",
14-
"@tsconfig/node-lts": "24.0.0",
15-
"@types/jest": "30.0.0",
16-
"@types/node": "25.9.2",
17-
"@typescript-eslint/parser": "8.60.1",
18-
"eslint": "10.4.1",
19-
"eslint-config-prettier": "10.1.8",
20-
"eslint-plugin-prettier": "5.5.6",
21-
"prettier": "3.8.3",
22-
"ts-jest": "^29.4.11",
23-
"ts-node": "10.9.2",
24-
"typedoc": "0.28.19",
25-
"typescript": "6.0.3"
26-
},
2+
"name": "node-crowdsec-client-root",
3+
"engines": {
4+
"node": ">=24",
5+
"pnpm": ">=9"
6+
},
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"generate:documentation": "typedoc"
10+
},
11+
"devDependencies": {
12+
"@tsconfig/node-lts": "20.1.3",
13+
"@types/jest": "29.5.14",
14+
"@types/node": "22.7.6",
15+
"@typescript-eslint/parser": "7.0.2",
16+
"eslint": "8.57.0",
17+
"eslint-config-prettier": "9.1.0",
18+
"eslint-plugin-prettier": "5.1.3",
19+
"prettier": "3.2.5",
20+
"ts-node": "10.9.2",
21+
"typedoc": "0.26.10",
22+
"typescript": "5.6.3"
23+
},
2724
"packageManager": "pnpm@9.15.9"
2825
}

packages/crowdsec-client-scenarios/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"maxmind": "^5.0.6"
6161
},
6262
"engines": {
63-
"node": ">=16"
63+
"node": ">=24"
6464
},
6565
"devDependencies": {
6666
"@jest/globals": "30.4.1",

packages/crowdsec-client-scenarios/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
[![NPM](https://nodei.co/npm/crowdsec-client-scenarios.png)](https://nodei.co/npm/crowdsec-client-scenarios/)
3030

31-
This library is a Node.js client to talk with crowdsec rest API .
31+
This library is a Node.js client to talk with crowdsec rest API . Please note that Node.js >= 24 is required.
3232
# Start
3333

3434
install it

packages/crowdsec-client-scenarios/src/scenarios/HTTPEnricher/HTTPEnricher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class HTTPEnricher extends EnricherScenario {
2828
};
2929

3030
alert.events = alert.events.map((e) => ({ ...e, meta: mergeMetas(e.meta, metas) }));
31+
alert.meta = mergeMetas(alert.meta, metas);
3132

3233
return alert;
3334
}

packages/crowdsec-client-scenarios/src/scenarios/XForwardedFor/XForwardedForChecker.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ export class XForwardedForChecker extends CheckerScenario {
5454
}
5555

5656
private generateAlert(
57-
alert: Omit<APITypes.Alert, 'scenario_version' | 'scenario_hash' | 'capacity' | 'leakspeed' | 'simulated' | 'events' | 'source'> &
58-
Partial<Pick<APITypes.Alert, 'events' | 'capacity' | 'leakspeed' | 'simulated' | 'source'>>,
57+
alert: Omit<
58+
APITypes.Alert,
59+
'scenario_version' | 'scenario_hash' | 'capacity' | 'leakspeed' | 'simulated' | 'events' | 'source' | 'meta'
60+
> &
61+
Partial<Pick<APITypes.Alert, 'events' | 'capacity' | 'leakspeed' | 'simulated' | 'source' | 'meta'>>,
5962
ip: string
6063
): APITypes.Alert {
6164
return {
@@ -128,6 +131,24 @@ export class XForwardedForChecker extends CheckerScenario {
128131
timestamp: date
129132
}
130133
],
134+
meta: [
135+
{
136+
key: 'http_forwarded_for',
137+
value: headers[0]
138+
},
139+
{
140+
key: 'http_forwarded_for_parsed',
141+
value: ipResult.map(({ ip }) => ip).join(', ')
142+
},
143+
{
144+
key: 'source_ip',
145+
value: ipStr
146+
},
147+
{
148+
key: 'timestamp',
149+
value: date
150+
}
151+
],
131152
events_count: 1,
132153
message: `Ip ${ipStr} performed '${scenarioName}' (1 event) at ${date}`,
133154
start_at: date,

packages/crowdsec-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"debug": "^4.4.3"
6060
},
6161
"engines": {
62-
"node": ">=18.12"
62+
"node": ">=24"
6363
},
6464
"devDependencies": {
6565
"@jest/globals": "30.4.1",

0 commit comments

Comments
 (0)