Search

Chapter 4. Exporting inventory data

download PDF

You can use the export service for inventory to export a list of systems and their data from your Insights inventory. You can specify CSV or JSON as the output format. The export process takes place asynchronously, so it runs in the background. The service is available in both the Insights UI and through the export service API.

The exported content includes the following information about each system in your inventory:

  • host_id
  • fqdn (Fully Qualified Domain Name)
  • display_name
  • group_id
  • group_name
  • state
  • os_release
  • updated
  • subscription_manager_id
  • satellite_id
  • tags
  • host_type
Note

The export service currently exports information about all systems in your inventory. Support for filters will be available in a future release.

The Inventory export service works differently from the export function in other services, such as Advisor. Some of the differences are:

  • Inventory export operates asynchronously
  • Exports the entire inventory to one continuous file (no pagination in the export file)
  • Retains generated files for 7 days
  • Uses token-based service accounts for authorization if using the export service API
Important

Your RBAC permissions affect the system information you can export. You must have inventory:hosts:read permission for a system to export system information.

4.1. Inventory data files

The inventory export process creates and downloads a zip file. The zip file contains the following files:

  • id.suffix — the export data file, with the file name format of id.json for JSON files, or id.csv for CSV files. For example: f26a57ac-1efc-4831-9c26-c818b6060ddf.json
  • README.md — the export manifest for the JSON/CSV file, which lists the downloaded files, any errors, and instructions for obtaining help
  • meta.json — describes the export operation — requestor, date, Organization ID, and file metadata (such as the filename of the JSON/CSV file)

4.2. Exporting system inventory from the Insights UI

You can export inventory data from the Insights UI. The inventory data export service works differently from the export service for other Insights services, such as Advisor.

Prerequisites

  • RBAC permissions for the systems you want to view and export

    • Inventory:hosts:read (inventory:hosts:read * for all systems in inventory)
  • A User Access role for workspaces. For more information about User Access roles, see User access to workspaces.

Procedure

  1. Navigate to Inventory > Systems. The list of systems displays.
  2. Click the Export icon next to the options icon (⋮). The drop-down menu displays.
  3. Select CSV or JSON as the export format. A status message displays: Preparing export. Once complete, your download will start automatically.
Systems inventory export showing the export icon in the UI

When the download completes, a browser window automatically opens to display the results.

If you remain on the Systems page after requesting the download, status messages from Insights appear with updates on the progress of the export operation.

4.3. Exporting system inventory using the export API

You can use the Export API to export your inventory data. Use the REST API entry point: console.redhat.com/api/export/v1.

The Export Service API supports the GET, POST, and DELETE HTTP methods. The API offers the following services:

  • POST /exports
  • GET /exports
  • GET /exports/id
  • DELETE /exports/id
  • GET /exports/id/status

The API works asynchronously. You can submit the POST /exports request for export from the Export API and receive a reply with an ID for that export. You can then use that ID to monitor the progress of the export operation with the GET /exports/id/status request. When the generated export is complete, you can download it (GET /exports/id) or delete it (DELETE /exports/id).

Successful requests return the following responses:

  • 200 — Success
  • 202 — Successfully deleted (for the DELETE method)

For more information about the operations, schemas, and objects, see Consoledot Export Service.

4.3.1. Requesting the system inventory export

Before you can request the exported data file, you need to obtain a unique ID for the download. To obtain the ID, issue a POST request. The server returns a response that includes the ID. Use the ID in any request that requires the id parameter, such as GET /exports/id.

Prerequisites

  • Token-based service account with the appropriate permissions for your systems
  • RBAC permissions for the systems you want to view and export

    • Inventory:hosts:read (inventory:hosts:read * for all systems in inventory)
  • A User Access role for workspaces. For more information about User Access roles, see User access to workspaces.

Procedure

  1. Create a request for the export service, or use this sample request code:

    {
    	“name”: “Inventory Export”,
    	“format”: “json”,
    	“sources”: [
    	   {
    		“application”: “urn:redhat:application:inventory”,
    		“resource”: “urn:redhat:application:inventory:export:systems”,
                 }
             ]
    }
    Note

    You can request CSV or JSON as your export format.

  2. In the Hybrid Cloud Console, navigate to the API documentation: https://console.redhat.com/docs/api/export .

    Note

    You can use the API documentation to experiment and run queries against the API before writing your own custom client and/or use the APIs in your automation.

  3. Select POST /export.
  4. Remove the existing sample code in the Request Body window and paste the request code into the window.
  5. Click Execute. This request initiates the export process. The curl request and server response appear, along with the result codes for the POST operation.
  6. Look for the id field in the server response. Copy and save the string value for id. Use this value for id in your requests.
  7. Optional. Issue the GET /exports request. The server returns the curl request, request URL, and response codes.
  8. Optional. To request the status of the export request, issue the GET /exports/id/status request.
  9. When the export has completed, issue the GET /exports/id request, with the ID string that you copied in place of id. The server returns a link to download the export file (the payload).
  10. Click Download File. When the download completes, a notification message appears in your browser.
  11. Click the browser notification to locate the downloaded zip file.
Note

The server retains export files for 7 days.

4.3.2. Deleting export files

To delete exported files, issue the DELETE /exports/id request.

Additional resources

4.3.3. Automating inventory export using Ansible playbooks

You can use an Ansible playbook to automate the inventory export process. The playbook is a generic playbook for the export service that uses token-based service accounts for authentication.

Procedure

  1. Navigate to https://github.com/jeromemarc/insights-inventory-export .
  2. Download the inventory-export.yml playbook.
  3. Run the playbook. The playbook does everything from requesting the export id, to requesting download status, to requesting the downloaded payload.

Additional resources

For more information about service accounts, refer to the KB article: Transition of Red Hat Hybrid Cloud Console APIs from basic authentication to token-based authentication via service accounts.

4.3.4. Using the inventory export service for multiple Insights services

You can use the inventory export service for multiple services, such as inventory and notifications. To request multiple services, include source information for each service that you want to request in your POST /exports request. For example:

{
  "name": "Inventory Export multiple sources",
  "format": "json",
  "sources": [
    {
      "application": "urn:redhat:application:inventory",
      "resource": "urn:redhat:application:inventory:export:systems",
      "filters": {}
    },
    {
      "application": "urn:redhat:application:notifications",
      "resource": "urn:redhat:application:notifications:export:events",
      "filters": {}
    }
  ]
}

The POST /exports request returns a unique id for each export.

The GET /exports request returns a zip file that includes multiple JSON or CSV files, one for each service that you request.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.