This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Analytic Rules

Analytic Rules are queries that can be run against the data either as it is ingested or on a scheduled basis.

An Analytic Rule runs a query over your data and turns each row the query returns into a detection. Detections are then delivered to one or more destinations, either written to a Feed as XML or sent to people by email.

A rule is the combination of four things, each of which has its own tab on the rule.

  • The query that decides what counts as a detection.
  • The processing type, which decides when and how the query is run.
  • The execution settings, which for a scheduled rule decide when it runs and over what period.
  • The notifications, which decide where detections are delivered.

If you want to run a query on a schedule and send the results to someone as a file rather than as detections, use a Report instead. Reports and Analytic Rules share most of their configuration, so much of this section applies to both.

Processing Types

The Processing Type is set on the rule’s Execution tab and decides how the query is run. It is the most significant choice you make about a rule, because it determines what the rest of the rule’s configuration means.

Processing Type When the query runs Typical use
Scheduled Query On a schedule that you define, over a window of data. Most rules.
Streaming Against each Stream as it is processed. Rules that must alert as close to ingest as possible.
Table Builder Experimental, see below. Not for production use.

Changing the processing type changes which tabs the rule shows, because some settings only apply to one type.

Scheduled Query

A Scheduled Query rule runs its query on a schedule, for example every hour or at 03:00 each day. Each run covers a window of data, and the rule keeps track of which windows it has already covered so that it can work through history without gaps or repeats.

This is the type to use for most rules. It is also the only type available to Reports.

Streaming

A Streaming rule is run by a Processor filter , in the same way as a translation pipeline. Each stream that matches the filter is passed through the rule as it is processed, so detections are raised without waiting for a schedule to come round.

Table Builder

Table Builder is an experimental feature and should not be used.

Anatomy of a Rule

The tabs shown on an Analytic Rule depend on its processing type.

Tab Shown for Purpose
Query All The query that defines the rule, see Query.
Settings All What the rule declares about itself, and where its errors go, see Settings.
Notifications All Where detections are delivered, see Notifications.
Execution All Processing type, and the schedules for a Scheduled Query rule, see Execution.
Shards Table Builder only The data held in the rule’s table, see Table Builder Rules.
Duplicate Management Scheduled Query only Suppression of repeated detections, see Duplicate Management.
Documentation All Markdown describing the rule.
Permissions All Who can read and use the rule.

The content of the Documentation tab is not just for readers. It is also used as the detailedDescription of the detections the rule raises, so it is worth writing something that will make sense to whoever receives the detection. This can be turned off per rule with Include Rule Documentation on the Settings tab.

Jobs

Analytic Rules are run by background jobs, all of which are disabled by default. A newly created rule will do nothing at all until the job for its processing type has been enabled in

Monitoring
Jobs
.

Job Drives
Analytic Executor: Scheduled Query Scheduled Query rules.
Analytic Executor: Table Builder Table Builder rules.
Analytic Execution History Retention Deletion of old execution history.

Streaming rules are run by the normal stream processing jobs rather than by a job of their own.

The job frequency controls how often Stroom looks for schedules that are due, not how often a rule runs. A rule scheduled to run every ten minutes will not do so if the job that looks for due schedules only runs hourly.

Configuration

Some rule behaviour is set by system properties rather than on the rule itself.

Property Purpose
stroom.analytics.timezone The time zone used when generating detections.
stroom.analytics.executionHistoryRetention How long execution history is kept.
stroom.analytics.emailConfig The SMTP server used for email notifications, see Notifications.
stroom.analytics.duplicateCheckStore The store behind Duplicate Management.
stroom.ui.analyticUiDefaultConfig The defaults offered in the UI for processing node, error feed and destination feed.

1 - Rule Queries

The query that defines what an Analytic Rule detects, and how its columns become the content of a detection.

The Query tab holds the StroomQl query that defines the rule. It is the same query editor used by the Query document, so you can write a query, run it and inspect the results while you are developing the rule.

Every row the query returns becomes one detection. This is the single most important thing to understand about a rule. A query that returns a million rows will raise a million detections, so it is worth running the query and looking at the row count before enabling the rule.

Choosing a Data Source

A rule query can use any data source that a Query document can use, but the choice interacts with the processing type.

  • A Scheduled Query rule can query anything, including Searchables and Lucene indexes.
  • A Streaming rule must query a View , because the View’s filter is what decides which streams are fed through the rule.

Time Ranges and Relative Times

A rule that is going to run repeatedly should express its time range relative to when it runs, not as absolute dates.

