On This Page

Home / Cribl as Code/ Cribl API/ API Code Examples/Configure Resources with the Cribl API

Configure Resources with the Cribl API

These code examples demonstrate how to use the Cribl API to create the following resources in Cribl Stream:

  • A Syslog Source to receive data on port 9021.
  • An S3 Destination to store processed data.
  • A Pipeline that filters events and keeps only data in the eventSource and eventID fields.
  • A Route that connects the Source, Pipeline, and Destination.

The examples also include deploying the resource configurations to a Worker Group to make them active. The examples use the Worker Group created in Configure Worker Groups to manage the resource configuration.

About Code Examples

Code examples use Bearer token authentication. Read the API authentication documentation to learn how to configure authentication. The API Credential (Cribl.Cloud and hybrid) or login credentials (on-prem) that you use to obtain the Bearer token must have the necessary Permissions for the operations in code examples.

Replace the variables in code examples with the corresponding information for your Cribl deployment.

For on-prem deployments, to use https in request URLs, you must configure Transport Layer Security (TLS).

Code examples do not include all available body parameters. For a complete list of body parameters for specific endpoints, refer to the documentation in the API Reference.

Create a Source

This example creates a Syslog Source to receive data on port 9021.

Cribl.Cloud and HybridOn-Prem

Create a Destination

This example creates an S3 Destination to store processed data. Replace placeholder values like your-aws-api-key before you run the example.

Cribl.Cloud and HybridOn-Prem

Create a Pipeline

This example creates a Pipeline that filters events and keeps only data in the eventSource and eventID fields.

Cribl.Cloud and HybridOn-Prem

Create a Route

This example creates a Route that connects the Syslog Source, Pipeline, and S3 Destination and adds it to the end of the default Routing table. The Routing table already includes a default Route, so this request changes the default Route’s setting for final to false so that it won’t block the new Route.

The PATCH /routes/default endpoint requires a complete representation of the Routing table and its existing Routes in the request body. This endpoint does not support partial updates. Cribl removes any omitted fields when updating the Routing table. Use GET /routes/default to retrieve the existing Routing table to use in the body of the PATCH request.

Cribl.Cloud and HybridOn-Prem

Commit and Deploy the Resource Configurations

This example demonstrates how to commit and deploy the resource configurations to your Worker Group, then commit to the Leader to keep it in sync with the Worker Group.

Committing and deploying the Worker Group configuration requires three requests: commit to the Worker Group, deploy to the Worker Group, and commit the the Leader to keep it in sync.

First, commit the pending resource configurations to the Worker Group:

Cribl.Cloud and HybridOn-Prem

Next, deploy the committed changes to the Worker Group. This request includes the version body parameter, which uses the value of commit from the response body for the commit request:

Cribl.Cloud and HybridOn-Prem

Finally, commit the changes to the Leader to keep the Leader in sync with the Worker Group:

Cribl.Cloud and HybridOn-Prem