Being notified about something is important, it lets us know if there is a problem or there is something we need to do. Where you receive these is equally important depending on the notification...
I have to thank a work colleague for the inspiration on this post, cheers Doug.
Version | Update | Date | Notes |
1.0 | Original Post | 9 May 2021 | |
1.2 | Sonarr Updated | 9 May 2021 | I was on an old version |
What is this post looking to do?
Within my home lab environment I've got a lot of services that send me notifications, most of the time this is through an internal mail relay and then into a mail account.
Email however possibly isn't the best place for notifications to end up because they clutter up the inbox at best and at worse get filtered into folders and not read so what's the point of having notifications enabled in the first place.
The usefulness of notifications is a whole other conversation and not one I'm having here, this is more a technical challenge and how I solved it for me.
so this post is about the services I run on my home lab and how I've got the notifications from each going into its own private Discord channel.
Why Discord?
It's a good question, I do host a rocket.chat server and the messages could have equally headed in there as well the same methods I'm going to use below apply to Rocket Chat just as much as Discord.
I'm using Discord daily, I've created a group for this blog server, and I was interested in what it can do and display as a service.

So how is this setup?
Creating Webhook
So, what exactly is a webhook? A webhook (also called a web callback or HTTP push API) is a way for an app to provide other applications with real-time information. A webhook delivers data to other applications as it happens, meaning you get data immediately. Unlike typical APIs where you would need to poll for data very frequently in order to get it real-time. This makes webhooks much more efficient for both provider and consumer. The only drawback to webhooks is the difficulty of initially setting them up.
Webhooks are sometimes referred to as “Reverse APIs,” as they give you what amounts to an API spec, and you must design an API for the webhook to use. The webhook will make an HTTP request to your app (typically a POST), and you will then be charged with interpreting it.
Create a channel
Assuming you have created your Discord server you will need to create a channel, I've chosen to group sets of notifications into different channels to I don't get the same email deluge of traffic

Click on the + next to Text Channels

Create a Private Text Channel, this is one only you'll be able to see so if others are using your Discord instance they are segregated and cannot see your notifications or alerts.
Select Text Channel and give the channel a meaningful name
Make sure Private Channel is Green
Click on Next

You can add other members to view your alerts on this next screen

or Click on Skip
This will setup a Private channel which your chosen alert will go into

Create a Webhook URL
Each channel has its own Webhook and to create it

Click on the cog next to the Channel Name

Click on Integrations then Create Webhook (or New Webhook)

Give the Webhook a name that you can reference later, you could create for security sake a Webhook for each service you want to send data into the discord channel.
For example, below I've created a Channel called nofify_netdata and have an email and a native Webhook.
Click on Copy Webhook URL will provide you something like this
https://discord.com/api/webhooks/829751477471150121/XT7Oe-829TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc
Which can now be used in other services

Notification Examples
These are a few examples of notifications that could go into Discord and some of the fun I had with setting them up.
Please Note
I will use as an example Webhook when I show how each of these is set to send notifications out. Don't use my Webhook,
https://discord.com/api/webhooks/829751477471150121/XT7Oe-829TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc
Generate your own as i've shown above.. I've deleted the channel and this Webhook.

Sonarr

Open Sonarr
Click on Settings and Connect

Click on the big + to add a new Notification service

Select Discord
Note:
If you don't see Discord, you're using an old version of Sonarr, this will still work if you select slack and use the discord Webhook URL and add /slack to the end of it.

Give a name of Discord (can be anything) choose when you want notifications and add any service tags you need.
Add the Webhook URL
https://discord.com/api/webhooks/829751477471150121/XT7Oe-829TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc
Click on test and save..

Discord will display the test Messages

Radarr

Radarr has a similar layout to Sonarr

Click on Settings -> Connect then click on the +

Click on Discord, there is a DiscordNotifier however in this example I'm keeping it simple.

Add the Webhook URL (NO /slack NEEDED) and Name and add tags and triggers for your needs.
Click Save, then Test and again you should see the Notifications in Discord.

