IBM Cloud Docs
Using cURL

Using cURL

You can use cURL, a command line tool, from a terminal to manage the IBM Cloud Monitoring service by using URL syntax.

cURL syntax

Use the following syntax from a terminal to run a cURL command:

curl -X <METHOD> <MONITORING_ENDPOINT>/<API_URL> <-H HEADERS,> [-d DATA]

Where

  • <METHOD> indicates the type of REST API call that you want to make.
  • <MONITORING-ENDPOINT> indicates the endpoint where the monitoring instance is available. For more inforamtion, see Monitoring endpoints. For example, the endpoint for an instance that is available in us-south is the following: https://us-south.monitoring.cloud.ibm.com
  • <API_URL> For more information about API URLs, see Monitoring REST APIs.
  • HEADERS add additional information such as information to authenticate with the IBM Cloud Monitoring service.
  • DATA allows you to pass additional information that might be required.

Headers for IAM Tokens

Use IAM tokens to authenticate with the IBM Cloud Monitoring service when you use the Monitoring REST API to automate routine tasks and monitor notifications.

In a cURL command, add the following options to authenticate with the IBM Cloud Monitoring service by using an IAM token:

-H "Authorization: $AUTH_TOKEN"
-H "IBMInstanceID: $GUID"
-H "SysdigTeamID: $TEAM_ID"

Where

  • IBMInstanceID indicates the GUID of the IBM Cloud Monitoring instance that you want to target with the cURL command.

    To get the GUID of the monitoring instance, run the following command: ibmcloud resource service-instance <NAME> --output json | jq -r '.[].guid'

  • Authorization indicates the IAM token that is used to authenticate with the IBM Cloud Monitoring service instance.

    To get the IAM AUTH_TOKEN token, run the following command: ibmcloud iam oauth-tokens | awk '{print $4}'

    For more information, see Getting the IAM API token.

  • SysdigTeamID indicates the GUID of a team.

    To get the GUID, see Getting the ID of a Monitoring team.

Headers for Monitoring Token

You can also use Monitoring API tokens to authenticate with the IBM Cloud Monitoring service when you use the Monitoring REST API to automate routine tasks and monitor notifications.

In a cURL command, add the following command option to authenticate with the IBM Cloud Monitoring service by using a Monitoring token:

-H "Authorization: Bearer $SYSDIG_TOKEN"

To get the Monitoring token, see Getting the Monitoring API token.

Running a cURL API query

To run a cURL API query and authrnticat by using the IAM token, complete the following steps:

  1. Set the IAM token.

    AUTH_TOKEN=$(ibmcloud iam oauth-tokens | awk '{print $4}')
    
  2. Set the IBM Cloud Monitoring instance GUID.

    GUID=$(ibmcloud resource service-instance <NAME> --output json | jq -r '.[].guid')
    
  3. Run the cURL API query.

    curl -X <METHOD> <MONITORING_ENDPOINT>/<API_URL> -H "Authorization: $AUTH_TOKEN" -H "IBMInstanceID: $GUID" -H "content-type: application/json"
    

For example, to create an alert where the alert definition and notification channel is defined through a JSON file, you can run the following command:

curl -X POST \
  https://us-south.monitoring.cloud.ibm.com/api/alerts \
  -H 'Authorization: Bearer eyJraW...' \
  -H 'IBMInstanceID: fc8ceb8a-...' \
  -H 'Content-Type: application/json' \
  -d @alert.json