When a scheduled rule runs, Stroom sets the reference time for the query to the rule’s effective execution time rather than to the current clock time. Every relative date expression in the query and in the time range is then resolved against that effective time.

This is what makes it possible for a rule to work through history. A rule whose query says where EventTime >= day() - 1d will, when it runs for an effective time of last Tuesday, select last Monday’s data. The same query run for an effective time of today selects yesterday’s data.

Columns

The columns your query selects become the content of each detection.

Every column is added to the detection as a name/value pair, using the column’s name as the key, and is available to email templates through the values dictionary. Two column names are treated specially.

Column Treatment
StreamId Used as the streamId of the detection’s linked event rather than added to values.
EventId Used as the eventId of the detection’s linked event rather than added to values.

Including StreamId and EventId in the query is what allows a detection to link back to the Event that caused it. Without them the detection still carries all its other values, but there is nothing to click through to.

Table Preferences

Some things about a result table cannot be expressed in StroomQl , such as which columns are hidden, how values are formatted and how rows are sorted. These are set by interacting with the results table in the UI and are stored on the rule alongside the query.

For an Analytic Rule these preferences affect only what you see while developing the query. For a Report they also affect the file that is produced, because the report is written from the same table.

Parameters

A rule can define parameters in the same way as a Query document, and refer to them in the query. Parameters are stored on the rule, so a scheduled rule always runs with the values held against it.

2 - Rule Settings

What a rule declares about itself, whether its documentation is included in detections, and where its errors go.

The Settings tab holds the settings that describe the rule itself, rather than its query, its schedule or the notifications it sends.

Level and Status

Field Description
Level The severity of the rule.
Status How reliable the rule is.

Neither is mandatory. A rule that sets neither produces detections without them, which is how every rule created before these settings existed behaves.

Both are written to every detection the rule produces, whatever its processing type, and both are available to notification email templates as {{ level }} and {{ status }}.

Level describes how urgent a detection from this rule is, so that whoever receives it can prioritise.

Level Meaning
Low Little urgency. Worth recording, but not worth interrupting anyone for.
Medium Ordinary priority.
High Should be looked at ahead of lower level detections.
Critical The most urgent. Reserve it, or it stops meaning anything.

Status describes how much the rule can be trusted, which tells an analyst how much weight to give a detection and how many false positives to expect.

Status Meaning
Experimental An early-stage rule that may be incomplete. Expect more false positives.
Testing More mature than an experimental rule. Actively being validated in real environments. Expect some false positives.
Stable Considered production-ready. Has been thoroughly tested across multiple environments. Expect a reasonable false positive rate.
Deprecated An outdated or superseded rule that may rely on old techniques or assumptions. Generally avoid using these in production.

Include Rule Documentation

Field Description
Include Rule Documentation Whether the rule’s documentation is included in the detections it produces.

The content of the rule’s Documentation tab is written to each detection as detailedDescription, which means it leaves Stroom with the detection, for example by email. Untick this where the documentation is for whoever maintains the rule rather than for whoever receives its detections.

Feed for Errors

Field Description
Feed For Errors The Feed that errors occurring during execution are written to. Use Set Default to use the feed configured for the system.

Reports

A Report has a Settings tab of its own, holding Feed For Errors along with the settings that decide what kind of file it produces.

A report has no Level, Status or Include Rule Documentation, because it delivers a file rather than detections.

3 - Rule Execution

Execution schedules, how a scheduled rule works through time, and the history of what it has run.

The Execution tab sets the rule’s processing type, and for a Scheduled Query rule it is where you define when the rule runs.

A scheduled rule does not have a single schedule field. Instead it has a list of execution schedules, each of which runs the rule independently. The tab is split, with the schedules in the upper pane and the history of what those schedules have done in the lower one.

Everything on this page applies equally to Reports , which use the same execution machinery.

Execution Schedules

Use the button above the schedule list to add a schedule.

Field Description
Name A name for this schedule, used to identify it in the history and recorded on every detection it raises.
Enabled Whether this schedule runs. A schedule that is not enabled is ignored.
Processing Node The node that will run the rule. Use Set Default to use the node configured for the system.
Schedule A frequency or Cron expression saying how often the rule runs.
Start Time The effective time of the first run, see How Time Works.
End Time An optional effective time after which the schedule stops running.
Run As User The User whose permissions the query runs with.

Having more than one schedule on a rule is useful when you want the same query run over different periods. A common pattern is a frequent schedule that keeps up with new data, plus a second schedule with a start and end time that is used once to work back over history.

