Notification Filter Rules
Filter rules are the heart of the Notification system. They control which events trigger notifications and where those notifications are delivered. There is one global configuration for all notification filter rules: the Turbot > Notifications > Rule-Based Routing policy setting.
Navigate to Policies and select Actions > New Policy Setting. Search for Rule-Based Routing, select Rule-Based Routing (under Turbot > Notifications), set the resource to Turbot, and enter your rules as YAML.
Rule Structure
The policy contains an array of rule-sets. Each rule-set consists of one or more rules and one or more delivery targets.
- rules: "NOTIFY $.oldControl.state:ok $.control.state:alarm"
emails:
- [email protected]
slackWebhookUrl: "https://hooks.slack.com/services/T02GC4A7C/BUDS3GB05P/iI27FCQjgiI27FCQ"
msTeamsWebhookUrl: "https://goliathfederalbank.webhook.office.com/webhookb2/xxx/IncomingWebhook/yyy/zzz"
webhookUrl: "https://api.goliathfederalbank.com/guardrails/notifications"
Delivery targets. Each rule-set can include any combination:
| Target | Description |
|---|---|
emails | A list of email addresses. |
slackWebhookUrl | A Slack incoming webhook URL. |
msTeamsWebhookUrl | A Microsoft Teams incoming webhook URL. |
webhookUrl | A custom HTTPS webhook URL. |
profiles | Permission-based routing to Guardrails user profiles (see Routing to Profiles). |
Rule Processing
Rules are defined in a multi-line string. Each line is a separate statement containing an action and one or more match conditions.
- Each statement starts with
NOTIFY(send notification) orIGNORE(suppress it). - Rules are processed in order. Processing stops at the first match.
- If no rule matches, the default
IGNORE *applies and the notification is not sent. - Conditions use the Guardrails filter syntax.
Array matching: To compare items in arrays, use a splat operator:
.*.: All items must match. An empty list also matches..+.: All items must match. An empty list does NOT match.- Use
[]to match an empty list.
Examples
Alert when a control moves from OK to alarm
- rules: "NOTIFY $.oldControl.state:ok $.control.state:alarm"
emails:
- [email protected]
- [email protected]
slackWebhookUrl: "https://hooks.slack.com/services/XXXXXXX/YYYYYYYYYY/ZZZZZZZZZZZZZZ"
Alert on security group enforcement actions
- rules: |
NOTIFY $.actionType.parent:'#/resource/types/securityGroup'
NOTIFY $.actionType.uri:'tmod:@turbot/aws-vpc-security#/control/types/securityGroupApproved'
msTeamsWebhookUrl: "https://goliathfederalbank.webhook.office.com/webhookb2/xxx/IncomingWebhook/yyy/zzz"
Ignore a specific resource, alert on all other alarms in an account
- rules: |
IGNORE $.resource.Name:test-bucket-do-not-alert
NOTIFY $.control.state:alarm $.resource.turbot.custom.aws.accountId:'123456789012'
emails:
- [email protected]
Monitor a single resource by ARN
- rules: |
NOTIFY $.resource.turbot.akas[0]:'arn:aws:ec2:us-east-2:123456789012:instance/i-08b562451d0215732'
slackWebhookUrl: "https://hooks.slack.com/services/XXXXXXX/YYYYYYYYYY/ZZZZZZZZZZZZZZ"
msTeamsWebhookUrl: "https://goliathfederalbank.webhook.office.com/webhookb2/xxx/IncomingWebhook/yyy/zzz"
Route to account team members based on permissions
- rules: "NOTIFY $.oldControl.state:ok $.control.state:alarm"
profiles:
- "Account/Owner"
- "Account/Admin"
- "Account/CC"
The Account/CC profile sends notifications to addresses defined in the Turbot > Notifications > CC policy on the account. If Turbot > Notifications > CC > Tag is enabled, Guardrails also reads the tag specified by Turbot > Notifications > CC > Tag > Name (default: turbot_notification_cc) from the resource and sends to the comma-separated email addresses in that tag value. See CC Lists and Tag-Based Routing for setup details.
Exposed Metadata
Filter rules match against the notification metadata. The available fields depend on the notification type.
Control Update Metadata
Control notifications expose the full resource data, the current and previous control state, and the control type:
{
"resource": {
"Name": "asst-regional-manager-bucket",
"Tags": [{"Key": "foo", "Value": "bar"}],
"Encryption": {
"ServerSideEncryptionConfiguration": {
"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]
}
},
"turbot": {
"id": "261303520089583",
"title": "asst-regional-manager-bucket",
"tags": {"foo": "bar"},
"custom": {
"aws": {
"accountId": "111222333444",
"partition": "aws",
"regionName": "us-east-1"
}
},
"akas": ["arn:aws:s3:::asst-regional-manager-bucket"],
"resourceTypeId": "209189633173890"
}
},
"control": {
"state": "alarm",
"reason": "Not approved: Usage",
"turbot": {
"id": "261303520603122",
"stateChangeTimestamp": "2023-06-07T03:24:40.347Z"
}
},
"oldControl": {
"state": "ok",
"reason": "Approved",
"turbot": {
"id": "261303520603122",
"stateChangeTimestamp": "2023-06-06T12:48:08.928Z"
}
},
"controlType": {
"uri": "tmod:@turbot/aws-s3#/control/types/bucketApproved",
"title": "Approved",
"parent": "#/resource/types/bucket",
"parentUri": "tmod:@turbot/aws-s3#/resource/types/bucket",
"categoryUri": "tmod:@turbot/turbot#/control/categories/resourceApproved"
}
}
Action Update Metadata
Action notifications expose the action type details:
{
"actionType": {
"uri": "tmod:@turbot/aws-s3#/action/types/bucketSetVersioning",
"title": "Set Versioning",
"parent": "#/resource/types/bucket",
"parentUri": "tmod:@turbot/aws-s3#/resource/types/bucket",
"categoryUri": "tmod:@turbot/turbot#/control/categories/other"
}
}
Next Steps
- Templates: Customize the format of notification messages.
- Configure Notifications: Enable notifications and set up delivery channels.