Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/nibbles
Browse files Browse the repository at this point in the history
  • Loading branch information
originalsouth committed Nov 7, 2024
2 parents 8ff6fac + 518ff8f commit a9da549
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 65 deletions.
2 changes: 1 addition & 1 deletion docs/source/manual/reports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ The table below gives an overview of the elements that can be found in each repo

Report flow
===========
On the Reports page you can generate new reports and get an overview of all generated reports. With the button 'Generate report' you get into the Report flow wizard, which can be used to choose your report, objects and plugins that are required for the report. Please note that enabling plugins during the report flow wizard will result in inaccurate data, as the plugins will take some time before they have gathered and analyzed all data. Check the Tasks page to verify that all tasks have completed.
On the Reports page you can generate new reports and get an overview of all generated reports. With the button 'Generate report' you get into the Report flow wizard, which can be used to choose your report, objects and plugins that are required for the report. There are two ways to select objects. You can manually select objects, which will be static. Or you can select a live set of objects by continuing with the selected filters. The selected objects will then always be based on the selected filters at the time of generating the report. and Please note that enabling plugins during the report flow wizard will result in inaccurate data, as the plugins will take some time before they have gathered and analyzed all data. Check the Tasks page to verify that all tasks have completed.


Plugins
Expand Down
8 changes: 0 additions & 8 deletions rocky/assets/css/components/pre.scss

This file was deleted.

1 change: 0 additions & 1 deletion rocky/assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
@import "components/ooi-summary";
@import "components/page-meta";
@import "components/plugins";
@import "components/pre";
@import "components/qr-code";
@import "components/report";
@import "components/report-name-table";
Expand Down
1 change: 1 addition & 0 deletions rocky/assets/css/manon-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
@use "@minvws/manon/breadcrumb-bar";
@use "@minvws/manon/breadcrumb-bar-content-block";
@use "@minvws/manon/code-base";
@use "@minvws/manon/code-block";
@use "@minvws/manon/description-list";
@use "@minvws/manon/filter";
@use "@minvws/manon/language-selector-list";
Expand Down
10 changes: 10 additions & 0 deletions rocky/assets/css/themes/soft/manon/code-base.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* code base */

:root {
--code-base-background-color: var(--colors-purrple-100);
}

code {
padding: 0.125rem 0.5rem;
white-space: nowrap;
}
6 changes: 6 additions & 0 deletions rocky/assets/css/themes/soft/manon/code-block.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* code base */

:root {
--code-block-background-color: var(--colors-purrple-100);
--code-block-code-padding: 0;
}
2 changes: 2 additions & 0 deletions rocky/assets/css/themes/soft/soft.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
@import "manon/button-ghost";
@import "manon/checkbox";
@import "manon/collapsible";
@import "manon/code-base";
@import "manon/code-block";
@import "manon/de-emphasized";
@import "manon/emphasized";
@import "manon/expando-rows";
Expand Down
51 changes: 33 additions & 18 deletions rocky/reports/runner/report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from tools.models import Organization

from octopoes.connector.octopoes import OctopoesAPIConnector
from octopoes.models import Reference
from octopoes.models import Reference, ScanLevel, ScanProfileType
from octopoes.models.types import type_by_name
from reports.report_types.aggregate_organisation_report.report import AggregateOrganisationReport, aggregate_reports
from reports.report_types.definitions import report_plugins_union
from reports.report_types.helpers import get_report_by_id
Expand All @@ -26,16 +27,34 @@ def run(self, report_task: ReportTask) -> None:
connector = OctopoesAPIConnector(
settings.OCTOPOES_API, report_task.organisation_id, timeout=settings.ROCKY_OUTGOING_REQUEST_TIMEOUT
)
recipe = connector.get(Reference.from_str(f"ReportRecipe|{report_task.report_recipe_id}"), valid_time)
recipe_ref = Reference.from_str(f"ReportRecipe|{report_task.report_recipe_id}")
recipe = connector.get(recipe_ref, valid_time)

report_types = [get_report_by_id(report_type_id) for report_type_id in recipe.report_types]
oois_count = len(recipe.input_recipe["input_oois"])
oois = []
now = datetime.now(timezone.utc)

