Search

Chapter 5. Using the Red Hat Satellite API

download PDF

This chapter provides a range of examples of how to use the Red Hat Satellite API to perform different tasks. You can use the API on Satellite Server via HTTPS on port 443, or on Capsule Server via HTTPS on port 8443.

You can address these different port requirements within the script itself. For example, in Ruby, you can specify the Satellite and Capsule URLs as follows:

url = 'https://satellite.example.com/api/v2/'
capsule_url = 'https://capsule.example.com:8443/api/v2/'
katello_url = 'https://satellite.example.com/katello/api/v2/'

For the host that is subscribed to Satellite Server or Capsule Server, you can determine the correct port required to access the API from the /etc/rhsm/rhsm.conf file, in the port entry of the [server] section. You can use these values to fully automate your scripts, removing any need to verify which ports to use.

This chapter uses curl for sending API requests. For more information, see Section 4.1, “API Requests with curl”.

Examples in this chapter use the Python json.tool module to format the output.

5.1. Working with Hosts

Listing Hosts

This example returns a list of Satellite hosts.

Example request:

$ curl -request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts | python -m json.tool

Example response:

{
      ...
       "total" => 2,
    "subtotal" => 2,
        "page" => 1,
    "per_page" => 1000,
      "search" => nil,
        "sort" => {
           "by" => nil,
        "order" => nil
    },
     "results" => [
      ...
}

Requesting Information for a Host

This request returns information for the host satellite.example.com.

Example request:

$  curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/satellite.example.com \
| python -m json.tool

Example response:

{
    "all_puppetclasses": [],
    "architecture_id": 1,
    "architecture_name": "x86_64",
    "build": false,
    "capabilities": [
        "build"
    ],
    "certname": "satellite.example.com",
    "comment": null,
    "compute_profile_id": null,
    ...
}

Listing Host Facts

This request returns all facts for the host satellite.example.com.

Example request:

$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \
| python -m json.tool

Example response:

{
    ...
    "results": {
        "satellite.example.com": {
            "augeasversion": "1.0.0",
            "bios_release_date": "01/01/2007",
            "bios_version": "0.5.1",
            "blockdevice_sr0_size": "1073741312",
            "facterversion": "1.7.6",
            ...
}

Searching for Hosts with Matching Patterns

This query returns all hosts that match the pattern "example".

Example request:

$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=example \
| python -m json.tool

Example response:

{
    ...
    "results": [
        {
            "name": "satellite.example.com",
            ...
        }
    ],
    "search": "example",
    ...
}

Searching for Hosts in an Environment

This query returns all hosts in the production environment.

Example request:

$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=environment=production \
| python -m json.tool

Example response:

{
    ...
    "results": [
        {
            "environment_name": "production",
            "name": "satellite.example.com",
            ...
        }
    ],
    "search": "environment=production",
    ...
}

Searching for Hosts with a Specific Fact Value

This query returns all hosts with a model name RHEV Hypervisor.

Example request:

$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" \
| python -m json.tool

Example response:

{
    ...
    "results": [
        {
            "model_id": 1,
            "model_name": "RHEV Hypervisor",
            "name": "satellite.example.com",
            ...
        }
    ],
    "search": "model=\"RHEV Hypervisor\"",
    ...
}

Deleting a Host

This request deletes a host with a name host1.example.com.

Example request:

$ curl --request DELETE --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/host1.example.com \
| python -m json.tool

Downloading a Full Boot Disk Image

This request downloads a full boot disk image for a host by its ID.

Example request:

$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/bootdisk/api/hosts/host_ID?full=true \
--output image.iso

5.2. Working with Life Cycle Environments

Satellite divides application life cycles into life cycle environments, which represent each stage of the application life cycle. Life cycle environments are linked to from an environment path. To create linked life cycle environments with the API, use the prior_id parameter.

You can find the built-in API reference for life cycle environments at https://satellite.example.com/apidoc/v2/lifecycle_environments.html. The API routes include /katello/api/environments and /katello/api/organizations/:organization_id/environments.

Listing Life Cycle Environments

Use this API call to list all the current life cycle environments on your Satellite for the default organization with ID 1.

Example request:

$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request GET --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/organizations/1/environments \
| python -m json.tool`

Example response:

      output omitted
   "description": null,
   "id": 1,
   "label": "Library",
   "library": true,
   "name": "Library",
   "organization": {
        "id": 1,
        "label": "Default_Organization",
        "name": "Default Organization"
   },
   "permissions": {
       "destroy_lifecycle_environments": false,
       "edit_lifecycle_environments": true,
       "promote_or_remove_content_views_to_environments": true,
       "view_lifecycle_environments": true
   },
   "prior": null,
   "successor": null,
   output truncated

Creating Linked Life Cycle Environments

Use this example to create a path of life cycle environments.

This procedure uses the default Library environment with ID 1 as the starting point for creating life cycle environments.

  1. Choose an existing life cycle environment that you want to use as a starting point. List the environment using its ID, in this case, the environment with ID 1:

    Example request:

    $ curl --request GET --user sat_username:sat_password --insecure \
    https://satellite.example.com/katello/api/environments/1 \
    | python -m json.tool

    Example response:

    	output omitted
       "id": 1,
       "label": "Library",
    	output omitted
        "prior": null,
        "successor": null,
      output truncated
  2. Create a JSON file, for example, life-cycle.json, with the following content:

    {"organization_id":1,"label":"api-dev","name":"API Development","prior":1}
  3. Create a life cycle environment using the prior option set to 1.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request POST --user sat_username:sat_password --insecure \
    --data @life-cycle.json \
    https://satellite.example.com/katello/api/environments \
    | python -m json.tool

    Example response:

          output omitted
        "description": null,
        "id": 2,
        "label": "api-dev",
        "library": false,
        "name": "API Development",
        "organization": {
            "id": 1,
            "label": "Default_Organization",
            "name": "Default Organization"
        },
        "permissions": {
            "destroy_lifecycle_environments": true,
            "edit_lifecycle_environments": true,
            "promote_or_remove_content_views_to_environments": true,
            "view_lifecycle_environments": true
        },
       "prior": {
            "id": 1,
            "name": "Library"
        },
        output truncated

    In the command output, you can see the ID for this life cycle environment is 2, and the life cycle environment prior to this one is 1. Use the life cycle environment with ID 2 to create a successor to this environment.

  4. Edit the previously created life-cycle.json file, updating the label, name, and prior values.

    {"organization_id":1,"label":"api-qa","name":"API QA","prior":2}
  5. Create a life cycle environment, using the prior option set to 2.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request POST --user sat_username:sat_password --insecure \
    --data @life-cycle.json \
    https://satellite.example.com/katello/api/environments \
    | python -m json.tool

    Example response:

          output omitted
       "description": null,
       "id": 3,
        "label": "api-qa",
        "library": false,
        "name": "API QA",
        "organization": {
            "id": 1,
            "label": "Default_Organization",
            "name": "Default Organization"
        },
        "permissions": {
            "destroy_lifecycle_environments": true,
            "edit_lifecycle_environments": true,
            "promote_or_remove_content_views_to_environments": true,
            "view_lifecycle_environments": true
        },
       "prior": {
            "id": 2,
            "name": "API Development"
        },
        "successor": null,
        output truncated

    In the command output, you can see the ID for this life cycle environment is 3, and the life cycle environment prior to this one is 2.

Updating a Life Cycle Environment

You can update a life cycle environment using a PUT command.

This example request updates a description of the life cycle environment with ID 3.

Example request:

$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" \
--request POST --user sat_username:sat_password --insecure \
--data '{"description":"Quality Acceptance Testing"}' \
https://satellite.example.com/katello/api/environments/3 \
| python -m json.tool

Example response:

      output omitted
    "description": "Quality Acceptance Testing",
    "id": 3,
    "label": "api-qa",
    "library": false,
    "name": "API QA",
    "organization": {
        "id": 1,
        "label": "Default_Organization",
        "name": "Default Organization"
    },
    "permissions": {
        "destroy_lifecycle_environments": true,
        "edit_lifecycle_environments": true,
        "promote_or_remove_content_views_to_environments": true,
        "view_lifecycle_environments": true
    },
    "prior": {
        "id": 2,
        "name": "API Development"
    },
    output truncated

Deleting a Life Cycle Environment

You can delete a life cycle environment provided it has no successor. Therefore, delete them in reverse order using a command in the following format:

Example request:

$ curl --request DELETE --user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/environments/:id

5.3. Uploading Content to the Satellite Server

This section outlines how to use the Satellite 6 API to upload and import large files to your Satellite Server. This process involves four steps:

  1. Create an upload request.
  2. Upload the content.
  3. Import the content.
  4. Delete the upload request.

The maximum file size that you can upload is 2MB. For information about uploading larger content, see Uploading Content Larger than 2 MB.

Procedure

  1. Create the upload request. Ensure you modify the example parameters to suit your deployment.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request POST --insecure \
    --user sat_username:sat_password  --data "{}" \
    https://satellite.example.com/katello/api/repositories/3/content_uploads

    This command returns the upload_id.

    Example response:

    {"upload_id":"0be156b1-f373-4cad-89d0-924f8f4491d2","_href":"/pulp/api/v2/content/uploads/0be156b1-f373-4cad-89d0-924f8f4491d2/"}

    Note the upload_id for uploading the content.

  2. Upload your content. Ensure you use the correct MIME type when you upload data. The API uses the application/json MIME type for the majority of requests to Satellite 6. Combine the upload_id, MIME type, and other parameters to upload content.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:multipart/form-data" \
    --request PUT --insecure --user sat_username:sat_password \
    --data-urlencode "content@/home/sat6user/rpmbuild/RPMS/noarch/python-scripttest-1.1.1-1.fc21.noarch.rpm" \
    --data-urlencode offset=0 \
    https://satellite.example.com/katello/api/repositories/3/content_uploads/0be156b1-f373-4cad-89d0-924f8f4491d2
  3. After you have uploaded the content to the Satellite Server, you need to import it into the appropriate repository. Until you complete this step, the Satellite Server does not detect the new content.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request PUT --insecure \
    --user sat_username:sat_password \
    --data "{\"uploads\":[\"0be156b1-f373-4cad-89d0-924f8f4491d2\"]}" \
    https://satellite.example.com/katello/api/repositories/3/import_uploads
  4. After you have successfully uploaded and imported your content, you can delete the upload request. This frees any temporary disk space that data is using during the upload.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request DELETE --insecure \
    --user sat_username:sat_password --data "{}" \
    https://satellite.example.com/katello/api/repositories/3/content_uploads/0be156b1-f373-4cad-89d0-924f8f4491d2

Uploading Content Larger than 2 MB

The following example demonstrates how to split a large file into chunks, create an upload request, upload the individual files, import them to Satellite, and then delete the upload request. Note that this example uses sample content, host names, user names, and file names.

  1. Use the following example to split your file into 2MB chunks:

    $ split --bytes 2MB --numeric-suffixes --suffix-length=1 \
    theforeman-foreman-5.0.1.tar.gz foreman_module.
  2. View the resulting files:

    $ ls -la theforeman-foreman-5.0.1.tar.gz foreman_module.*
    -rw-r--r--. 1 root root 50000 Nov  4 04:42 foreman_module.0
    -rw-r--r--. 1 root root 32928 Nov  4 04:42 foreman_module.1
    -rw-r--r--. 1 root root 82928 Nov  4 04:41 theforeman-foreman-5.0.1.tar.gz
  3. Create an upload request.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request POST --insecure --user sat_username:sat_password --data "{}" \
    https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads

    Example response:

    {"upload_id":"9585528f-07ad-4bb1-9c80-ccece249b2b7","_href":"/pulp/api/v2/content/uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7/"}

    Note the upload_id for uploading the content.

  4. Upload the file chunks to Satellite Server. Notice the use of the offset parameter in this example and how it relates to the file size:

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:multipart/form-data" \
    --request PUT --insecure --user sat_username:sat_password \
    --data-urlencode "content@foreman_module.0" \
    --data-urlencode offset=0 \
    https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7
  5. Import the complete upload to the repository:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request PUT --insecure --user sat_username:sat_password \
    --data "{\"upload_ids\":[\"9585528f-07ad-4bb1-9c80-ccece249b2b7\"]}" \
    https://ibm-vm01.example.com/katello/api/repositories/2/import_uploads
  6. Delete the upload request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request DELETE --insecure --user sat_username:sat_password --data "{}" \
    https://ibm-vm01.example.com/katello/api/repositories/2/content_uploads/9585528f-07ad-4bb1-9c80-ccece249b2b7
  7. On Satellite Server, check the transferred file:

    # ls -la /var/lib/pulp/content/puppet_module/theforeman-foreman-5.0.1.tar.gz
    -rw-r--r--. 1 apache apache 82928 Nov  4 04:55 /var/lib/pulp/content/puppet_module/theforeman-foreman-5.0.1.tar.gz
  8. Verify that the initial file is the same as the transferred by comparing them:

    $ cmp /var/lib/pulp/content/puppet_module/theforeman-foreman-5.0.1.tar.gz \
    theforeman-foreman-5.0.1.tar.gz

5.4. Applying Errata to a Host or Host Collection

You can use the API to apply errata to a host, host group, or host collection. The following is the basic syntax of a PUT request:

$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" --request PUT \
--user sat_username:sat_password --insecure \
--data json-formatted-data https://satellite7.example.com

You can browse the built in API doc to find a URL to use for applying Errata. You can use the Satellite web UI to help discover the format for the search query. Navigate to Hosts > Host Collections and select a host collection. Go to Collection Actions > Errata Installation and notice the search query box contents. For example, for a Host Collection called my-collection, the search box contains host_collection="my-collection".

Applying Errata to a Host

This example uses the API URL for bulk actions /katello/api/hosts/bulk/install_content to show the format required for a simple search.

Example request:

$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" --request PUT \
--user sat_username:sat_password --insecure \
--data "{\"organization_id\":1,\"included\":{\"search\":\"my-host\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" \
https://satellite.example.com/api/v2/hosts/bulk/install_content

Applying Errata to a Host Collection

In this example, notice the level of escaping required to pass the search string host_collection="my-collection" as seen in the Satellite web UI.

Example request:

$ curl --header "Accept:application/json" \
--header "Content-Type:application/json" --request PUT \
--user sat_username:sat_password --insecure \
--data "{\"organization_id\":1,\"included\":{\"search\":\"host_collection=\\\"my-collection\\\"\"},\"content_type\":\"errata\",\"content\":[\"RHBA-2016:1981\"]}" \
https://satellite.example.com/api/v2/hosts/bulk/install_content

5.5. Using Extended Searches

You can find search parameters that you can use to build your search queries in the web UI. For more information, see Building Search Queries in Administering Red Hat Satellite.

For example, to search for hosts, complete the following steps:

  1. In the Satellite web UI, navigate to Hosts > All Hosts and click the Search field to display a list of search parameters.
  2. Locate the search parameters that you want to use. For this example, locate os_title and model.
  3. Combine the search parameters in your API query as follows:

    Example request:

    $ curl --insecure --user sat_username:sat_password \
    https://satellite.example.com/api/v2/hosts?search=os_title=\"RedHat+7.7\",model=\"PowerEdge+R330\" \
    | python -m json.tool

    Example response:

      {
        ...
        "results": [
            {
                "model_id": 1,
                "model_name": "PowerEdge R330",
                "name": "satellite.example.com",
                "operatingsystem_id": 1,
                "operatingsystem_name": "RedHat 7.7",
                ...
            }
        ],
        "search": "os_title=\"RedHat 7.7\",model=\"PowerEdge R330\"",
        "subtotal": 1,
        "total": 11
    }

5.6. Using Searches with Pagination Control

You can use the per_page and page pagination parameters to limit the search results that an API search query returns. The per_page parameter specifies the number of results per page and the page parameter specifies which page, as calculated by the per_page parameter, to return.

The default number of items to return is set to 1000 when you do not specify any pagination parameters, but the per_page value has a default of 20 which applies when you specify the page parameter.

Listing Content Views

This example returns a list of Content Views in pages. The list contains 10 keys per page and returns the third page.

Example request:

$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=10&page=3

Listing Activation Keys

This example returns a list of activation keys for an organization with ID 1 in pages. The list contains 30 keys per page and returns the second page.

Example request:

$ curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/activation_keys?organization_id=1&per_page=30&page=2

Returning Multiple Pages

You can use a for loop structure to get multiple pages of results.

This example returns pages 1 to 3 of Content Views with 5 results per page:

$ for i in seq 1 3; do \
curl --request GET --user sat_username:sat_password \
https://satellite.example.com/katello/api/content_views?per_page=5&page=$i; \
done

5.7. Overriding Smart Class Parameters

You can search for Smart Parameters using the API and supply a value to override a Smart Parameter in a Class. You can find the full list of attributes that you can modify in the built-in API reference at https://satellite.example.com/apidoc/v2/smart_class_parameters/update.html.

  1. Find the ID of the Smart Class parameter you want to change:

    • List all Smart Class Parameters.

      Example request:

      $ curl --request GET --insecure --user sat_username:sat_password \
      https://satellite.example.com/api/smart_class_parameters
    • If you know the Puppet class ID, for example 5, you can restrict the scope:

      Example request:

      $ curl --request GET --insecure --user sat_username:sat_password \
      https://satellite.example.com/api/puppetclasses/5/smart_class_parameters

      Both calls accept a search parameter. You can view the full list of searchable fields in the Satellite web UI. Navigate to Configure > Smart variables and click in the search query box to reveal the list of fields.

      Two particularly useful search parameters are puppetclass_name and key, which you can use to search for a specific parameter. For example, using the --data option to pass URL encoded data.

      Example request:

      $ curl --request GET --insecure --user sat_username:sat_password \
      --data 'search=puppetclass_name = access_insights_client and key = authmethod' \
      https://satellite.example.com/api/smart_class_parameters

      Satellite supports standard scoped-search syntax.

  2. When you find the ID of the parameter, list the full details including current override values.

    Example request:

    $ curl --request GET --insecure --user sat_username:sat_password \
    https://satellite.example.com/api/smart_class_parameters/63
  3. Enable overriding of parameter values.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request PUT --insecure --user sat_username:sat_password \
    --data '{"smart_class_parameter":{"override":true}}' \
    https://satellite.example.com/api/smart_class_parameters/63

    Note that you cannot create or delete the parameters manually. You can only modify their attributes. Satellite creates and deletes parameters only upon class import from a proxy.

  4. Add custom override matchers.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request PUT --insecure --user sat_username:sat_password \
    --data '{"smart_class_parameter":{"override_value":{"match":"hostgroup=Test","value":"2.4.6"}}}' \
    https://satellite.example.com/api/smart_class_parameters/63

    For more information about override values, see https://satellite.example.com/apidoc/v2/override_values.html.

  5. You can delete override values.

    Example request:

    $ curl --request DELETE --user sat_username:sat_password \
    https://satellite.example.com/api/smart_class_parameters/63/override_values/3

5.8. Modifying a Smart Class Parameter Using an External File

Using external files simplifies working with JSON data. Using an editor with syntax highlighting can help you avoid and locate mistakes.

Modifying a Smart Class Parameter Using an External File

This example uses a MOTD Puppet manifest.

  1. Search for the Puppet Class by name, motd in this case.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request GET --user sat_user:sat_password --insecure \
    https://satellite.example.com/api/smart_class_parameters?search=puppetclass_name=motd \
    | python -m json.tool
  2. Examine the following output. Each Smart Class Parameter has an ID that is global for the same Satellite instance. The content parameter of the motd class has id=3 in this Satellite Server. Do not confuse this with the Puppet Class ID that displays before the Puppet Class name.

    Example response:

    {
    	"avoid_duplicates": false,
    		"created_at": "2017-02-06 12:37:48 UTC", # Remove this line.
    			"default_value": "", # Add a new value here.
    			"description": "",
    		"hidden_value": "",
    		"hidden_value?": false,
    		"id": 3,
    		"merge_default": false,
    		"merge_overrides": false,
    		"override": false, # Set the override value to true.
    			"override_value_order": "fqdn\nhostgroup\nos\ndomain",
    		"override_values": [], # Remove this line.
    			"override_values_count": 0,
    		"parameter": "content",
    		"parameter_type": "string",
    		"puppetclass_id": 3,
    		"puppetclass_name": "motd",
    		"required": false,
    		"updated_at": "2017-02-07 11:56:55 UTC", # Remove this line.
    			"use_puppet_default": false,
    		"validator_rule": null,
    		"validator_type": ""
    }
  3. Use the parameter ID 3 to get the information specific to the motd parameter and redirect the output to a file, for example, output_file.json.

    Example request:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" --request GET \
    --user sat_user:sat_password --insecure \`
    https://satellite.example.com/api/smart_class_parameters/3 \
    | python -m json.tool > output_file.json
  4. Copy the file created in the previous step to a new file for editing, for example, changed_file.json:

    $ cp output_file.json changed_file.json
  5. Modify the required values in the file. In this example, change the content parameter of the motd module, which requires changing the override option from false to true:

    {
    	"avoid_duplicates": false,
    		"created_at": "2017-02-06 12:37:48 UTC", # Remove this line.
    			"default_value": "", # Add a new value here.
    			"description": "",
    		"hidden_value": "",
    		"hidden_value?": false,
    		"id": 3,
    		"merge_default": false,
    		"merge_overrides": false,
    		"override": false, # Set the override value to true.
    			"override_value_order": "fqdn\nhostgroup\nos\ndomain",
    		"override_values": [], # Remove this line.
    			"override_values_count": 0,
    		"parameter": "content",
    		"parameter_type": "string",
    		"puppetclass_id": 3,
    		"puppetclass_name": "motd",
    		"required": false,
    		"updated_at": "2017-02-07 11:56:55 UTC", # Remove this line.
    			"use_puppet_default": false,
    		"validator_rule": null,
    		"validator_type": ""
    }
  6. After editing the file, verify that it looks as follows and then save the changes:

    {
    	"avoid_duplicates": false,
    		"default_value": "No Unauthorized Access Allowed",
    			"description": "",
    		"hidden_value": "",
    		"hidden_value?": false,
    		"id": 3,
    		"merge_default": false,
    		"merge_overrides": false,
    		"override": true,
    			"override_value_order": "fqdn\nhostgroup\nos\ndomain",
    		"override_values_count": 0,
    		"parameter": "content",
    		"parameter_type": "string",
    		"puppetclass_id": 3,
    		"puppetclass_name": "motd",
    		"required": false,
    		"use_puppet_default": false,
    		"validator_rule": null,
    		"validator_type": ""
    }
  7. Apply the changes to Satellite Server:

    $ curl --header "Accept:application/json" \
    --header "Content-Type:application/json" \
    --request PUT --user sat_username:sat_password --insecure \
    --data @changed_file.json \
    https://satellite.example.com/api/smart_class_parameters/3

5.9. Deleting OpenSCAP reports

In Satellite Server, you can delete one or more OpenSCAP reports. However, when you delete reports, you must delete one page at a time. If you want to delete all Openscap reports, use the bash script that follows.

Deleting an OpenSCAP Report

To delete an OpenSCAP report, complete the following steps:

  1. List all OpenSCAP reports. Note the IDs of the reports that you want to delete.

    Example request:

    curl --insecure --user username:_password_ \
    https://satellite.example.com/api/v2/compliance/arf_reports/ | python -m json.tool

    Example response:

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  3252    0  3252    0     0   4319      0 --:--:-- --:--:-- --:--:--  4318
    {
        "page": 1,
        "per_page": 20,
        "results": [
            {
                "created_at": "2017-05-16 13:27:09 UTC",
                "failed": 0,
                "host": "host1.example.com",
                "id": 404,
                "othered": 0,
                "passed": 0,
                "updated_at": "2017-05-16 13:27:09 UTC"
            },
            {
                "created_at": "2017-05-16 13:26:07 UTC",
                "failed": 0,
                "host": "host2.example.com,
                "id": 405,
                "othered": 0,
                "passed": 0,
                "updated_at": "2017-05-16 13:26:07 UTC"
            },
            {
                "created_at": "2017-05-16 13:25:07 UTC",
                "failed": 0,
                "host": "host3.example.com",
                "id": 406,
                "othered": 0,
                "passed": 0,
                "updated_at": "2017-05-16 13:25:07 UTC"
            },
            {
                "created_at": "2017-05-16 13:24:07 UTC",
                "failed": 0,
                "host": "host4.example.com",
                "id": 407,
                "othered": 0,
                "passed": 0,
                "updated_at": "2017-05-16 13:24:07 UTC"
            },
        ],
        "search": null,
        "sort": {
            "by": null,
            "order": null
        },
        "subtotal": 29,
        "total": 29
  2. Using an ID from the previous step, delete the OpenSCAP report. Repeat for each ID that you want to delete.

    Example request:

    # curl --insecure --user username:_password_ \
    --header "Content-Type: application/json" \
    --request DELETE https://satellite.example.com/api/v2/compliance/arf_reports/405

    Example response:

    HTTP/1.1 200 OK
    Date: Thu, 18 May 2017 07:14:36 GMT
    Server: Apache/2.4.6 (Red Hat Enterprise Linux)
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    Foreman_version: 1.11.0.76
    Foreman_api_version: 2
    Apipie-Checksum: 2d39dc59aed19120d2359f7515e10d76
    Cache-Control: max-age=0, private, must-revalidate
    X-Request-Id: f47eb877-35c7-41fe-b866-34274b56c506
    X-Runtime: 0.661831
    X-Powered-By: Phusion Passenger 4.0.18
    Set-Cookie: request_method=DELETE; path=/
    Set-Cookie: _session_id=d58fe2649e6788b87f46eabf8a461edd; path=/; secure; HttpOnly
    ETag: "2574955fc0afc47cb5394ce95553f428"
    Status: 200 OK
    Vary: Accept-Encoding
    Transfer-Encoding: chunked
    Content-Type: application/json; charset=utf-8

Example BASH Script to Delete All OpenSCAP Reports

Use the following bash script to delete all the OpenSCAP reports:

#!/bin/bash

#this script removes all the arf reports from the satellite server

#settings
USER=username
PASS=password
URI=https://satellite.example.com

#check amount of reports
 while [ $(curl --insecure --user $USER:$PASS $URI/api/v2/compliance/arf_reports/ | python -m json.tool | grep \"\total\": | cut --fields=2 --delimiter":" | cut --fields=1 --delimiter"," | sed "s/ //g") -gt 0 ]; do

#fetch reports
 for i in $(curl --insecure --user $USER:$PASS $URI/api/v2/compliance/arf_reports/ | python -m json.tool | grep \"\id\": | cut --fields=2 --delimiter":" | cut --fields=1 --delimiter"," | sed "s/ //g")

#delete reports
  do
  curl --insecure --user $USER:$PASS --header "Content-Type: application/json" --request DELETE $URI/api/v2/compliance/arf_reports/$i
  done
done
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.