Run as User

The query runs with the permissions of the Run As User, not those of whoever created the rule. If that user cannot see some of the data, the rule will silently detect nothing in it.

How Time Works

Each run of a schedule has two different times associated with it, and telling them apart is the key to understanding scheduled rules.

Time Meaning
Execution Time The wall clock time at which the rule actually ran.
Effective Execution Time The point in time the run represents. This is what relative date expressions in the query resolve against.

For a rule that is keeping up with new data the two are almost the same. They diverge whenever a rule is catching up, because a rule that is behind will run now for an effective time in the past.

The effective time of the first run comes from the schedule’s Start Time, or from the next occurrence of the schedule if no start time is set. After each successful run Stroom records where it has got to, and the next run picks up from there.

Contiguous Execution

Whether a schedule catches up or skips ahead is decided by whether it is contiguous.

  • A contiguous schedule takes its next effective time from the last effective time. If the rule has not run for a week, it will work forward through that week one run at a time until it catches up. No window of data is missed.
  • A non-contiguous schedule takes its next effective time from the current time. If the rule has not run for a week, that week is skipped.

Contiguous execution is what you want for a rule that must not miss anything. Be aware that it means a rule which has been disabled for a long time, or whose start time is set well in the past, will have a lot of catching up to do when it is enabled.

Replaying an Execution

Selecting a row in the execution history and clicking Replay Execution sets up a re-run of that one execution.

Replaying does not run anything immediately. It adds a new execution schedule, named after the original with (replay) appended, whose start and end times are both the effective execution time of the row you selected. The new schedule is created disabled, so nothing happens until you enable it.

This is deliberate, as it gives you the chance to check the bounds before the rule runs again. Once enabled, the schedule runs the rule once for that effective time and then has nothing further to do.

Replay works on a single history row at a time. To re-run a range of executions, add an ordinary schedule with the start and end times you want instead.

Execution History

The lower pane lists what each schedule has done.

Column Description
Execution Time When the run happened.
Effective Execution Time The point in time the run represents.
Status Complete or Error.
Message The error message where the run failed.

History is kept for the period set by the stroom.analytics.executionHistoryRetention property and is deleted by the Analytic Execution History Retention job.

The Execution Schedule Manager

The rule’s Execution tab only shows that rule’s schedules.

Monitoring
Execution Schedule Manager
shows every execution schedule in the system, for Analytic Rules and Reports alike, and is where bulk operations live.

The list identifies each schedule by the document it belongs to as well as by its own name, and can be filtered.

Button Purpose
Edit Selected Schedule Edit one schedule, as on the rule itself.
Batch Edit Schedules Change the name, enabled state, processing node, schedule, bounds or run as user of many schedules at once.
Filter Schedules Narrow the list, for example to one document or one node.
Run Schedules Now Force schedules to run without waiting for them to fall due.
Delete Schedules Delete the selected schedules.

Run Schedules Now and Batch Edit Schedules can be applied either to the schedules you have selected or to everything matching the current filter.

Error Feed

Errors raised while a rule is running are written as Error streams to the rule’s error feed.

The feed is set by Feed For Errors on the Settings tab rather than on this one. Where the rule does not name one, the feed configured in stroom.ui.analyticUiDefaultConfig.defaultErrorFeed is used, and a run for which neither is set fails.

A run can fail before there is anywhere to write to, for example when neither the rule nor the system configuration names an error feed. Failures of that kind are recorded against the execution history instead, which is why it is worth looking at both.

4 - Rule Notifications

Delivering detections to a feed or to people by email, and limiting how many notifications a rule can send.

The Notifications tab decides what happens to the detections a rule raises. Settings that describe the rule as a whole, such as what its detections contain, are on the Settings tab instead.

The tab is a list of notifications. A rule can have any number of notifications and each one is delivered independently. A rule that both writes detections to a feed for later analysis and emails a few people about them has two notifications, not one.

Column Description
Enabled Whether this notification is delivered.
Type Stream or Email.
Destination The feed or email address that detections go to.
Limit Whether the number of notifications is limited.
Max The limit, where one is set.

Everything on this page applies to Reports as well, except that a report delivers a file rather than a detection. The differences are covered in Report Delivery.

Stream Destinations

A Stream notification writes detections into a Feed as XML conforming to the detection:1 XML Schema . This is the right choice when detections are themselves data, to be indexed, searched, or fed into another rule.