for ooi_id in recipe.input_recipe["input_oois"]:
ooi = connector.get(Reference.from_str(ooi_id), valid_time)
oois.append(ooi)
if input_oois := recipe.input_recipe.get("input_oois"):
for ooi_id in input_oois:
ooi = connector.get(Reference.from_str(ooi_id), valid_time)
oois.append(ooi)
elif query := recipe.input_recipe.get("query"):
types = {type_by_name(t) for t in query["ooi_types"]}
scan_level = {ScanLevel(cl) for cl in query["scan_level"]}
scan_type = {ScanProfileType(t) for t in query["scan_type"]}

oois = connector.list_objects(
types=types,
valid_time=datetime.now(tz=timezone.utc),
scan_level=scan_level,
scan_profile_type=scan_type,
search_string=query["search_string"],
order_by=query["order_by"],
asc_desc=query["asc_desc"],
).items

oois_count = len(oois)
ooi_pks = [ooi.primary_key for ooi in oois]

self.bytes_client.organization = report_task.organisation_id

Expand All @@ -48,9 +67,7 @@ def run(self, report_task: ReportTask) -> None:
report_type_ids = [report.id for report in report_types]

if "${ooi}" in parent_report_name and oois_count == 1:
ooi = recipe.input_recipe["input_oois"][0]
ooi_human_readable = Reference.from_str(ooi).human_readable
parent_report_name = Template(parent_report_name).safe_substitute(ooi=ooi_human_readable)
parent_report_name = Template(parent_report_name).safe_substitute(ooi=oois[0].human_readable)

aggregate_report, post_processed_data, report_data, report_errors = aggregate_reports(
connector, oois, report_type_ids, valid_time, report_task.organisation_id
Expand All @@ -60,10 +77,10 @@ def run(self, report_task: ReportTask) -> None:
connector,
Organization.objects.get(code=report_task.organisation_id),
valid_time,
recipe.input_recipe["input_oois"],
ooi_pks,
{
"input_data": {
"input_oois": recipe.input_recipe["input_oois"],
"input_oois": ooi_pks,
"report_types": recipe.report_types,
"plugins": report_plugins_union(report_types),
}
Expand All @@ -72,12 +89,11 @@ def run(self, report_task: ReportTask) -> None:
report_data,
post_processed_data,
aggregate_report,
recipe_ref,
)
else:
subreport_names = []
error_reports, report_data = collect_reports(
valid_time, connector, recipe.input_recipe["input_oois"], report_types
)
error_reports, report_data = collect_reports(valid_time, connector, ooi_pks, report_types)

for report_type_id, data in report_data.items():
report_type = get_report_by_id(report_type_id)
Expand All @@ -96,9 +112,7 @@ def run(self, report_task: ReportTask) -> None:
)

if "${ooi}" in parent_report_name and oois_count == 1:
ooi = recipe.input_recipe["input_oois"][0]
ooi_human_readable = Reference.from_str(ooi).human_readable
parent_report_name = Template(parent_report_name).safe_substitute(ooi=ooi_human_readable)
parent_report_name = Template(parent_report_name).safe_substitute(ooi=ooi[0].human_readable)

save_report_data(
self.bytes_client,
Expand All @@ -107,14 +121,15 @@ def run(self, report_task: ReportTask) -> None:
Organization.objects.get(code=report_task.organisation_id),
{
"input_data": {
"input_oois": recipe.input_recipe["input_oois"],
"input_oois": ooi_pks,
"report_types": recipe.report_types,
"plugins": report_plugins_union(report_types),
}
},
report_data,
subreport_names,
parent_report_name,
recipe_ref,
)

