For the complete documentation index, see llms.txt. This page is also available as Markdown.
Ai SreExpressionsAlerts

Use CEL Expressions in Alert Rules

Use CEL expressions to write regex matching, multi-value checks, and complex boolean logic into alert rule conditions.

CEL (Common Expression Language) expressions provide advanced conditional logic for alert rule conditions beyond simple field comparisons.

CEL expressions cannot be tested or previewed before they execute. Syntax validation occurs when you save, but runtime errors only appear in execution logs. Test triggers in non-production environments first.

FEATURE FLAG REQUIRED

CEL expression mode requires the IR_CEL_CONDITIONS feature flag. Contact your Harness account team to enable this feature.

When to use CEL expressions to route alerts

Use CEL expressions when you need:

  • Regex pattern matching: Filter alerts by service name patterns

  • Complex boolean logic: Combine multiple conditions with custom precedence

  • String operations: Check if alert titles contain specific text, match patterns

  • Numeric comparisons: Filter by threshold values, error rates, percentages

  • Multi-value checks: Use in operator for cleaner multi-value matching


Available alert data in CEL expressions

Standard alert fields:

alert.id                 // Unique alert identifier
alert.title              // Alert title or summary
alert.priority           // p1_critical, p2_error, p3_warning, p4_info
alert.service            // Service name from alert payload
alert.source             // Alert source (datadog, newrelic, prometheus, etc.)
alert.timestamp          // When alert was received (milliseconds since epoch)
alert.severity           // Severity from source system
alert.url                // Link to alert in source system
alert.environment        // Environment field from alert payload

The variables available in an alert rule are the fields defined on the alert template. To stop repeated alerts from one monitor from opening new alerts, map the Deduplication ID field when you configure the integration. Go to Create a webhook to map it.

Custom alert fields:


CEL alert rule examples

Critical production alerts only:

High-priority alerts from specific sources:

Production API service alerts:

Error rate threshold:

Multiple service groups:

Alert title pattern matching:

Source and region filtering:

Complex multi-condition logic:


CEL operators to route alerts

Comparison:

Logical:

String operations:

List membership:


Field-based conditions versus CEL

Field-based conditions example:

  • Field: severity

  • Operator: equals

  • Value: critical

  • AND

  • Field: environment

  • Operator: equals

  • Value: production

Equivalent CEL expression:

CEL advantages:

  • More concise for complex conditions

  • Regex pattern matching

  • Calculations and numeric operations

  • Flexible string operations

  • Better for multi-value checks with in operator


Best practices for CEL in alert rules

1. Keep expressions simple and readable:

2. Use explicit parentheses:

3. Add null checks for optional fields:

4. Test with sample alerts:

  • Send test alerts through the webhook

  • Verify alert rule fires as expected

  • Check execution logs for errors

  • Refine expression based on results

5. Use in for multiple values:


Troubleshooting CEL in alert rules

Expression syntax errors when saving alert rule

Check for single = instead of ==, unclosed strings, missing parentheses, or typos in field names. Use the exact namespace prefix (alert.). The error message shows the position of the syntax error.

Field not found errors in alert rule CEL expression

Verify the field name matches exactly (case-sensitive) and exists in the alert payload. Use alert. prefix for all alert fields. For custom fields, ensure they are present in the incoming alert data.

Regex pattern not matching expected alerts

Test your regex pattern using an online regex tester. Escape special characters with backslashes. Use ^ for start of string and $ for end of string. Example: alert.service.matches( "^prod-api\\.") with escaped dot.

Null pointer errors when alert rule executes

Add null checks before accessing fields: alert.custom_field != null && alert.custom_field.contains("text"). Custom fields may not be present on every alert.


Next steps

FAQs

How do I stop repeated alerts from the same monitor from opening new alerts?

AI SRE has no fingerprint field. Alert deduplication works through the Deduplication ID field (deduplication_id), which you map from the incoming payload when you configure the integration, usually to whatever the source calls its monitor or check ID.

On ingest, AI SRE looks for an alert on the same alert template with the same Deduplication ID. If it finds one, the incoming payload updates that alert instead of creating a second one, so a flapping monitor produces a single alert with a rising update count. Deduplication ID appears on the alert details panel, and incidents have the same field.

There is no time window on the match. For alerts, the match is scoped to open statuses, so once an alert is closed, the next payload with the same Deduplication ID creates a new alert, however long the gap. Closing the alert is the boundary, not a clock. Incidents match on Deduplication ID regardless of status.

Correlation Tag and Correlation Duration are a separate feature that groups related alerts. Go to Create a webhook to configure them.

Need Help? Contact our support team by email at support@harness.io or visit the Harness Documentation for additional resources and troubleshooting guides.

Last updated

Was this helpful?