On This Page

Home / Cribl as Code/ Cribl API/ API Workflows/ Cribl Search Workflows/Save Searches and Get Alerts

Save Searches and Get Alerts

Use the Cribl API to save and schedule searches, then configure a Notification target and Notification so that you can receive alerts based on specific search results.

About the Example Requests

Replace the variables in the example requests with the corresponding information for your Cribl deployment.

In the cURL command options, replace ${token} with a valid API Bearer token. You can also set the $token environment variable to match the value of a Bearer token.

You must commit and deploy the changes you make. You can use the Cribl API to automate commit and deploy commands.

To save a search, send a request to the POST /search/saved endpoint. The response is a JSON object with details about the saved search.

Saved searches are available to schedule to run at your desired interval.

Save a Search ExampleBody Parameter InformationResponse Example

Schedule an existing saved search by sending a request to PATCH /search/saved/{id}. The request URL uses the id value for an existing saved search to specify the search to schedule.

A PATCH /search/saved/{id} request updates the specified saved search to add a schedule object. If you want to maintain the unscheduled saved search, you can save and schedule the search in a single API request with POST /search/saved—just make sure to use a unique name and id in the request body.

The PATCH /search/saved/{id} endpoint requires a complete representation of the search that you want to schedule in the request body. This endpoint does not support partial updates. Cribl removes any omitted fields when updating the search to include a schedule.

Also, before you send the PATCH request, confirm that the search configuration is correct. If the existing configuration is incorrect, the updated search may not function as expected. The response is a JSON object that includes details for the saved and scheduled search.

Schedule a Saved Search ExampleBody Parameter InformationResponse Example

Create a Notification Target

To receive alerts when a scheduled search generates results that match the triggering conditions that you specify, you need a Notification target to send alerts to.

Once created, Notification targets are available across Cribl products. If you want to use the default System Messages target or an existing target, you can create a Notification without adding a new Notification target.

Amazon SNS Notification Target (Topic ARN)

This example creates an Amazon SNS Notification target for sending Notifications to an Amazon Simple Notification Service (SNS) topic. You can also configure Amazon SNS targets to send text messages (SMS) to a phone number.

The response is a JSON object that includes the Notification target configuration and a status object that lists the target’s health and metrics.

Amazon SNS Example (Topic ARN)Body Parameter InformationResponse Example

Amazon SNS Notification Target (Phone Number)

This example creates an Amazon SNS Notification target for sending text message (SMS) Notifications to a phone number. You can also configure a target that uses the Amazon Simple Notification Service (SNS) topic instead.

The response is a JSON object that includes the Notification target configuration and a status object that lists the target’s health and metrics.

Amazon SNS Example (Phone Number)Body Parameter InformationResponse Example

Email Notification Target

This example creates an email Notification target that uses the SMTP server of your choice. The response is a JSON object that includes the Notification target configuration and a status object that lists the target’s health and metrics.

Email ExampleBody Parameter InformationResponse Example

PagerDuty Notification Target

This example creates a PagerDuty Notification target that uses the Cribl Search native integration with the PagerDuty API. The response is a JSON object that includes the Notification target configuration and a status object that lists the target’s health and metrics.

PagerDuty ExampleBody Parameter InformationResponse Example

Slack Notification Target

This example creates a Slack Notification target that uses Slack’s incoming webhooks. The response is a JSON object that includes the Notification target configuration and a status object that lists the target’s health and metrics.

Slack ExampleBody Parameter InformationResponse Example

Webhook Notification Target

This example creates a webhook Notification target that applies a custom format to Notification events before sending them. The response is a JSON object that includes the Notification target configuration and a status object that lists the target’s health and metrics.

Webhook ExampleBody Parameter InformationResponse Example

Create a Notification to Send Alerts

Create a Notification to get alerts when a scheduled search generates results that match the triggering conditions that you specify.

When you create a Notification, Cribl also adds the Notification details to the search that you specified for savedQueryId. If you retrieve the saved search, its configuration will include the schedule and Notification details.

You must have a saved and scheduled search and a Notification target to create a Notification.

Cribl does not support creating Notification events for searches that reside within Packs.

The following example demonstrates how to create a Notification for a scheduled search based on a custom condition. The response is a JSON object that includes the Notification configuration.

Custom Condition ExampleBody Parameter InformationResponse Example

The following example demonstrates how to create a Notification for a scheduled search based on search results.

Search Results ExampleBody Parameter InformationResponse Example