See for the official Zabbix site.

Troubleshooting/Userparameters with PHP

Jump to: navigation, search

It has been found that if you have PHP-5.3.3 installed and attempt to use a PHP script as a UserParameter entry that the execution of said script will not complete and the affected zabbix_agentd will eventually time out with no data returned. Using PHP >= 5.4, however, this is no longer an issue - the PHP UserParameter script completes successfully and data is returned.

Verification of this was done in CentOS-6.9 and RHEL-7.3 with Zabbix-3.2 and in Centos-6.9 with Zabbix-2.2.18 and Zabbix-2.4.8. Using strace on the hung zabbix_agentd task, everything comes to a halt at the second "wait4(3215" entry. Terminating the task (ctrl-c) is shown following that entry. If the hung process is allowed to hang without manual termination, the zabbix_agentd task will eventually time out and terminate with no script data returned. If the script in question is a discovery script intended to find a host/client and start data collection, the failed process will prevent the Zabbix server from receiving anything and it will not register the discovered host nor request or obtain any data from it.

Another, perhaps less preferable, alternative to installing PHP >= 5.4 is to install the script under Apache (HTTPD) with its own PHP module, and invoke the UserParameter script using

UserParameter=<key>,curl --raw --silent http://localhost/zabbix-php/<script filename>

were the HTML directory is chosen not to interfere with the normal Zabbix front-end HTML directory. This works just fine with PHP-5.3.3 and where another PHP version cannot be installed this may be a viable option.

Hung agentd process:

alarm(3)                                = 0
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f6ce1aeda90) = 3215
close(4)                                = 0
read(3, 0x7ffc3cf7f210, 4095)           = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_STOPPED, si_pid=3215, si_status=SIGTTOU, si_utime=0, si_stime=0} ---
read(3, 0x7ffc3cf7f210, 4095)           = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
--- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL, si_value={int=22, ptr=0x16}} ---
rt_sigreturn()                          = -1 EINTR (Interrupted system call)
close(3)                                = 0
kill(4294964081, SIGTERM)               = 0
wait4(3215, ^CProcess 3214 detached
 <detached ...>
[root@newzabbix tmp]# zabbix_agentd [3214]: Warning: Got signal [signal:2(SIGINT),sender_pid:0,sender_uid:0,reason:128]. Exiting ...
zabbix_agentd [3214]: Zabbix Agent stopped. Zabbix 2.2.18 (revision 67443).