mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Conform to the new output of the Insights system reports endpoint
This commit is contained in:
@@ -1677,7 +1677,7 @@ class HostInsights(GenericAPIView):
|
|||||||
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def _get_platform_id(self, host, session, headers):
|
def _get_platform_info(self, host, session, headers):
|
||||||
url = '{}/api/inventory/v1/hosts?insights_id={}'.format(
|
url = '{}/api/inventory/v1/hosts?insights_id={}'.format(
|
||||||
settings.INSIGHTS_URL_BASE, host.insights_system_id)
|
settings.INSIGHTS_URL_BASE, host.insights_system_id)
|
||||||
res = self._call_insights_api(url, session, headers)
|
res = self._call_insights_api(url, session, headers)
|
||||||
@@ -1688,7 +1688,7 @@ class HostInsights(GenericAPIView):
|
|||||||
_('Could not translate Insights system ID {}'
|
_('Could not translate Insights system ID {}'
|
||||||
' into an Insights platform ID.').format(host.insights_system_id))
|
' into an Insights platform ID.').format(host.insights_system_id))
|
||||||
|
|
||||||
return platform_id
|
return res['results'][0]
|
||||||
|
|
||||||
def _get_reports(self, platform_id, session, headers):
|
def _get_reports(self, platform_id, session, headers):
|
||||||
url = '{}/api/insights/v1/system/{}/reports/'.format(
|
url = '{}/api/insights/v1/system/{}/reports/'.format(
|
||||||
@@ -1711,11 +1711,15 @@ class HostInsights(GenericAPIView):
|
|||||||
|
|
||||||
return remediations
|
return remediations
|
||||||
|
|
||||||
def _get_insights(self, platform_id, session, headers):
|
def _get_insights(self, session, headers):
|
||||||
|
platform_info = self._get_platform_info(host, session, headers)
|
||||||
|
platform_id = platform_info['id']
|
||||||
reports = self._get_reports(platform_id, session, headers)
|
reports = self._get_reports(platform_id, session, headers)
|
||||||
remediations = self._get_remediations(platform_id, session, headers)
|
remediations = self._get_remediations(platform_id, session, headers)
|
||||||
|
|
||||||
return {'insights_content': filter_insights_api_response(reports, remediations)}
|
return {
|
||||||
|
'insights_content': filter_insights_api_response(platform_info, reports, remediations)
|
||||||
|
}
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
host = self.get_object()
|
host = self.get_object()
|
||||||
@@ -1739,7 +1743,6 @@ class HostInsights(GenericAPIView):
|
|||||||
password = cred.get_input('password', default='')
|
password = cred.get_input('password', default='')
|
||||||
session = self._get_session(username, password)
|
session = self._get_session(username, password)
|
||||||
headers = self._get_headers()
|
headers = self._get_headers()
|
||||||
platform_id = self._get_platform_id(host, session, headers)
|
|
||||||
|
|
||||||
data = self._get_insights(platform_id, session, headers)
|
data = self._get_insights(platform_id, session, headers)
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
# by a different Insights endpoint
|
# by a different Insights endpoint
|
||||||
|
|
||||||
|
|
||||||
def filter_insights_api_response(reports, remediations):
|
def filter_insights_api_response(platform_info, reports, remediations):
|
||||||
severity_mapping = {
|
severity_mapping = {
|
||||||
1: 'INFO',
|
1: 'INFO',
|
||||||
2: 'WARN',
|
2: 'WARN',
|
||||||
@@ -23,25 +23,24 @@ def filter_insights_api_response(reports, remediations):
|
|||||||
4: 'CRITICAL'
|
4: 'CRITICAL'
|
||||||
}
|
}
|
||||||
|
|
||||||
new_json = {}
|
new_json = {
|
||||||
if 'checked_on' in reports:
|
'last_check_in': platform_info.get('updated'),
|
||||||
new_json['last_check_in'] = reports['checked_on']
|
'reports': [],
|
||||||
if 'active_reports' in reports:
|
}
|
||||||
new_json['reports'] = []
|
for rep in reports:
|
||||||
for rep in reports['active_reports']:
|
new_report = {
|
||||||
new_report = {
|
'rule': {},
|
||||||
'rule': {},
|
'maintenance_actions': remediations
|
||||||
'maintenance_actions': remediations
|
}
|
||||||
}
|
rule = rep.get('rule') or {}
|
||||||
rule = rep.get('rule') or {}
|
for k in ['description', 'summary']:
|
||||||
for k in ['description', 'summary']:
|
if k in rule:
|
||||||
if k in rule:
|
new_report['rule'][k] = rule[k]
|
||||||
new_report['rule'][k] = rule[k]
|
if 'category' in rule:
|
||||||
if 'category' in rule:
|
new_report['rule']['category'] = rule['category']['name']
|
||||||
new_report['rule']['category'] = rule['category']['name']
|
if rule.get('total_risk') in severity_mapping:
|
||||||
if rule.get('total_risk') in severity_mapping:
|
new_report['rule']['severity'] = severity_mapping[rule['total_risk']]
|
||||||
new_report['rule']['severity'] = severity_mapping[rule['total_risk']]
|
|
||||||
|
|
||||||
new_json['reports'].append(new_report)
|
new_json['reports'].append(new_report)
|
||||||
|
|
||||||
return new_json
|
return new_json
|
||||||
|
|||||||
Reference in New Issue
Block a user