Skip to content

Commit

Permalink
Merge pull request #1356 from guardian/ts/cloudbuster-logging-tweaks
Browse files Browse the repository at this point in the history
refactor: use logger in cloudbuster
  • Loading branch information
tjsilver authored Dec 16, 2024
2 parents c4850b7 + cb4080e commit d6c2675
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
42 changes: 23 additions & 19 deletions packages/cloudbuster/src/digests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RequestedChannel } from '@guardian/anghammarad';
import type { Action, Anghammarad, NotifyParams } from '@guardian/anghammarad';
import type { cloudbuster_fsbp_vulnerabilities } from '@prisma/client';
import { stringToSeverity } from 'common/src/functions';
import { logger } from 'common/src/logs';
import type { SecurityHubSeverity, Severity } from 'common/src/types';
import { type Config } from './config';
import { groupFindingsByAccount } from './findings';
Expand Down Expand Up @@ -146,25 +147,28 @@ export async function sendDigest(

const { enableMessaging, stage } = config;

if (enableMessaging && stage == 'PROD') {
console.log(
`Sending ${digest.accountId} digest to ${JSON.stringify(notifyParams.target, null, 4)}...`,
);
await anghammaradClient.notify(notifyParams);
} else if (enableMessaging) {
const testNotifyParams = {
...notifyParams,
target: { Stack: 'testing-alerts' },
};

console.log(
`Sending ${digest.accountId} digest to ${JSON.stringify(testNotifyParams.target, null, 4)}...`,
);

await anghammaradClient.notify(testNotifyParams);
if (enableMessaging) {
const notificationParameters =
stage === 'PROD'
? notifyParams
: {
...notifyParams,
target: { Stack: 'testing-alerts' },
};
logger.log({
message: `Sending ${digest.accountId} (${digest.accountName}) digest...`,
accountName: digest.accountName,
target: notificationParameters.target,
enableMessaging,
});

await anghammaradClient.notify(notificationParameters);
} else {
console.log(
`Messaging disabled. Anghammarad would have sent: ${JSON.stringify(notifyParams, null, 4)}`,
);
logger.log({
message: `Messaging disabled. Anghammarad would have sent: ${JSON.stringify(notifyParams, null, 4)}`,
accountName: digest.accountName,
target: notifyParams.target,
enableMessaging,
});
}
}
13 changes: 7 additions & 6 deletions packages/cloudbuster/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Anghammarad } from '@guardian/anghammarad';
import type { cloudbuster_fsbp_vulnerabilities } from '@prisma/client';
import { logger } from 'common/logs';
import { getFsbpFindings } from 'common/src/database-queries';
import { getPrismaClient } from 'common/src/database-setup';
import type { SecurityHubSeverity } from 'common/src/types';
Expand All @@ -15,9 +16,9 @@ export async function main() {
const prisma = getPrismaClient(config);

// *** DATA GATHERING ***
console.log(
`Starting Cloudbuster. Level of severities that will be scanned: ${severities.join(', ')}`,
);
logger.log({
message: `Starting Cloudbuster. Level of severities that will be scanned: ${severities.join(', ')}`,
});

const dbResults = (await getFsbpFindings(prisma, severities)).filter(
(f) => f.workflow.Status !== 'SUPPRESSED',
Expand All @@ -27,9 +28,9 @@ export async function main() {
findingsToGuardianFormat,
);

console.log(
`${tableContents.length} high and critical FSBP findings detected`,
);
logger.log({
message: `${tableContents.length} high and critical FSBP findings detected`,
});

await prisma.cloudbuster_fsbp_vulnerabilities.deleteMany();
await prisma.cloudbuster_fsbp_vulnerabilities.createMany({
Expand Down

0 comments on commit d6c2675

Please sign in to comment.