Skip to content

Commit

Permalink
Merge pull request #991 from MTES-MCT/brevo-status
Browse files Browse the repository at this point in the history
feat: add monitoring for Brevo service in healthcheck endpoint
  • Loading branch information
loicguillois authored Nov 7, 2024
2 parents 74b9d2f + e78ae2a commit 3dc2b9d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ fileignoreconfig:
checksum: 25a58ba4ecfb8606daf5efbae6a1f0f2efe4e87a4a8a18e745712b39198d93a5
- filename: packages/api-sdk/src/test/campaign-api.test.ts
checksum: b200d9e1fec310660a91e99cd048b24cbe983e0f9f965861d061a7f0992af43e
- filename: packages/healthcheck/src/checks/brevo.ts
checksum: a1fbeb01d83167b791eb8175eeb80178cc6da19bb83a6ba3cb2077ca96ebda5e
- filename: packages/utils/src/object.ts
checksum: 9893602dd7197e44a7c361e44c31b5fb86a025227af95c02998a6857bd1a694b
- filename: server/.env.example
Expand Down
23 changes: 23 additions & 0 deletions packages/healthcheck/src/checks/brevo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Check } from './check';

export function brevoCheck(apiKey: string): Check {
return {
name: 'brevo',
async test() {
const url =
'https://api.brevo.com/v3/smtp/statistics/aggregatedReport';
const options = {
method: 'GET',
headers: {
accept: 'application/json',
'api-key': apiKey
}
};
await fetch(url, options).then(res => {
if(res.status !== 200) {
throw new Error('Brevo API is not available');
}
});
}
};
}
1 change: 1 addition & 0 deletions packages/healthcheck/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './checks/brevo';
export * from './checks/postgres';
export * from './checks/redis';
export * from './checks/s3';
Expand Down
2 changes: 2 additions & 0 deletions server/src/infra/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import util from 'node:util';

import {
healthcheck,
brevoCheck,
postgresCheck,
redisCheck,
s3Check
Expand Down Expand Up @@ -121,6 +122,7 @@ export function createServer(): Server {
'/',
healthcheck({
checks: [
brevoCheck(config.mailer.apiKey ?? ''),
redisCheck(config.redis.url),
postgresCheck(config.db.url),
s3Check(config.s3)
Expand Down

0 comments on commit 3dc2b9d

Please sign in to comment.