Rule Queries
The Query tab holds the
StroomQl
StroomQl
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.
See Also
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
Searchable
A Searchable is the term given the special searchable data sources that appear at the root of the explorer tree picker when selecting a data source. These data sources are special internal data sources that are not user managed content, unlike an Index. They provide the means to search various aspects of Stroom’s internals, such as the Meta Store or Processor Tasks.Click to see more details... 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.
See Also
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.
Note
effectiveExecutionTime and executionTime.
See Also
Time Windows
A query with a window clause gives a row for each window of time, such as a count for each user for each day.
A rule judges a window only when it has all of the window’s events, so that a window is judged once and is not judged on part of its events.
A Scheduled Query rule judges each window once, in the run whose time range holds the end of the window.
A row that uses lead() is judged in the run whose time range holds the end of the last window it reads.
Where the query gives no end to its time range, the range ends at the effective execution time.
The rule searches back before the start of its time range as far as it needs to, for the start of the first window it judges and for the windows that it reads with lag().
For example, a rule run once a day with windows of a day, a time range from day() - 1d to day() and lag(count(), 1) judges yesterday, and searches the day before as well so that it can compare the two.
Give each run a time range that follows on from the last one, so that every window ends in one of them.
The range does not need to line up with the windows: a range from now() - 1d to now() judges each day in the run after it ends.
The search back applies to the whole query, including any join, so a joined data source is searched over the same longer range.
A limit in the query applies to the windows the rule judges, and not to the windows it searches only for lag().
Note
window clause is the field that the time range of the data source applies to.
With any other field, or with a time range that has no start, every run judges every window that is ready by the effective execution time, and the rule does not search back.
See Also
Columns
The columns your query selects become the content of each detection.
Columns that Stroom adds for its own use, such as the ones behind a having expression or a window, are not added.
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
Event
Warning
Source IP has to be written as values['Source IP'] in a template, whereas SourceIp can be written as values.SourceIp.
See Also
Table Preferences
Some things about a result table cannot be expressed in
StroomQl
StroomQl
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.