Fetching policy execution statuses of resources

  1. Authenticate to the cloud platform via the Python shell.

    The following variables should be available now:

    >>> base_url  # the base URL of the API
    >>> auth  # the 'Authorization' header value with the access token
    {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImMwMD...'}
  2. Send a GET request to the /policy_management/v4/policy_statuses endpoint:

    >>> response = requests.get(f'{base_url}/policy_management/v4/policy_statuses', headers=auth)
  3. Check the status code of the response:

    >>> response.status_code

    Status code 200 means that the request was successful.

    A different status code means that an error has occurred. For the details, refer to “Status and error codes”.

    Also, the response body contains an object with the items key containing an array of objects with resource data and status of its policies execution formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'items': [{'context': {'agent_id': '23effcf6-2798-4631-9a52-5785bf3af657',
                            'agent_name': 'DESKTOP-JRPTA4A',
                            'id': '5c350066-2ba6-4eeb-aa91-1213dd35f033',
                            'name': 'DESKTOP-JRPTA4A',
                            'tenant_id': '17',
                            'tenant_name': '',
                            'type': 'resource.machine',
                            'user_defined_name': 'DESKTOP-JRPTA4A'},
                'policies': [{'names': [],
                            'next_run_time': '2020-10-12T12:10:00Z',
                            'running': {'state': 'idle'},
                            'status': 'ok',
                            'type': 'policy.security.patch_management'},
     'paging': {'cursors': {'total': 1}}}