As detailed in the Alerts article, alerts are messages that you can set up to inform you about an event. During the process of creating an event definition, you can attach an alert to the event, and you can choose how these alerts will be sent (email, Slack or Discord alert, etc.).
Graylog supports alerts through the following methods:
PagerDuty Alerts (Operations Only)
The following section exclusively pertains to a Graylog Enterprise feature. To learn more about obtaining an Enterprise license, please contact the Graylog Sales team.
The PagerDuty alert allows you to create new incidents in PagerDuty in response to events in your Graylog server. These are the supported configuration options to be defined in the New Notification menu for PagerDuty:
-
Routing Key
Your PagerDuty integration routing key. -
Use a Custom Incident Key
If enabled, an incident key will be generated using the provided Incident Key Prefix. This will prevent PagerDuty from creating multiple incidents for a single event. If not selected, an incident key will NOT be generated, and each event notification will create a new incident in PagerDuty. -
Incident Key Prefix
If a custom incident key is enabled, this will be used as a prefix for the incident key. -
Client Name
The name of the Graylog system that triggered the PagerDuty incident. -
Client URL
The URL for your Graylog web interface. If provided, this will be used to construct links that will be embedded in your PagerDuty incident.
Slack Alerts
Slack allows you to send alerts to your Slack workspace in response to events in your Graylog server. These are the supported configuration options to be defined in the New Notification menu for Slack:
-
Configuration Color
Highlight the custom message with a color you prefer. -
Webhook URL
The unique URL used to send messages to your Slack instance. -
Channel
The channel to which you will send a message or you can select @user or @team to receive the alert. -
Custom Message
The message that will be sent to Slack. The data described above can be used in this template. -
Time Zone for Date/Time Values
Select your preferred time zone used for timestamps in the alert. This selection will default to UTC.
-
Message Backlog Limit (optional)
Limit the number of backlog messages sent as part of the Slack alert. If set to 0, no limit will be enforced. -
User Name (optional)
User name of the sender in Slack. -
Selections (you may choose to enable the following options):
-
Include Title: If enabled, this will include the full event definition title and description in the alert.
-
Notify Channel: If enabled, this will notify all the users in a channel with @channel.
-
Notify Here: If enabled, this will notify only active users in the channel with @here.
-
Link Names: If enabled, this will find and link channel names and user names in the alert.
-
-
Icon URL(optional)
Image to use as the icon for this message. -
Icon Emoji(optional)
Emoji to use as the icon for this message (this overrides any icon URL).
Microsoft Teams Alerts
Microsoft Teams alerts allow you to send messages to a Teams channel when specific events occur in your Graylog setup. This is done via a webhook, which is the same method used for Slack alerts.
These are the supported configuration options to be defined in the New Notification menu for Microsoft Teams:
-
Configuration Color
Highlight the custom message with a color of your choice. -
Webhook URL
This is the unique URL generated while setting up your webhook. Copy the URL that was generated when creating your webhook and paste it into this field. -
Custom Message
This is the message that will be sent to your MS Teams channel. -
Time Zone for Date/Time Values
Select your preferred time zone used for timestamps in the alert. This selection will default to UTC.
-
Message Backlog Limit (optional)
Limit the number of backlog messages sent as part of the MS Teams alert. If set to 0, no limit will be enforced. -
Icon URL
This is an image to use as the icon for this message.
Script Alerts [Operations Only]
The following section exclusively pertains to a Graylog Enterprise feature. To learn more about obtaining an Enterprise license, please contact the Graylog Sales team.
The script alert option lets you configure a script that will be executed when the alert is triggered.
These are the supported configuration options to be defined in the New Notification menu for script alerts:
-
Script Path
The path to where the script is located. Must be within the permitted script path (which is customizable). -
Script Timeout
The maximum time (in milliseconds) the script will be allowed to execute before being forcefully terminated. -
Script Arguments
Space-delimited string of parameters. Any of the data described above can be used. -
Send Alert Data Through STDIN
Sends the JSON encoded data described above through standard in. You can use a JSON parser in your script.
Script Alert success is determined by its exit value; success equals zero. Any non-zero exit value will cause it to fail. Returning any error text through STDERR will also cause the alarm callback to fail.
Here is a sample Python script that shows all supported Script Alert functionality (argument parsing, STDIN JSON parsing, STDOUT, exit values, and returning an exit value).
#!/usr/bin/env python3
import json
import sys
# Function that prints text to standard error
def print_stderr(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# Main function
if __name__ == "__main__":
# Print out all input arguments.
sys.stdout.write("All Arguments Passed In: " + ' '.join(sys.argv[1:]) + "\n")
# Turn stdin.readlines() array into a string
std_in_string = ''.join(sys.stdin.readlines())
# Load JSON
event_data = json.loads(std_in_string)
# Extract some values from the JSON.
sys.stdout.write("Values from JSON: \n")
sys.stdout.write("Event Definition ID: " + event_data["event_definition_id"] + "\n")
sys.stdout.write("Event Definition Title: " + event_data["event_definition_title"] + "\n")
sys.stdout.write("Event Timestamp: " + event_data["event"]["timestamp"] + "\n")
# Extract Message Backlog field from JSON.
sys.stdout.write("\nBacklog:\n")
for message in event_data["backlog"]:
for field in message.keys():
sys.stdout.write("Field: " + field + "\t")
sys.stdout.write("Value: " + str(message[field]) + "\n")
# Write to stderr if desired
# print_stderr("Test return through standard error")
# Return an exit value. Zero is success, non-zero indicates failure.
exit(0)
Email Alerts
Email alerts can be used to send an email to the configured alert receivers when conditions are triggered. Make sure to check the email-related configuration settings in the Graylog configuration file.
Several configuration options are available for the alert to customize the email that will be sent. Note that the email body and email subject are JMTE templates. JMTE is a minimal template engine that supports variables, loops and conditions. See the JMTE documentation for a language reference.
The default body template shows some advanced examples of accessing the available information in the template:
--- [Event Definition] ---------------------------
Title: ${event_definition_title}Description: ${event_definition_description}
Type: ${event_definition_type}
--- [Event] --------------------------------------
Timestamp: ${event.timestamp}
Message: ${event.message}
Source: ${event.source}
Key: ${event.key}
Priority: ${event.priority}
Alert: ${event.alert}
Timestamp Processing: ${event.timestamp}
Timerange Start: ${event.timerange_start}
Timerange End: ${event.timerange_end}
Fields:
${foreach event.fields field}${field.key}: ${field.value}
${end}
${if backlog}
--- [Backlog] ------------------------------------
Last messages accounting for this alert:
${foreach backlog message}
${message}
${end}
${end}
These are the supported configuration options to be defined in the New Notification menu for email alerts:
-
Subject
The subject used for the email alert. As noted above, the email subject is a JMTE template.
-
Reply-To
The email address recipients should reply to if necessary.
-
Sender
The email address that will be used as the sending address. If the field is left empty, the default address will be used.
-
User Recipient(s) (optional)
Select all Graylog users that will receive the alert.
-
Email Recipient(s) (optional)
Add any additional email addresses to receive the alert.
-
Time Zone for Date/Time Values (optional)
You can opt to use a specific time zone for the body of the email.
-
Body Template
This is the template used to generate the email body. As noted above, the email body is a JMTE template.
-
HTML Body Template
This is the template used to generate the email HTML body.
HTTP Alerts
HTTP alerts allow you to configure an endpoint that will be called when the alert is triggered.
Graylog will send a POST request to the alert URL, including information about the alert. The body of the request is the JSON encoded data described above.
Here is an example of the payload included in an alert:
{
"event_definition_id": "this-is-a-test-notification",
"event_definition_type": "test-dummy-v1",
"event_definition_title": "Event Definition Test Title",
"event_definition_description": "Event Definition Test Description",
"job_definition_id": "<unknown>",
"job_trigger_id": "<unknown>",
"event": {
"id": "NotificationTestId",
"event_definition_type": "notification-test-v1",
"event_definition_id": "EventDefinitionTestId",
"origin_context": "urn:graylog:message:es:testIndex_42:b5e53442-12bb-4374-90ed-0deadbeefbaz",
"timestamp": "2020-05-20T11:35:11.117Z",
"timestamp_processing": "2020-05-20T11:35:11.117Z",
"timerange_start": null,
"timerange_end": null,
"streams": [
"000000000000000000000002"
],
"source_streams": [],
"message": "Notification test message triggered from user <admin>",
"source": "000000000000000000000001",
"key_tuple": [
"testkey"
],
"key": "testkey",
"priority": 2,
"alert": true,
"fields": {
"field1": "value1",
"field2": "value2"
}
},
"backlog": []
}
These are the supported configuration options to be defined in the New Notification menu for HTTP alerts:
-
URL
The URL to POST to when an event occurs.
-
Skip TLS Verification (optional)
Select this option to omit performing a TLS certification of the URL.
-
Basic Authentication (optional)
The Basic authentication string needs to follow this format: <username>:<password>.
-
API Key (optional)
Enter an optional API key if preferred. Note that if an API secret is set, an API key must also be set.
-
API Secret (optional)
Enter an optional secret if preferred. Note that if an API secret is set, an API key must also be set.
Legacy Alarm Callback [Operations Only] DEPRECIATED
The following section exclusively pertains to a Graylog Enterprise feature. To learn more about obtaining an Enterprise license, please contact the Graylog Sales team.
Legacy alarm callbacks are being depreciated and are no longer supported in the documentation. If you are currently using legacy alarm callbacks, please migrate to script alerts as soon as possible. You can read more about creating script alerts above.