Skip to content

Documentation

Automatic Lookback on Events

Search previously received events, correlate them with new information, and create alerts from matching events.

CYBERQUEST Data Transformation Service (DTS) scripts can search previously received events. This lets you correlate new information, such as an Indicator of Compromise (IOC), with historical activity and create an alert when matching events are found.

Create alerts

The global Alert object provides two methods for creating alerts.

Alert.create(options): void

Creates an alert from an options object:

/** @type {Record<string, unknown>} */
const eventObject = {
    EventID: 100000,
    LocalTime: moment().format("YYYY-MM-DD HH:mm:ss.SSS")
};

Alert.create({
    template: "template name",
    logs: [eventObject],
    name: "alert name",
    emails: "[email protected], [email protected]",
    description: "alert description",
    secLevel: 8,
    secScore: 80,
    metaData: "additional metadata"
});

options is required and must be a non-null object. Its properties are optional:

PropertyTypeRequiredDefault and behavior
templatestringNoAlert template name. Defaults to "".
logsArray<object>NoEvent objects to associate with the alert. Defaults to an empty array. A non-array value is also treated as an empty array.
namestringNoAlert name. Defaults to "NewAlert" when omitted or when its length is less than three characters.
emailsstring | Array<string>NoA comma-separated string or an array of email addresses. Defaults to no recipients. Invalid addresses are discarded.
descriptionstringNoAlert description. Defaults to "NewAlert description" when omitted or when its length is less than three characters.
secLevelnumberNoA finite security level from 0 through 10, inclusive. Defaults to 0 when omitted, out of range, or not a finite number.
secScorenumberNoA finite security score from 0 through 100, inclusive. Defaults to 0 when omitted, out of range, or not a finite number.
metaDataunknownNoAdditional alert metadata. Defaults to "".

Strings containing email addresses are split on commas. Leading and trailing whitespace is removed from each valid address.

Returns: void.

Alert.createSimple(alert): void

Sends a serialized alert payload directly:

/** @type {Record<string, unknown>} */
const eventObject = {
    EventID: 100000,
    LocalTime: moment().format("YYYY-MM-DD HH:mm:ss.SSS")
};

Alert.createSimple(JSON.stringify({
    logs: [eventObject],
    GeneratedTime: moment().format("YYYY-MM-DD HH:mm:ss.SSS"),
    IsAlert: "1",
    AlertSecurityLevel: 9,
    AlertSecurityScore: 90,
    AlertName: "IOC found in historical events",
    TemplateName: "",
    Description: "A known IOC matched historical activity.",
    Why: "The source or destination IP matched the IOC.",
    Category: "Security",
    SubCategory: "Threat intelligence",
    Tenant: "Tenant-name",
    MitreID: "T1071"
}));

The alert parameter is required and has type string. It must contain the complete serialized alert payload expected by the receiving service. Alert.createSimple forwards the string unchanged; it does not parse or validate it. The example payload uses the following fields:

FieldTypeRequired
logsArray<object>Depends on the receiving service
GeneratedTimestringDepends on the receiving service
IsAlertstringDepends on the receiving service
AlertSecurityLevelnumberDepends on the receiving service
AlertSecurityScorenumberDepends on the receiving service
AlertNamestringDepends on the receiving service
TemplateNamestringDepends on the receiving service
DescriptionstringDepends on the receiving service
WhystringDepends on the receiving service
CategorystringDepends on the receiving service
SubCategorystringDepends on the receiving service
TenantstringDepends on the receiving service
MitreIDstringDepends on the receiving service

These fields illustrate the payload used by this example; the local API does not define their requiredness or default values.

Returns: void.

Use Alert.create for the standard options-based API. Use Alert.createSimple only when you already have the complete serialized alert payload required by the receiving service.

Search historical events

The global Events object provides the following lookback methods:

Events.getCount(query, days = 0); // number | false
Events.getBackLogs(query, days = 0, count = 100); // Array<object> | false

Events.getCount(query, days = 0): number | false

ParameterTypeRequiredDescription
querystringYesElasticsearch query-string expression used to match events.
daysnumberNoFinite number of days to look back. Defaults to 0.

Returns: number containing the number of matching events, or false when days is not a finite number. Unlike getBackLogs, this method does not explicitly reject a negative days value.

Events.getBackLogs(query, days = 0, count = 100): Array<object> | false

ParameterTypeRequiredDescription
querystringYesElasticsearch query-string expression used to match events. It must contain at least two characters.
daysnumberNoFinite, non-negative number of days to look back. Defaults to 0.
countnumberNoFinite maximum number of events to return. Defaults to 100.

Returns: Array<object> containing up to count matching events, ordered by LocalTime in descending order (newest first). Returns false when the query is too short, either numeric argument is not a finite number, or days is negative.

Example: correlate an IOC with historical events

In Rules > DTS Objects, add an object and create a custom script. The following example searches the previous 30 days for events involving either of two IP addresses. It creates an alert when more than two events match:

const query = "SrcIP:192.168.1.1 OR DestIP:192.168.0.1";
const numberOfEvents = Events.getCount(query, 30);

if (numberOfEvents > 2) {
    const matchingEvents = Events.getBackLogs(query, 30, 100);

    Alert.create({
        emails: "[email protected], [email protected]",
        logs: matchingEvents,
        name: "IOC found in historical events",
        description: "Known malicious IP addresses matched historical events.",
        secLevel: 5,
        secScore: 10,
        metaData: "Matched by a DTS threat-intelligence lookback."
    });
}

For instructions on configuring the DTS object, see Create a DTS alert.