Notifications
This section documents the full capabilities of Notification Templates, and which fields exist to manipulate the template/behavior.
The Conditions and Triggering Notifications section will briefly explain how the condition
field interacts with the Spyderbat data model in order to trigger notifications.
The Dereferencing Values section describes how you can inject values from the json record that triggered the notification into the notification itself.
The Internal Functions section details the various functions you can use to add additional context to your notifications or manipulate existing values into a more desirable format.
Note: The following are advanced concepts. An understanding of them is not required to get started with notifications. Follow the how-to guides to quickly setup commonly-used notifications.
Data Model Primer
Notifications in Spyderbat are driven by the data model. The Spyderbat Nano Agent generates raw telemetry and sends it to the Spyderbat Analytics Engine. The Analytics Engine processes the raw data and builds the behavior web that is viewable in the Console. Additionally, the Analytics Engine analyzes data in the behavior web for security detections, operations issues, policy violations, and more.
The data emitted by the Analytics Engine comes in two flavors: models and events. Notifications are generated by evaluating these two types of records. Models are (potentially) long-lived objects that have a start, middle, and end in their lifecycle. Events represent detections or occurrences that happen at a single point in time.
Take processes as an example. Spyderbat receives process telemetry and builds models to track the state of the processes themselves. What gets emitted from Spyderbat looks like this:
Process Model
The model above is for an interactive bash shell process running on a machine with the Spyderbat Nano Agent installed. It contains all the information required to add it into the behavior web. It also happens that this process is running with an effective user (euser
) "root". That is a privileged account and we have a security detection when we see an interactive shell running as root.
Conditions and Triggering Notifications
Dereferencing Values
In Spyderbat's Notification Templates, you can dynamically include specific values from the JSON objects you are monitoring in the Template fields using dereferencing syntax. The syntax for dereferencing is as follows:
For direct field access:
{{ field_name }}
For subfield access within a dictionary:
{{ parent_field.sub_field }}
Let's consider an example JSON object:
Suppose you have a Saved Query for a Red Flag i.e a security detection on the root bash process above. Events generally have a ref
field that points to the id
of the model they're related to.
Examples of Dereferencing Values from the Object Above:
Example with Email Template:
These examples demonstrate how you can leverage dereferencing to dynamically include specific values from the JSON object in your notifications for more context on alert. Feel free to adjust the examples based on your specific use cases and requirements.
Internal Functions
In Spyderbat's Notification Templates, you can enhance the template alert by using internal functions as well in each Template type. The syntax for using functions is as follows:
{{ __FUNCTION_NAME__ [| ARG1, ARG2, ..., ARGN] }}
Arguments are optional, depending on the function used. The return value of the function will replace the {{ __FUNCTION_NAME__ }}
placeholder, or an error message will be displayed if something goes wrong.
Example JSON object used in function examples:
This metrics record is used to monitor the resource utilization of the Spyderbat Nano Agent.
Functions:
{{ __cluster__ }}
Arguments: This function takes 0 arguments
Description: Returns the name of the cluster the object is associated with or "No Cluster."
Pagerduty Template spec Example:
This would result in a list displayed in the notification:
Cluster: No Cluster
This is because in the metrics object above, the cluster_name field is null.
{{ __hr_time__ }}
Arguments: This function takes 0 arguments
Description: Returns a human-readable version of the time field found in the object.
PagerDuty Template Spec Example:
This would result in a list displayed in the notification:
Time: 2023-12-01 20:02:58UTC
This converts the epoch time 1701460978.1299076 in the time
field in the record above to something human readable.
{{ __linkback__ }}
Arguments: This function takes 0 arguments
Description: Returns a relevant URL linking back to the Spyderbat Console for the object being evaluated.
PagerDuty Template Spec Example:
This would result in a linkback URL being generated, pointing to the Agent Health page for the agent referenced above "ref": "agent:07Ax6uRpB606065sXXXX"
. It would display as a link "View in Spyderbat" at the bottom of your notification.
{{ __origin__ }}
Arguments: This function takes 0 arguments
Description: Returns a string explaining why the notification was generated.
PagerDuty Template Spec Example:
This would result in a message like:
Notification Origin:
This notification was generated because an event_metric record matched the condition specified in notification config "Agent CPU Usage - notif:6voXLIYfRPmTky-XVAaXXX".
{{ __percent__ | number }}
Arguments: This function takes exactly 1 argument
number:
type: String or Number
description: If a String is supplied, the string must be a field in the object with a numerical value.
Description: Multiplies an input number by 100, caps the precision at 2 decimal places, and appends a percent (%) symbol.
PagerDuty Template Spec Example:
This would result in a list displayed in the notification:
CPU Usage: 4.17%
Here’s an all list of the field names along with their actual function:
__hr_time__
– Human-readable timestamp of the event.__time_int__
– Timestamp in integer format.__linkback__
– URL linking back to the event in Spyderbat.__origin__
– The origin or source of the event.__cluster__
– The cluster where the event occurred.__source__
– The source component or entity that generated the event.__hostname__
– The hostname where the event took place.__percent__
– A percentage value associated with the event.__pd_severity__
– Severity level formatted specifically for PagerDuty.__query_name__
– The name of the saved query that triggered the event.
Conclusion: You can use a mix of both Static values from the Object by dereferencing and using Spyderbat's Internal function to enhance templates for direct context on Notification Alert.
Last updated
Was this helpful?