Field Description
Destination Feed The feed the detections are written to. Use Set Default to use the feed configured for the system.
Use Source Feed If Possible Writes detections to the feed the source data came from rather than to the destination feed.

Use Source Feed If Possible is useful for a streaming rule that runs across many feeds and whose detections are best kept alongside the data that produced them.

Email Destinations

An Email notification sends each detection to people as an email.

Field Description
To Recipient addresses.
Cc Addresses to copy.
Bcc Addresses to copy without other recipients seeing.
Email Subject Template A template for the subject line.
Email Body Template A template for the body.

Each field accepts more than one address.

Templates

The subject and body are Jinja templates rather than fixed text, so that each email can describe the detection that triggered it.

The values from the detection are put into the template context before the template is rendered, so {{ detectTime }} renders when the detection happened and values.SourceIp renders the value of the query’s SourceIp column.

If the rendered body looks like HTML it is sent as an HTML email, otherwise it is sent as plain text.

Testing

Two buttons let you check a template without waiting for a real detection.

  • Test Template renders the template against an example detection and shows you the result, including any errors in the template.
  • Send Test Email sends that example detection to the configured recipients, which also proves the SMTP configuration works.

Limiting Notifications

A rule that suddenly matches far more data than expected can send a very large number of emails. The limit settings exist to bound that.

Field Description
Limit Notifications Whether a limit applies.
Maximum Notifications How many notifications may be sent before this one stops.
Resume Notifications After How long to wait before allowing notifications again.

Once Maximum Notifications have been sent the notification switches itself off and nothing further is delivered through it. It comes back on when Resume Notifications After has elapsed since the last notification was sent, at which point the count starts again from zero.

The count is held per notification and is not persisted, so restarting the node resets it.

5 - Detections

What a detection contains, how it is built from the rule’s query, and the XML written to a feed.

A detection is what an Analytic Rule produces. One is raised for each row the rule’s query returns, and it is the detection, rather than the row, that is delivered to the rule’s notifications.

Detections written to a Feed are XML in the detection:1 namespace, so they can be indexed and searched like any other data in Stroom. Detections sent by email are rendered through a template that has access to the same fields.

How a Detection is Built

Most of a detection is filled in for you from the rule and from the run that raised it.

Field Where it comes from
detectTime When the detection was raised.
detectorName The name of the Analytic Rule .
detectorUuid The UUID of the rule document.
detectorVersion The version of the rule document at the time it ran.
detailedDescription The content of the rule’s Documentation tab, see below.
detectionUniqueId A generated UUID , different for every detection.
detectionRevision Always 0 for detections raised by a rule.
executionSchedule The name of the execution schedule that fired, for a scheduled rule.
executionTime The wall clock time at which the rule ran.
effectiveExecutionTime The point in time the run represented.
values One entry per column in the query, see below.
linkedEvents Built from the StreamId and EventId columns, see below.
level The severity declared by the rule, where it declares one, see Settings.
status How reliable the rule declares itself to be, where it declares it, see Settings.

Because detailedDescription comes from the rule’s documentation, what you write there is delivered with the detections the rule raises. It is worth writing it for whoever receives the detection rather than for whoever maintains the rule.

Whether it is included is controlled by Include Rule Documentation on the Settings tab, which applies to every processing type. Where it is unticked, detailedDescription is left empty.

Values

Every column the query selects becomes an entry in values, keyed by the column name. In a feed these appear as <value name="..."> elements, and in an email template they are reachable through the values dictionary.

The two exceptions are StreamId and EventId. Rather than appearing in values, they are used to build a linked event, which records the Stream and Event the detection relates to. A detection whose query selects neither will have no linked events.

Fields a Rule Does Not Set

The detection:1 schema has several fields that an Analytic Rule never populates, because they only make sense for a detector that revises its own findings over time.

Field Purpose
headline A short description of what was detected.
fullDescription A complete description of what was detected.
detectorEnvironment Where the detector was deployed.
defunct Marks earlier revisions of a detection as invalid.

These exist because the same schema is used by detections produced outside Stroom, for example by an XSLT in a translation pipeline or by an external processing framework, which can set them.

Detections as a Data Source

Writing detections to a feed means they can be treated as data in their own right. Once indexed they can be searched from a Dashboard or Query, reported on, and used as the input to further rules.

A rule whose query runs over a feed of detections is a common way of spotting a pattern across detections that no single detection shows on its own.

6 - Duplicate Management

Suppressing detections that repeat something you have already been told.

Some rules will detect the same thing over and over. A rule that runs hourly and looks for a misconfigured device will find that device every hour until someone fixes it, and nobody needs telling twenty four times a day.

