I deployed Grafana on CentOS 7.9 to collect application logs and send email alerts. The current deployment environment cannot directly connect to the internet; it connects to the internet through an HTTP proxy such as 192.168.6.1:8088. How should I configure Grafana so that alert emails can be sent to my Gmail account?
Standard HTTP library in Go reads the environment variables HTTP_PROXY
, HTTPS_PROXY
, and NO_PROXY
. So try to us these env variables - that’s the easiest way. If it is not working, then you can assume that used golang email module ignore these env variables and you should dig in Grafana source code.
Grafana 9.5.19 running on docker does not work.I tried setting environment variables with “–env https_proxy=192.168.1.50:8888” and confirmed their effectiveness using the curl command. However, after experimentation, I found that sending alarms via email does not go through the http_proxy. Even when the proxy is set to an invalid address, the alarms can still be sent.
that env variable name can be case sensitive, try uppercase version
Another option may be proxy configuration on the docker daemon level.
Thank you for your reply. I have tested it again, and make sure Grafana can get the linux proxy settings. I found If you choose to send alerts through TINGTING or Slack, they will be sent via the proxy. However, if you have configured email notifications, the proxy will not be used.
This is a very common scenario where many people need to monitor application logs in intranet and send emails to the internet via a proxy. I have been searching for nearly a week, and it seems that there is no easy way to achieve this.
I would say that makes sense. All tools/contact points, which are using HTTP(s) protocol respect HTTP_PROXY
variable. But email is not going over HTTP protocol - that’s SMTP usually.
So, currently, Grafana does not support sending email alerts through a proxy?The alternative approach is to use webhooks to send the alert request to my own program, which can then utilize a proxy to send the email?
Check the source code and you will find. But there is at least no Grafana config option for that. IMHO that’s not stopping you to solve it outside of Grafana:
- use local SMTP server, which will be “forwarding” emails outside in required way
- some advance networking (e.g. tunnelling, …)
…
Of course solutions outside of Grafana are out of scope Grafana forum.
I would actually say that emails are nearly always sent through a proxy.
Unless you happen to be sending to an address which is handled by the mail
server you send to, that mail server works out how to get the email delivered
for you (ie: it acts as a proxy) and sends it on, either to the destination
server, or sometimes to another proxy, and sooner or later the email arrives
on the machine whose mailbox the recipient is collecting from.
This is simply the way SMTP was designed from the start.
Therefore I belive you can achieve what you want (Grafana alerts to be sent
out via your local network mail relay) simply by setting up something like
SSMTP (yes, two Ss are deliberate there) on your Grafana server.
Antony.