The built-in mail option seems to work out of the box, but every post seems to suggest using a script to trigger internal mail binaries for mail notifications. Those require extra dependencies and configuration. With SendGrid and the REST API, it can be simply done with a script using curl. I assume a SendGrid account and key have already been setup.
Creating the script
sudo vim /usr/lib/zabbix/alertscripts/sendgrid.sh
sendgrid.sh
#!/bin/bash SENDGRID_API_KEY="YOURKEYHERE" curl --request POST \ --url "https://api.sendgrid.com/v3/mail/send" \ --header "Authorization: Bearer $SENDGRID_API_KEY" \ --header 'Content-Type: application/json' \ --data "{\"personalizations\": [{\"to\": [{ \"email\": \"$1\"}]}],\"from\": {\"email\": \"[email protected]\"},\"subject\": \"$2\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$3\"}]}"
Notification Testing
There is no way to test aside from triggering an actual fault, so it’s necessary to create a dummy condition and then trigger it with the zabbix_sender utility. I had to explicitly install it:
Install zabbix_sender
sudo apt install zabbix_sender
Create Action and Condition
- Configuration -> Actions -> Create action
- Select condition
- Add new condition (= Dummy trigger)
- Select the Operations tab
- Add new operations (user with custom media type)
- Save by clicking Add
Trigger
zabbix_sender --zabbix-server=127.0.0.1 --host="192.168.0.240" --key="test.timestamp" --value="${VALUE}"
De-trigger
VALUE="$(date --rfc-3339=ns)"; zabbix_sender --zabbix-server=127.0.0.1 --host="192.168.0.240" --key="test.timestamp" --value="${VALUE}"
reference: http://cavaliercoder.com/blog/testing-zabbix-actions.html