This commit is contained in:
Holger Sielaff
2025-10-01 11:23:44 +02:00
parent 47dd362409
commit c848bd267b
4 changed files with 78 additions and 1 deletions

15
debscripts/control Normal file
View File

@@ -0,0 +1,15 @@
Package: zabbix-php-monitoring
Version: 1.0.0
Section: admin
Priority: optional
Architecture: all
Depends: php8.3-fpm, zabbix-agent, logrotate, jq
Maintainer: System Administrator <admin@localhost>
Description: PHP Exception Monitoring for Zabbix
This package provides comprehensive PHP exception monitoring for Zabbix.
It includes:
- Automatic exception logging via auto_prepend_file
- Zabbix template for monitoring and alerting
- Log rotation configuration
- User permissions for log access and service management
- Deduplication of identical exceptions based on unique identifiers

46
debscripts/postinst Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
set -e
# 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
for cfg in /etc/php/8.3/fpm/pool.d/*.conf; do
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; '
echo -e "\n; Added by php8.3-zabbix-monitor\n${comment}php_admin_value[auto_prepend_file] = /usr/lib/zabbix-php.php" >> $cfg
done
# Restart services to apply configuration
systemctl reload php8.3-fpm.service || true
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

15
debscripts/prerm Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
set -e
# Pre-removal script for zabbix-php-monitoring
echo "Removing zabbix-php-monitoring..."
# Restart PHP-FPM to clear the auto_prepend_file configuration
systemctl reload php8.3-fpm.service || true
# Note: We don't remove the log files as they may contain important data
echo "Log files in /var/log/zabbix/ have been preserved"
echo "Configuration files will be removed"
exit 0

View File

@@ -63,7 +63,7 @@ zabbix_export:
} }
triggers: triggers:
- uuid: 9df96b18c230490a9a0a9e2307226350 - uuid: 9df96b18c230490a9a0a9e2307226350
expression: 'length(last(/PHP Exceptions Monitoring/php.exception.latest)) > 15' expression: 'length(last(/PHP Exceptions Monitoring/php.exception.latest)) > 15 and change(/PHP Exceptions Monitoring/php.exception.latest) <> 0'
name: 'PHP Exception Detected' name: 'PHP Exception Detected'
event_name: 'New PHP Exception Logged' event_name: 'New PHP Exception Logged'
priority: HIGH priority: HIGH
@@ -102,6 +102,7 @@ zabbix_export:
value: application value: application
- tag: component - tag: component
value: php value: php
recovery_mode: NONE
- uuid: 8df96b18c230490a9a0a9e2307226340 - uuid: 8df96b18c230490a9a0a9e2307226340
name: 'PHP Exception Log Size' name: 'PHP Exception Log Size'
type: ZABBIX_PASSIVE type: ZABBIX_PASSIVE