Skip to content

Commit

Permalink
[backend/frontend] Use ID instead of label when resolving expectation…
Browse files Browse the repository at this point in the history
… from OpenBAS (#8626)

Co-authored-by: Souad Hadjiat <souad.hadjiat@filigran.io>
  • Loading branch information
RomuDeuxfois and SouadHadjiat authored Oct 7, 2024
1 parent cde8568 commit af10c8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
3 changes: 1 addition & 2 deletions opencti-platform/opencti-front/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ const depsToOptimize = [
"@mui/lab/LoadingButton",
"@mui/material/Breadcrumbs",
"classnames",
"react-draggable",
"react-beautiful-dnd"
"react-draggable"
]

const logger = createLogger()
Expand Down
75 changes: 27 additions & 48 deletions opencti-platform/opencti-graphql/src/database/xtm-obas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,28 @@ export const createInjectInScenario = async (
}
};

const emptyResult = {
unknown: 1,
success: 0,
failure: 0,
};

const extractExerciseResultByType = (exerciseGlobalScore: any, type: string) => {
const resultType = exerciseGlobalScore.filter((n: { type: string, value: number }) => n.type === type).at(0);
return resultType.avgResult === 'UNKNOWN' ? {
emptyResult
} : {
unknown: resultType.distribution?.filter((n: { id: string, value: number }) => n.id === 'PENDING').at(0)?.value,
success: resultType.distribution?.filter((n: { id: string, value: number }) => n.id === 'SUCCESS').at(0)?.value,
failure: resultType.distribution?.filter((n: { id: string, value: number }) => n.id === 'FAILED').at(0)?.value
};
};

export const getScenarioResult = async (id: string) => {
const noResult = {
prevention: {
unknown: 1,
success: 0,
failure: 0,
},
detection: {
unknown: 1,
success: 0,
failure: 0,
},
human: {
unknown: 1,
success: 0,
failure: 0,
}
prevention: emptyResult,
detection: emptyResult,
human: emptyResult,
};
// OpenBAS not configured
if (isEmptyField(XTM_OPENBAS_URL) || isEmptyField(XTM_OPENBAS_TOKEN)) {
Expand All @@ -179,40 +184,14 @@ export const getScenarioResult = async (id: string) => {
if (!exercise || !exercise.exercise_id) {
return noResult;
}
const prevention = exercise.exercise_global_score.filter((n: { type: string, value: number }) => n.type === 'PREVENTION').at(0);
const preventionResult = prevention.avgResult === 'UNKNOWN' ? {
unknown: 1,
success: 0,
failure: 0
} : {
unknown: prevention.distribution?.filter((n: { label: string, value: number }) => n.label === 'Pending').at(0).value,
success: prevention.distribution?.filter((n: { label: string, value: number }) => n.label === 'Successful').at(0).value,
failure: prevention.distribution?.filter((n: { label: string, value: number }) => n.label === 'Failed').at(0).value
};
const detection = exercise.exercise_global_score.filter((n: { type: string, value: number }) => n.type === 'DETECTION').at(0);
const detectionResult = detection.avgResult === 'UNKNOWN' ? {
unknown: 1,
success: 0,
failure: 0
} : {
unknown: detection.distribution?.filter((n: { label: string, value: number }) => n.label === 'Pending').at(0).value,
success: detection.distribution?.filter((n: { label: string, value: number }) => n.label === 'Successful').at(0).value,
failure: detection.distribution?.filter((n: { label: string, value: number }) => n.label === 'Failed').at(0).value
};
const humanResponse = exercise.exercise_global_score.filter((n: { type: string, value: number }) => n.type === 'HUMAN_RESPONSE').at(0);
const humanResponseResult = humanResponse.avgResult === 'UNKNOWN' ? {
unknown: 1,
success: 0,
failure: 0
} : {
unknown: humanResponse.distribution?.filter((n: { label: string, value: number }) => n.label === 'Pending').at(0).value,
success: humanResponse.distribution?.filter((n: { label: string, value: number }) => n.label === 'Successful').at(0).value,
failure: humanResponse.distribution?.filter((n: { label: string, value: number }) => n.label === 'Failed').at(0).value
};
const { exercise_global_score: exerciseGlobalScore } = exercise;
const prevention = extractExerciseResultByType(exerciseGlobalScore, 'PREVENTION');
const detection = extractExerciseResultByType(exerciseGlobalScore, 'DETECTION');
const human = extractExerciseResultByType(exerciseGlobalScore, 'HUMAN_RESPONSE');
return {
prevention: preventionResult,
detection: detectionResult,
human: humanResponseResult
prevention,
detection,
human,
};
} catch (err) {
logApp.info('Scenario not found in OpenBAS', { err });
Expand Down

0 comments on commit af10c8c

Please sign in to comment.