Files

54 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2025-10-01 11:23:44 +02:00
#!/bin/bash
2025-10-01 11:32:35 +02:00
# Uhhhhhhhhhhhhhhhh
PHP_VERSION=$(dpkg -l | grep -Pe 'php[0-9.]+-fpm' | awk '{print $2}' | sed 's/php//;s/-fpm//')
PHP_VERSION=${PHP_VERSION-8.3}
2025-10-01 11:23:44 +02:00
set -e
2025-10-01 11:32:35 +02:00
2025-10-01 11:23:44 +02:00
# Post-installation script for zabbix-php-monitoring
# Create log directory with proper permissions
mkdir -p /var/log/zabbix
chown www-data:zabbix /var/log/zabbix
chmod 755 /var/log/zabbix
# Create log file with proper permissions if it doesn't exist
if [ ! -f /var/log/zabbix/php.log ]; then
touch /var/log/zabbix/php.exceptions.log
chown www-data:zabbix /var/log/zabbix/php.exceptions.log
chmod 644 /var/log/zabbix/php.exceptions.log
fi
# Set permissions on sudoers file
chown root:root /etc/sudoers.d/zabbix-php-user
chmod 440 /etc/sudoers.d/zabbix-php-user
# Unset previous empty prepend_file
# sed -i 's/^[[:space:]]*auto_prepend_file[[:space:]]*=[[:space:]]*$/; auto_prepend_file =/' /etc/php/*/fpm/php.ini
2025-10-01 11:32:35 +02:00
for cfg in /etc/php/$PHP_VERSION/fpm/pool.d/*.conf; do
2025-10-01 11:23:44 +02:00
grep -q auto_prepend_file $cfg && continue
read -p "$(echo -e "\e[3;31mZabbix monitor in $cfg einrichten? [\e[1;31mY\e[0m,n]: \e[0m")" ok
comment=''
[[ "$ok" =~ n|N ]] && comment='; Comment out to enable\n; '
2025-10-01 11:32:35 +02:00
echo -e "\n; Added by php$PHP_VERSION-zabbix-monitor\n${comment}php_admin_value[auto_prepend_file] = /usr/lib/zabbix-php.php" >> $cfg
2025-10-01 11:23:44 +02:00
done
# Restart services to apply configuration
2025-10-01 11:32:35 +02:00
systemctl reload php$PHP_VERSION-fpm.service || true
2025-10-01 11:23:44 +02:00
systemctl restart zabbix-agent.service || true
echo "Zabbix PHP monitoring has been installed successfully."
echo "Log file: /var/log/zabbix/php.exceptions.log"
echo "Template file: /usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.yaml"
echo ""
echo "To complete setup:"
echo "1. Import the template into your Zabbix server"
echo "2. Assign the template to your hosts"
echo "3. Configure zabbix_agentd.conf with appropriate log monitoring"
exit 0