Create Email Alert Contact Point
Video Lecture
Description
I want to send email alerts using Grafana, but I need to first create an alert contact point.
In this video, we will create a new contact point for sending email alerts.
You will need an SMTP server. Many corporations will provide an SMTP service for their staff. This same service can be used to send emails from Grafana.
I will show how I've set up my own SMTP server, but you may already have a email service that you can use.
Many corporations will provide an email service for there employees. Example, if your work email is my-name@example.com
, then your email client on your work phone will be configured with some combination of settings that may resemble,
Name | my-name |
my-name@example.com |
|
IMAP | mail.example.com |
SMTP | mail.example.com |
Port | 25 or 465 |
Username | my-name@example.com |
Password | ********** |
In this video, I already have a domain that I purchased from Namecheap. For an extra $1 a month, I can get an email service add-on that I can use to send and receive emails. I will configure Grafana to use this email service.
If you have a corporate email service that you already connect your work mobile phone to, then the set-up process and settings will be very similar. You will be able to use Grafana to send emails using your work email address, or perhaps your network administrator can create an email address more specific for sending alerts from Grafana.
Note
If you don't have any email service that you can use to programmatically send emails from, then you can try installing PostFix on your Grafana server. In recent times though, this option has become much harder to implement since many cloud providers now block outbound SMTP for new users to minimize the possibility of sending spam. I have instructions below on setting up a send-only SMTP server for Grafana.
Next to configure Grafana SMTP settings
sudo nano /etc/grafana/grafana.ini
Find the SMTP specific settings, uncomment and edit.
Below are some sample settings. Your actual settings will depend on the domain name of your SMTP service.
[smtp]
enabled = true
host = mail.example.com:465
user = admin@example.com
password = """your-password-wrapped-in-triple-quotes"""
from_address = admin@example.com
from_name = Grafana
ehlo_identity = example.com
Restart Grafana and check its status.
sudo service grafana-server restart
sudo service grafana-server status
Go back into Grafana and into your new Email notification channel settings, and try to send a test email to yourself.
Set up Send-Only SMTP using PostFix
If you don't have an SMTP server available, you can install a local send only SMTP server on your Grafana server itself.
sudo apt install mailutils
At the prompt, I choose Internet Site
After the installation is finished, I need to configure the Postfix SMTP server.
sudo nano /etc/postfix/main.cf
I edit 2 values at the bottom being,
inet_interfaces = loopback-only
inet_protocols = ipv4
Then restart postfix
sudo service postfix restart
I can test the SMTP server sends emails using
echo "This is the body" | mail -s "This is the subject" -a "FROM:root@your-domain.tld" your@email-address
Sending an email from the command line must work before you continue. "Work", means that you got an email in your inbox.
Next to configure Grafana SMTP settings
sudo nano /etc/grafana/grafana.ini
Find the SMTP specific settings, uncomment and edit
[smtp]
enabled = true
host = localhost:25
skip_verify = true
from_address = admin@[your grafana domain name or ip]
from_name = Grafana
ehlo_identity = [your grafana domain name or ip]
Restart Grafana
sudo service grafana-server restart
Go back into Grafana, into your new Email notification channel settings and try to send a test email.
Check your SPAM folder.
Troubleshooting
If you have trouble sending and receiving emails through Grafana, you can check the Grafana log file.
cat /var/log/grafana/grafana.log | grep email
Note that passwords need to be wrapped in triple quotes if they have the characters #
or ;
If you have set up a local SMTP server using PostFix, then also check my SMTP Troubleshooting page in my Zabbix course at https://sbcode.net/zabbix/setup-smtp/#troubleshooting
Grafana Cloud
If you use your own Grafana Cloud deployment, then an SMTP server will already be configured for your use of receiving alerts from Grafana.
Add your own email address as a recipient, and press the Test button.
While it is important to know the inner details of managing your own Grafana server, it can later be more strategic for your business to outsource the many aspects of it. Visit Grafana Cloud to start the process.
Benefits,
- Upgraded 28-day trial to Grafana Pro (vs. the standard 14-days)
- 3 users
- 10k metrics
- 50GB logs
- 50GB traces
- Automatic updates
- 30 notifications for OnCall
- 14-day retention
Sign up at Grafana Cloud