Please enable JS

Create a Zabbix 3 mail script alert.

A while back I've posted a way to create a mail script for Zabbix 2.x to send email alerts. This post explains how to do this for Zabbix 3.x, but using the excellent Postmark email service instead of the local machine itself.

Find out what the alert script directory is by checking /etc/zabbix/zabbix_server.conf and look for the value for the variable "AlertScriptsPath".
Take note of the directory and create a mailscript file in that directory like ie;

sudo nano /usr/lib/zabbix/alertscripts/postmark-mail

Then we'll need to post to the Postmark API using curl and need to pass the proper variables which it gets from Zabbix. (documentation)

The result would look like the example below. (Make sure you use a valid Postmark token in the script.

curl "https://api.postmarkapp.com/email" \
  -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-Postmark-Server-Token: server_token_here" \
  -d "{From: 'a_verified_sender_signature@mydomain.com', To: '$1', Subject: '$2', TextBody: '$3'}"

Make the script executable by:

sudo chmod +x postmark-mail

Next, on the Zabbix interface, navigate to: "media types" and click the button "create media type". Next enter the values as shown below:

You'll understand that the 3 parameters correspond with the variables used in the script we created.

After you created the media type you should add it to the user you'll use for alerting. Let's pick the admin user.

Navigate to 'administration', 'users' and click the admin user. Next, click the 'media' tab and click the 'add' link to add the postmark-mail media type from the 'type' pulldown list. Next enter the email address you would like to send alerts to. Don't forget to click the 'update' button to save your changes.



Interessant

Een interessant onderwerp voorbij zien komen en er meer over te weten komen? Neem contact op.