Graylog 4

Graylog alerts were the catalyst for this adventure and I had a few issues getting the right format

Open Graylog and click on Alerts and then Notifications
Click on Create Notification

The important thing here is to choose Slack as the Notification type and again use the /slack ending to the Discord Webhook URL
Fill in the other settings as you see fit.

Click on Execute Test Notification when you are ready to test

Discord should display a message in the appropriate channel.
Now when you create Events by clicking on Event Notifications on the top right

When presented with the Notification part of the setup Discord should be available.

AWX

Like Graylog I'm finding having AWX Notifications going into discord really helpful
Login to AWX

Click on Administration -> Notifications
Click on Add

Under type Choose Mattermost

Key here is adding /slack to the end of the Webhook URL
https://discord.com/api/webhooks/829751477471150121/XT7Oe-829TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc/slack
Add a Name and save

Test the connection using the Bell to the right of the Notification entry

To use the notifications

Head to Resources -> Templates and edit a Template
Choose Notifications and Enable accordingly.

Netdata

Netdata has 2 modes standalone and cloud, with the latter it's possible to claim and group your individual nodes within the netdata.cloud login your set up. At the time of writing however the netdata.cloud service only supports email notifications.
However it's possible on each of the installs on the servers to send notifications
Login to a server running netdata as a user able to edit the netdata files and run
/etc/netdata/edit-config health_alarm_notify.conf
This will open the notification conf file
Scroll down to the config section
#------------------------------------------------------------------------------
# discord (discordapp.com) global notification options
# multiple recipients can be given like this:
# "CHANNEL1 CHANNEL2 ..."
# enable/disable sending discord notifications
SEND_DISCORD="YES"
# Create a webhook by following the official documentation -
# https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks
DISCORD_WEBHOOK_URL=""
# if a role's recipients are not configured, a notification will be send to
# this discord channel (empty = do not send a notification for unconfigured
# roles):
DEFAULT_RECIPIENT_DISCORD="notify_discord"
The changes to the section which need to be made are
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/829751477471150121/XT7Oe-829TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc"
Set the recipient to the name of the Discord channel
DEFAULT_RECIPIENT_DISCORD="notify_discord"
Save and Exit
A note (optional)
It's also possible to set this up using Slack as well to pump into Discord
# slack (slack.com) global notification options
# multiple recipients can be given like this:
# "RECIPIENT1 RECIPIENT2 ..."
# enable/disable sending slack notifications
SEND_SLACK="YES"
# Login to your slack.com workspace and create an incoming webhook, using the "Incoming Webhooks" App: https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
# Do not use the instructions in https://api.slack.com/incoming-webhooks#enable_webhooks, as those webhooks work only for a single channel.
# You need only one for all your netdata servers (or you can have one for each of your netdata).
# Without the app and a webhook, netdata cannot send slack notifications.
SLACK_WEBHOOK_URL="https://discord.com/api/webhooks/829751477471150121/XT7Oe-29TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc/slack"
# if a role's recipients are not configured, a notification will be send to:
# - A slack channel (syntax: '#channel' or 'channel')
# - A slack user (syntax: '@user')
# - The channel or user defined in slack for the webhook (syntax: '#')
# empty = do not send a notification for unconfigured roles
DEFAULT_RECIPIENT_SLACK="#"
Note the Webhook has /slack on the end.
SLACK_WEBHOOK_URL="https://discord.com/api/webhooks/829751477471150121/XT7Oe-29TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc/slack"
and the Recipieant set to
DEFAULT_RECIPIENT_SLACK="#"
sends to the webhook channel
Restart Netdata
service netdata restart
service netdata status
To test the Alerts run
/usr/libexec/netdata/plugins.d/alarm-notify.sh test
This will output
# SENDING TEST WARNING ALARM TO ROLE: sysadmin
2021-04-09 09:53:06: alarm-notify.sh: INFO: sent slack notification for: pvexps13 test.chart.test_alarm is WARNING without specifying a channel
2021-04-09 09:53:06: alarm-notify.sh: INFO: sent discord notification for: pvexps13 test.chart.test_alarm is WARNING to 'notify_discord'
2021-04-09 09:53:06: alarm-notify.sh: INFO: sent email notification for: pvexps13 test.chart.test_alarm is WARNING to 'root'
# OK
# SENDING TEST CRITICAL ALARM TO ROLE: sysadmin
2021-04-09 09:53:07: alarm-notify.sh: INFO: sent slack notification for: pvexps13 test.chart.test_alarm is CRITICAL without specifying a channel
2021-04-09 09:53:07: alarm-notify.sh: INFO: sent discord notification for: pvexps13 test.chart.test_alarm is CRITICAL to 'notify_discord'
2021-04-09 09:53:07: alarm-notify.sh: INFO: sent email notification for: pvexps13 test.chart.test_alarm is CRITICAL to 'root'
# OK
# SENDING TEST CLEAR ALARM TO ROLE: sysadmin
2021-04-09 09:53:07: alarm-notify.sh: INFO: sent slack notification for: pvexps13 test.chart.test_alarm is CLEAR without specifying a channel
2021-04-09 09:53:12: alarm-notify.sh: INFO: sent discord notification for: pvexps13 test.chart.test_alarm is CLEAR to 'notify_discord'
2021-04-09 09:53:12: alarm-notify.sh: INFO: sent email notification for: pvexps13 test.chart.test_alarm is CLEAR to 'root'
# OK
In Discord the following will be shown


