Debian – Zabbix does not run custom alertscript

bashdebianshellzabbix

I'm running Debian 8 and Zabbix 3.2.

I've made a custom alert script, which runs fine when I run in terminal:

/bin/sh /usr/lib/zabbix/alertscripts/send_sms.sh 4483222740 Hello

This send a SMS via Twilio, works fine.

In my zabbix_server.conf I have:

AlertScriptsPath=/usr/lib/zabbix/alertscripts

I've created a custom media type following https://www.zabbix.com/documentation/3.2/manual/config/notifications/media/script

But the script is not being called. I have a general media type for e-mail which are being triggered correctly.

My permissions for the script is:

ls -alh
total 12K
drwxr-xr-x 2 root root 4.0K Mar  9 09:04 .
drwxr-xr-x 4 root root 4.0K Feb  3 13:36 ..
-rwxr--r-- 1 root root  165 Mar  9 09:12 send_sms.sh

I've tried to grep for "send_sms" in the /var/log/ directory to see if any errors occurred. Nothing.

I'm ending my script with

exit 0

How to debug?

Best Answer

a) the permissions you quote, -rwxr--r-- 1 root root 165 Mar 9 09:12 send_sms.sh, only allow to execute the script to the root user (owner of the script). Zabbix daemons normally run as the zabbix user, so that user doesn't have the permission to run the script. As the script it already world readable, changing the permissions to 755 should be acceptable and will allow Zabbix to run the script

b) if your script relies on any environment variables, make sure to set those in the script itself - Zabbix does not source the profile or anything else you might expect to set those variables