2

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?

Michael Nielsen
  • 131
  • 2
  • 9

3 Answers3

3

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

Richlv
  • 2,354
  • 1
  • 13
  • 18
1

Instead of opening up the permissions you could make a sudoers file that allows the zabbix user to run the script. Sudoers syntax is really finicky and if you mess it up it will break sudo completely until you remove the file or line that's incorrect so be careful though.

zabbix ALL=NOPASSWD: /usr/lib/zabbix/alertscripts/send_sms.sh * There needs to be a tab-character between zabbix and ALL, not a space so make sure your editor doesn't substitute this. This site seems to do it so don't just copy and paste that directly.

Drop that line in /etc/sudoers.d/zabbix for example. Do this as root so that you're not locked out if you accidentally break sudo on yourself. You can test the syntax afterwards with visudo -cf /etc/sudoers.d/zabbix.

Edit: Then again, my use case for this is a check related to updates using apt-get which needs root. Twilio probably still works and it's just a matter of getting to read/execute your file.

Okänd
  • 11
  • 2
  • Please note that if root permissions are not needed, using `sudo` can be harmful - now the script runs with elevated privileges when that was not needed. – Richlv Mar 29 '17 at 20:30
-1

i solved this question, not about the permission, write here may help others. Because the zabbix run your script is not in your Alertscript,so you just need add one command: cd $Alertscriptpath (base on your enviroment),it's just work

tooya
  • 1