Gmail

Up until this point, the notifications have been native coming out of systems into Discord. I do get some emails like RedHat Errata which I was thinking about posting as a Discord Alert when I received them.
My first and probably the simplest way of doing this was using zapier.com

with the Trigger for the Email being a Gmail search of
in:inbox from:(errata@redhat.com) newer_than:1d
However, I'm in a bit of a love-hate relationship with Zapier and the costs of it, so I headed over to a self-hosted N8N install (Link about N8N above

My N8N workflow ended up looking like this, which was a Daily Cron Job running
in:inbox from:(errata@redhat.com) newer_than:1d
As a Gmail search and pulling down the full mail
Discord then pulls the mail dates. from fields and a mail snippet into Discord
N8Ns code outputs to JSON formatted code which looks like this.
{
"name": "RH Emails to Discord",
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
450,
130
]
},
{
"parameters": {
"resource": "message",
"operation": "getAll",
"additionalFields": {
"format": "full",
"labelIds": [
"INBOX"
],
"q": "in:inbox from:(errata@redhat.com) newer_than:1d "
}
},
"name": "Gmail",
"type": "n8n-nodes-base.gmail",
"position": [
694,
137
],
"typeVersion": 1,
"credentials": {
"gmailOAuth2": "Google"
}
},
{
"parameters": {
"webhookUri": "https://discord.com/api/webhooks/829751477471150121/XT7Oe-29TERLPKbGtDrTObylTPfeTcTg51CTfO2yk25sWp8HQv5G4SUb8TZRV9sMOmc",
"text": "=Redhat Errata\n{{Object.values($node[\"Gmail\"].json[\"payload\"][\"headers\"][13]).join(', ')}}\n{{$node[\"Gmail\"].json[\"payload\"][\"headers\"][16][\"value\"]}}\n{{$node[\"Gmail\"].json[\"snippet\"]}}"
},
"name": "Discord",
"type": "n8n-nodes-base.discord",
"typeVersion": 1,
"position": [
930,
140
]
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"hour": 7,
"minute": 30
},
{
"hour": 18
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
400,
350
]
}
],
"connections": {
"Gmail": {
"main": [
[
{
"node": "Discord",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Gmail",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"timezone": "Europe/London",
"saveExecutionProgress": "DEFAULT"
},
"id": "1"
}
(Note the formatting will be out, DM me on discord if you'd like a copy of it)
The output of this when run is:

Thoughts
While I appreciate this isn't for everyone, I did find this an interesting exercise in data flow and notification management.