Duplicate Management suppresses detections that match ones the rule has already raised. The tab is only shown for Scheduled Query rules.

This is different from limiting notifications, which bounds how many notifications a rule may send regardless of what they say. Duplicate management suppresses repeats while still delivering anything new.

Settings

Field Description
Remember Notifications Store the column values of de-duplicated detections so they can be viewed.
Suppress Duplicate Notifications Suppress detections identical to ones already sent.
Choose Columns Use a chosen set of columns to decide what counts as identical, rather than all of them.
Columns A comma delimited list of column names, used when Choose Columns is set.

The two switches are independent, and the store is used if either of them is set.

Remember Suppress Effect
No No No store is used at all, and every detection is delivered.
No Yes Duplicates are suppressed.
Yes No Every detection is delivered, but what the rule has seen is recorded so it can be viewed.
Yes Yes Duplicates are suppressed, and what the rule has seen can be viewed.

Setting Remember Notifications on its own is a useful way to see what a rule would suppress before committing to suppressing it.

The lower part of the tab lists what the rule has stored, which is how you check why something was or was not suppressed. It also lets you clear the store.

Choosing Columns

Where Choose Columns is not set, the columns used depend on whether the query groups its results.

  • A query with grouped columns uses those grouped columns, and ignores the rest.
  • A query with no grouping uses every column.

Using every column is often too strict, because a column that changes on every run will make every detection unique. A rule whose query selects a timestamp, or a count, or an event id, will never suppress anything unless the columns are narrowed down to the ones that identify the thing being detected.

Choose Columns is how you narrow them. For the misconfigured device example, choosing just the device name means the rule tells you about that device once rather than hourly, however much the other columns change.

Column names are case sensitive and must match the names in the query.

The Duplicate Check Store

Each rule has its own store, held on the processing node and configured by the stroom.analytics.duplicateCheckStore property.

The store is keyed on the rule, so it survives the rule being edited. It is deleted when the rule is deleted.

7 - Streaming Rules

Rules that run against streams as they are processed rather than on a schedule.

A Streaming rule is run by a Processor filter rather than by a schedule. Each Stream that matches the filter is passed through the rule as it is processed, so a detection is raised without waiting for the next scheduled run.

Use this type where the delay imposed by a schedule is unacceptable. For most rules a Scheduled Query is the better choice, because it can look across a window of data rather than at one stream at a time.

Data Source

A streaming rule must query a View , and that View must specify an extraction pipeline.

The View is what makes streaming possible. Its filter determines which streams are selected for processing, and its extraction pipeline determines the fields the rule’s query can use.

A rule whose query names anything other than a View, or whose View has no pipeline, fails when it is processed rather than when it is saved. The error is reported against the rule, so a streaming rule that raises nothing at all is worth checking here first.

Processing

The Execution tab of a streaming rule shows the rule’s processors and filters, in the same form as the Processors tab of a pipeline.

When a filter is created for the rule, its expression is defaulted from the filter on the View the query uses. You can then narrow it further, for example to a subset of feeds or a range of stream creation times.

Because streaming rules use the normal stream processing machinery, they behave like any other processing task.

  • They are picked up by the standard stream processor jobs, not by the Analytic Executor jobs.
  • Their progress can be tracked, and they can be reprocessed, from the Processors screen.
  • Their priority competes with other processing on the node.

Differences from a Scheduled Rule

A streaming rule has no execution schedules, and consequently no execution history, no effective execution time and no catch up behaviour. Relative date expressions in the query resolve against the time of processing.

It also has no Duplicate Management tab, so repeated detections must be controlled by limiting notifications instead.

Streaming rules are the only type that can use Use Source Feed If Possible on a stream notification, which writes each detection to the feed the source data came from rather than to the destination feed, see Stream Destinations.

8 - Table Builder Rules

An experimental processing type that should not be used.

A Table Builder rule builds and maintains its own table of data from the streams it processes, and raises detections from that table. The table is held in shards on the processing node, separately from the rest of Stroom’s data.

The rule’s Shards tab, which is only shown for this processing type, lists those shards and lets you look at what they contain.

Settings

Field Description
Enabled Whether the rule is processed.
Processing Node The node that builds the table.
Min Stream Create Time The earliest stream creation time to process.
Max Stream Create Time The latest stream creation time to process.
Aggregation Period How long to wait for data before processing it.
Time To Keep Data In The Table How long data is retained in the rule’s table.
Processing Info A read only summary of what the rule has processed.