diff --git a/awx/main/tests/data/insights.py b/awx/main/tests/data/insights.py
index 325dff7ba8..6fdca9540a 100644
--- a/awx/main/tests/data/insights.py
+++ b/awx/main/tests/data/insights.py
@@ -5,5 +5,7 @@ import os
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(dir_path, 'insights.json')) as data_file:
- TEST_INSIGHTS_PLANS = json.loads(data_file.read())
+ TEST_INSIGHTS_PLANS = json.load(data_file)
+with open(os.path.join(dir_path, 'insights_remediations.json')) as data_file:
+ TEST_INSIGHTS_REMEDIATIONS = json.load(data_file)['data']
diff --git a/awx/main/tests/data/insights_remediations.json b/awx/main/tests/data/insights_remediations.json
new file mode 100644
index 0000000000..17a2fb1541
--- /dev/null
+++ b/awx/main/tests/data/insights_remediations.json
@@ -0,0 +1,33 @@
+{
+ "data": [
+ {
+ "id": "9197ba55-0abc-4028-9bbe-269e530f8bd5",
+ "name": "Fix Critical CVEs",
+ "created_by": {
+ "username": "jharting@redhat.com",
+ "first_name": "Jozef",
+ "last_name": "Hartinger"
+ },
+ "created_at": "2018-12-05T08:19:36.641Z",
+ "updated_by": {
+ "username": "jharting@redhat.com",
+ "first_name": "Jozef",
+ "last_name": "Hartinger"
+ },
+ "updated_at": "2018-12-05T08:19:36.641Z",
+ "issue_count": 0,
+ "system_count": 0,
+ "needs_reboot": true
+ }
+ ],
+ "meta": {
+ "count": 0,
+ "total": 0
+ },
+ "links": {
+ "first": null,
+ "last": null,
+ "next": null,
+ "previous": null
+ }
+}
diff --git a/awx/main/tests/unit/utils/test_insights.py b/awx/main/tests/unit/utils/test_insights.py
index 96351338b7..72de5018bc 100644
--- a/awx/main/tests/unit/utils/test_insights.py
+++ b/awx/main/tests/unit/utils/test_insights.py
@@ -3,15 +3,16 @@
from awx.main.utils.insights import filter_insights_api_response
-from awx.main.tests.data.insights import TEST_INSIGHTS_PLANS
+from awx.main.tests.data.insights import TEST_INSIGHTS_PLANS, TEST_INSIGHTS_REMEDIATIONS
def test_filter_insights_api_response():
- actual = filter_insights_api_response(TEST_INSIGHTS_PLANS)
+ actual = filter_insights_api_response(TEST_INSIGHTS_PLANS, TEST_INSIGHTS_REMEDIATIONS)
assert actual['last_check_in'] == '2019-03-19T21:59:09.213151-04:00'
assert len(actual['reports']) == 5
- assert len(actual['reports'][0]['maintenance_actions']) == 0
+ assert len(actual['reports'][0]['maintenance_actions']) == 1
+ assert actual['reports'][0]['maintenance_actions'][0]['name'] == "Fix Critical CVEs"
rule = actual['reports'][0]['rule']
assert rule['severity'] == 'WARN'
diff --git a/awx/main/utils/insights.py b/awx/main/utils/insights.py
index f65cecb4e8..d4b4cf0d25 100644
--- a/awx/main/utils/insights.py
+++ b/awx/main/utils/insights.py
@@ -11,11 +11,11 @@
# reports[].rule.severity (str) -> active_reports[].rule.total_risk (int)
# reports[].rule.{ansible,ansible_fix} appears to be unused
-# reports[].maintenance_actions[] missing entirely, will be provided
+# reports[].maintenance_actions[] missing entirely, is now provided
# by a different Insights endpoint
-def filter_insights_api_response(json):
+def filter_insights_api_response(reports, remediations):
severity_mapping = {
1: 'INFO',
2: 'WARN',
@@ -24,14 +24,14 @@ def filter_insights_api_response(json):
}
new_json = {}
- if 'checked_on' in json:
- new_json['last_check_in'] = json['checked_on']
- if 'active_reports' in json:
+ if 'checked_on' in reports:
+ new_json['last_check_in'] = reports['checked_on']
+ if 'active_reports' in reports:
new_json['reports'] = []
- for rep in json['active_reports']:
+ for rep in reports['active_reports']:
new_report = {
'rule': {},
- 'maintenance_actions': [] # This will be populated by a different API call
+ 'maintenance_actions': remediations
}
rule = rep.get('rule') or {}
for k in ['description', 'summary']:
diff --git a/awx/ui/client/src/inventories-hosts/inventories/insights/plan-filter.js b/awx/ui/client/src/inventories-hosts/inventories/insights/plan-filter.js
index 40916cd5ec..5c404acaaf 100644
--- a/awx/ui/client/src/inventories-hosts/inventories/insights/plan-filter.js
+++ b/awx/ui/client/src/inventories-hosts/inventories/insights/plan-filter.js
@@ -9,8 +9,8 @@
if(plan === null || plan === undefined){
return "PLAN: Not Available CREATE A NEW PLAN IN INSIGHTS";
} else {
- let name = (plan.maintenance_plan.name === null) ? "Unnamed Plan" : plan.maintenance_plan.name;
- return `${name} (${plan.maintenance_plan.maintenance_id})`;
+ let name = (plan.name === null) ? "Unnamed Plan" : plan.name;
+ return `${name} (${plan.id})`;
}
};
}