How to send emails from a custom panel plugin?

Hi.

I created a custom panel plugin (TypeScript + React) that get data from ElasticSearch to monitor our systems. The plugin with custom logic (based on data) shows the state of the systems.
Now I would like to send an email to a SMS gateway (or even to voice gateway). That just means send an email to a specific email address with phone numbers in the subject and a body with a specific format.

As far as I know Grafana can send an email via alerts that are linked with some graph panel and some threshold. I don’t have any of that.

Is there a way to send (trigger via code) an email when my panel logic detects an error/warning? Do I have to write the sending logic (in the panel) myself with some nodeJS lib (without grafana) or is there some other way?

AFAIK there’s no official plugin support for sending emails, so I’m afraid you’d need to implement it yourself.

We were looking for similar functionality for one of our clients to create a feedback panel and utilize alerts to send it via email, Slack, etc.

I would be interested in what you come up with.

Thanks Marcus, it was my suspicion.
Will do that

Mikhail, I plan to use a nodeJS library such as Nodemailer.
I haven’t used it before so I hope it will be a good fit.
Will let you know

2 Likes

@mikhailvolkov

What I end up doing is to make an NodeJS app backend that sends emails using nodemailer lib as this can’t be part of the frontend (Grafana panel).
This nodeJS server runs alongside Grafana on the same virtual machine. I used Express lib to expose an endpoint to Grafana.
So from the custom Grafana panel I just have to send a POST request to
localhost:port/api/sendEmail along with some json data to be used for the subject and body

The dependencies that I used
“@types/express”: “^4.17.13”,
“@types/node”: “^17.0.22”,
“@types/nodemailer”: “^6.4.4”,
“express”: “^4.17.3”,
“nodemailer”: “^6.7.3”,
“ts-node”: “^10.7.0”,
“typescript”: “^4.6.2”

1 Like

@marcusolsson
if I call an API (axios) to send an email (node backend) from the panel (custom plugin code) does that mean that the email will be sent only when the panel is rendered (i.e. when someone has the dashboard open)? I want that an email is sent automatically when some criteria is met (based on grafana data that comes from ElasticSearch).
Is this more suitable for a Grafana backend plugin?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.