From ae88764dc8e976a3c4d289c9f75a8718915e054e Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Mon, 12 Aug 2019 18:48:13 +0300 Subject: [PATCH] Pillar grading resource is now real data --- monkey/common/data/zero_trust_consts.py | 22 +++++ .../cc/resources/reporting/report.py | 85 +++++++------------ .../zerotrust/PillarGrades.js | 1 + 3 files changed, 56 insertions(+), 52 deletions(-) diff --git a/monkey/common/data/zero_trust_consts.py b/monkey/common/data/zero_trust_consts.py index db18f056a..72d2bfc43 100644 --- a/monkey/common/data/zero_trust_consts.py +++ b/monkey/common/data/zero_trust_consts.py @@ -99,6 +99,28 @@ TESTS_MAP = { POSSIBLE_STATUSES_KEY: [STATUS_UNEXECUTED, STATUS_CONCLUSIVE, STATUS_POSITIVE] }, } + +PILLARS_TO_TESTS = { + DATA: [], + PEOPLE: [], + NETWORKS: [], + DEVICES: [], + WORKLOADS: [], + VISIBILITY_ANALYTICS: [], + AUTOMATION_ORCHESTRATION: [] +} + + +def populate_pillars_to_tests(): + for pillar in PILLARS: + for test, test_info in TESTS_MAP.items(): + if pillar in test_info[PILLARS_KEY]: + PILLARS_TO_TESTS[pillar].append(test) + + +populate_pillars_to_tests() + + EVENT_TYPE_ISLAND = "island" EVENT_TYPE_MONKEY_NETWORK = "monkey_network" EVENT_TYPE_MONKEY_LOCAL = "monkey_local" diff --git a/monkey/monkey_island/cc/resources/reporting/report.py b/monkey/monkey_island/cc/resources/reporting/report.py index 61a034e45..e2a1a4722 100644 --- a/monkey/monkey_island/cc/resources/reporting/report.py +++ b/monkey/monkey_island/cc/resources/reporting/report.py @@ -4,7 +4,8 @@ import json import flask_restful from flask import jsonify -from common.data.zero_trust_consts import TESTS_MAP, EXPLANATION_KEY, PILLARS_KEY +from common.data.zero_trust_consts import TESTS_MAP, EXPLANATION_KEY, PILLARS_KEY, PILLARS, STATUS_CONCLUSIVE, \ + STATUS_INCONCLUSIVE, STATUS_POSITIVE, STATUS_UNEXECUTED, PILLARS_TO_TESTS from monkey_island.cc.auth import jwt_required from monkey_island.cc.models.finding import Finding from monkey_island.cc.services.reporting.report import ReportService @@ -151,55 +152,35 @@ def get_recommendations_status(): ] +def get_pillar_grade(pillar, all_findings): + pillar_grade = { + "Pillar": pillar, + STATUS_CONCLUSIVE: 0, + STATUS_INCONCLUSIVE: 0, + STATUS_POSITIVE: 0, + STATUS_UNEXECUTED: 0 + } + + tests_of_this_pillar = PILLARS_TO_TESTS[pillar] + + test_unexecuted = {} + for test in tests_of_this_pillar: + test_unexecuted[test] = True + + for finding in all_findings: + test_unexecuted[finding.test] = False + test_info = TESTS_MAP[finding.test] + if pillar in test_info[PILLARS_KEY]: + pillar_grade[finding.status] += 1 + + pillar_grade[STATUS_UNEXECUTED] = sum(1 for condition in test_unexecuted.values() if condition) + + return pillar_grade + + def get_pillars_grades(): - return [ - { - "Pillar": "Data", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - { - "Pillar": "Networks", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - { - "Pillar": "People", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - { - "Pillar": "Workloads", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - { - "Pillar": "Devices", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - { - "Pillar": "Visibility & Analytics", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - { - "Pillar": "Automation & Orchestration", - "Conclusive": 6, - "Inconclusive": 6, - "Positive": 6, - "Unexecuted": 6 - }, - ] + pillars_grades = [] + all_findings = Finding.objects() + for pillar in PILLARS: + pillars_grades.append(get_pillar_grade(pillar, all_findings)) + return pillars_grades diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PillarGrades.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PillarGrades.js index 9b746afd2..c2dd335f3 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PillarGrades.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/PillarGrades.js @@ -12,6 +12,7 @@ const columns = [ { Header: 'Conclusive', accessor: 'Conclusive'}, { Header: 'Inconclusive', accessor: 'Inconclusive'}, { Header: 'Unexecuted', accessor: 'Unexecuted'}, + { Header: 'Positive', accessor: 'Positive'}, ] } ];