Use CEL Expressions in Alert Rules
Learn how to use CEL expressions to write dynamic conditions for alert rules in Harness AI SRE.
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.
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
inoperator 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.fingerprint // Deduplication fingerprint
alert.severity // Severity from source system
alert.url // Link to alert in source system
alert.environment // Environment field from alert payloadCustom 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
inoperator
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
Next steps
Go to Create Dynamic Content for complete CEL syntax reference, additional operators, and advanced patterns
Go to Route Alerts to learn about alert rule configuration
Go to Ingest Alerts to set up incoming alert sources
Last updated
Was this helpful?