Skip to content

Commit

Permalink
Merge pull request #69 from AirWalk-Digital/feature/fix-aggregations
Browse files Browse the repository at this point in the history
Feature/fix aggregations
  • Loading branch information
mcuckson authored Jul 17, 2023
2 parents b883fec + 67dcf12 commit c8759fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ SQLite is ok for dev, but for a more representative environment postgres should
docker run --name some-postgres -e POSTGRES_PASSWORD=password -d -p 5432:5432 postgres
FLASK_APP=./utils/debug.py FLASK_DEBUG=True DATABASE_URI=postgresql://postgres:[email protected]/airview CREATE_DB=True flask run
```


17 changes: 11 additions & 6 deletions app/airview_api/services/aggregation_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from airview_api.database import db
from sqlalchemy import func, literal
from sqlalchemy.sql.functions import coalesce
import itertools
from datetime import datetime
import json
Expand Down Expand Up @@ -36,6 +37,7 @@ def get_control_overviews(application_id: int, quality_model: str):
.join(Control)
.join(System)
.join(Service)
.join(Resource)
.group_by(
TechnicalControl.id,
TechnicalControl.name,
Expand Down Expand Up @@ -74,9 +76,9 @@ def get_compliance_aggregation(application_id):
System.name,
System.stage,
TechnicalControl.name,
Control.severity,
Control.name,
Control.id,
coalesce(Control.severity, literal("HIGH")),
coalesce(Control.name, literal("Unmapped")),
coalesce(Control.id, literal(0)),
Resource.id,
Resource.name,
MonitoredResource.last_modified,
Expand All @@ -86,8 +88,8 @@ def get_compliance_aggregation(application_id):
.join(Resource)
.join(MonitoredResource)
.join(TechnicalControl)
.join(Control)
.join(System)
.join(Control, isouter=True)
.join(System, isouter=True)
.where(MonitoredResource.monitoring_state == MonitoredResourceState.FLAGGED)
.where(ApplicationEnvironment.application_id == application_id)
)
Expand Down Expand Up @@ -131,7 +133,10 @@ def get_control_overview_resources(application_id, technical_control_id):
Resource.id,
Resource.name,
Environment.name.label("environment"),
MonitoredResource.monitoring_state.label("status"),
coalesce(
MonitoredResource.monitoring_state,
literal("MONITORING"),
).label("status"),
literal(False).label("pending"),
)
.select_from(ApplicationEnvironment)
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1514,15 +1514,15 @@
"parameters": [
{
"in": "query",
"name": "reference",
"name": "type",
"required": false,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "type",
"name": "reference",
"required": false,
"schema": {
"type": "string"
Expand Down

0 comments on commit c8759fd

Please sign in to comment.