--- id: write-aggregation-rule title: Write an Aggregation Rule sidebar_label: Aggregation Rule description: Learn how to write an aggregation rule. slug: /help/docs/cse/rules/write-aggregation-rule/ canonical: https://www.sumologic.com/help/docs/cse/rules/write-aggregation-rule/ --- import useBaseUrl from '@docusaurus/useBaseUrl'; import CseRule from '../../reuse/cse-rule-description-links.md'; import CseDynamicSeverity from '../../reuse/cse-dynamic-severity.md'; import Iframe from 'react-iframe'; This topic has information about Cloud SIEM aggregation rules and how to write them. :::info If you are new to writing your own Cloud SIEM rules, see [Before You Write a Custom Rule](/docs/cse/rules/before-writing-custom-rule) for tips and techniques that are useful for getting started. ::: import TerraformLink from '../../reuse/terraform-link.md'; :::tip You can use Terraform to manage aggregation rules with the [`sumologic_cse_aggregation_rule`](https://registry.terraform.io/providers/SumoLogic/sumologic/latest/docs/resources/cse_aggregation_rule) resource. ::: ## About aggregation rules This section describes the purpose of aggregation rules, and gives an example of how you would use one. If you’re ready to jump in and configure a rule, see [Create an aggregation rule](#create-an-aggregation-rule) below. An aggregation rule is useful when you want to fire a signal based multiple conditions—up to six—being met over a period of time.  As an example, suppose you want to  fire a signal when the ratio of failed to successful HTTP requests is too high—75% or more. You can use an aggregation rule to calculate the percentage of failed requests, and configure the rule to fire a signal when the request failure rate is 75% or higher. The table below summarizes the rule configuration. Each row corresponds to an element of the sentence-style configuration UI for the **If Triggered** settings for an aggregation rule. | Configuration setting | What it does | |:--|:--| | When records matching the expression
`!isNull(http_response_statusCode)` | Filters the records to which the rule will be applied: only records that contain a non-null `http_response_statusCode` field. | | **grouped by** `device_ip` | Specifies the field by which aggregation results will be grouped: `device_ip` | | **within** 5 minutes | Specifies the duration across which records will be evaluated. | | Aggregation 1
Name. `good`
Function. `count`
Expression. `http_response_statusCode <= 201` | Defines an aggregation named “good”, which counts the number of records encountered during the within duration in which the `http_response_statusCode` value is less than or equal to 201, which indicates a request was successful. | | Aggregation 2
Name. `bad`
Function. `count`
Expression. `http_response_statusCode > 201` | Defines an aggregation named “bad”, which counts the number of records encountered during the within duration in which the `http_response_statusCode` value is less greater than 201, which indicates a request failed. | | that match the following condition
`(bad/(good+bad))*100 > 75` | Specifies the condition for firing a signal based on the results of the “good” and “bad” aggregation: more than 75% percent of requests failed during the within duration. | The screenshot below shows the **If Triggered** configuration for the example rule in the Rules Editor.  If Triggered section of an aggregation rule :::training Micro Lesson Watch this micro lesson to learn how to create an aggregation rule.