self.bytes_client.organization = None
1 change: 1 addition & 0 deletions rocky/reports/templates/forms/report_form_fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
name="choose_recurrence"
value="{{ request.POST.choose_recurrence }}">
{% endif %}
<input type="hidden" name="object_selection" value="{{ object_selection }}">
45 changes: 40 additions & 5 deletions rocky/reports/templates/partials/report_ooi_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,40 @@ <h2>
Select objects ({{ total_oois }})
{% endblocktranslate %}
</h2>
<p>{% translate "Select which objects you want to include in your report." %}</p>
<p>
{% blocktranslate %}
Select which objects you want to include in your report. You can either continue
with a live set or you can select the objects manually from the table below.
{% endblocktranslate %}
</p>
<p>
{% blocktranslate %}
A live set is a set of objects based on the applied filters.
Any object that matches this applied filter (now or in the future) will be used as
input for the scheduled report. If your live set filter (e.g. 'hostnames' with
'L2 clearance' that are 'declared') shows 2 hostnames that match the filter today,
the scheduled report will run for those 2 hostnames. If you add 3 more hostnames
tomorrow (with the same filter criteria), your next scheduled report will contain
5 hostnames. Your live set will update as you go.
{% endblocktranslate %}
</p>
{% include "partials/ooi_list_filters.html" %}

<form novalidate
method="post"
action="{{ next }}"
class="inline layout-wide checkboxes_required">
{% csrf_token %}
{% include "forms/report_form_fields.html" %}

<input type="hidden" name="ooi" value="all">
<button type="submit"
class="button select_all_objects_element"
name="object_selection"
value="query">
{% translate "Continue with live set" %}<span class="icon ti-chevron-right"></span>
</button>
</form>
{% if not ooi_list %}
<p>{% translate "No objects found." %}</p>
<div class="button-container">
Expand Down Expand Up @@ -51,7 +82,8 @@ <h2>
<form novalidate
method="post"
action="{{ next }}"
class="inline layout-wide checkboxes_required">
class="inline layout-wide checkboxes_required"
id="object_table_form">
{% csrf_token %}
{% if all_oois_selected %}
{% include "forms/report_form_fields.html" %}
Expand Down Expand Up @@ -95,10 +127,13 @@ <h2>
{% endfor %}
</tbody>
</table>
<button type="submit"
class="button ghost"
name="object_selection"
value="selection">
{% translate "Continue with selection" %}<span class="icon ti-chevron-right"></span>
</button>
</div>
<button type="submit" class="button">
{% translate "Continue with selection" %}<span class="icon ti-chevron-right"></span>
</button>
</form>
{% include "partials/list_paginator.html" %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<tr>
<th scope="col">{% translate "Name" %}</th>
<th scope="col">{% translate "Report type" %}</th>
<th scope="col">{% translate "Input Objects" %}</th>
<th scope="col">{% translate "Reference date" %}</th>
<th scope="col">{% translate "Creation date" %}</th>
<th scope="col" class="nowrap">{% translate "Input objects" %}</th>
<th scope="col" class="nowrap">{% translate "Reference date" %}</th>
<th scope="col" class="nowrap">{% translate "Creation date" %}</th>
{% if report.children_reports %}<th scope="col"></th>{% endif %}
</tr>
</thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
<caption class="visually-hidden">{% translate "Scheduled Reports:" %}</caption>
<thead>
<tr>
<th scope="col">{% translate "Name" %}</th>
<th scope="col" class="nowrap">{% translate "Name" %}</th>
<th scope="col">{% translate "Report type" %}</th>
<th scope="col">{% translate "Input Object" %}</th>
<th scope="col">{% translate "Reference date" %}</th>
<th scope="col">{% translate "Creation date" %}</th>
<th scope="col">{% translate "Input object" %}</th>
<th scope="col" class="nowrap">{% translate "Reference date" %}</th>
<th scope="col" class="nowrap">{% translate "Creation date" %}</th>
</tr>
</thead>
<tbody>
Expand All @@ -77,7 +77,13 @@
<span class="label tags-color-{{ report.report_type|get_report_type_label_style }}">{{ report.report_type|get_report_type_name }}</span>
</td>
<td>
{% for ooi in report.input_oois %}<span>{{ ooi|human_readable }}</span>{% endfor %}
{% if report.input_oois|length == 1 %}
{% with ooi=report.input_oois.0 %}
<a href="{% ooi_url 'ooi_detail' ooi organization.code query=ooi.mandatory_fields %}">{{ ooi|human_readable }}</a>
{% endwith %}
{% else %}
{{ report.input_oois|length }}
{% endif %}
</td>
<td class="nowrap">{{ report.observed_at|date }}</td>
<td class="nowrap">{{ report.date_generated }}</td>
Expand Down
Loading

0 comments on commit a9da549

Please sign in to comment.