Skip to content

Commit

Permalink
Adding posture score to benchmark (elastic#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanSh authored and orouz committed Jan 13, 2022
1 parent 5fa6982 commit 2bb21ce
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const getFindingsEsQuery = (
*/
const roundScore = (value: number) => Number((value * 100).toFixed(1));

const calculatePostureScore = (total: number, passed: number, failed: number) =>
total === 0 ? undefined : roundScore(passed / failed);

const getLatestFinding = (): SearchRequest => ({
index: FINDINGS_INDEX,
size: 1,
Expand Down Expand Up @@ -163,15 +166,17 @@ const getAllFindingsStats = async (
const findings = await esClient.count(getFindingsEsQuery(cycleId));
const passedFindings = await esClient.count(getFindingsEsQuery(cycleId, 'passed'));
const failedFindings = await esClient.count(getFindingsEsQuery(cycleId, 'failed'));

const totalFindings = findings.body.count;
const totalPassed = passedFindings.body.count;
const totalFailed = failedFindings.body.count;

return {
name: 'general',
totalFindings: findings.body.count,
postureScore:
findings.body.count === 0
? undefined
: roundScore(passedFindings.body.count / findings.body.count),
totalPassed: passedFindings.body.count,
totalFailed: failedFindings.body.count,
postureScore: calculatePostureScore(totalFindings, totalPassed, totalFailed),
totalFindings,
totalPassed,
totalFailed,
};
};

Expand All @@ -190,15 +195,16 @@ const getBenchmarksStats = async (
getFindingsEsQuery(cycleId, 'failed', benchmark)
);

const totalFindings = benchmarkFindings.body.count;
const totalPassed = benchmarkPassedFindings.body.count;
const totalFailed = benchmarkFailedFindings.body.count;

return {
name: benchmark,
totalFindings: benchmarkFindings.body.count,
postureScore:
benchmarkFindings.body.count === 0
? undefined
: roundScore(benchmarkPassedFindings.body.count / benchmarkFindings.body.count),
totalPassed: benchmarkPassedFindings.body.count,
totalFailed: benchmarkFailedFindings.body.count,
postureScore: calculatePostureScore(totalFindings, totalPassed, totalFailed),
totalFindings,
totalPassed,
totalFailed,
};
})
);
Expand Down

0 comments on commit 2bb21ce

Please sign in to comment.