diff --git a/src/DEBIAN/control b/src/DEBIAN/control deleted file mode 100644 index 7e22a8e..0000000 --- a/src/DEBIAN/control +++ /dev/null @@ -1,15 +0,0 @@ -Package: zabbix-php-monitoring -Version: 1.0.0 -Section: admin -Priority: optional -Architecture: all -Depends: php8.3-fpm, zabbix-agent, logrotate -Maintainer: System Administrator -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 \ No newline at end of file diff --git a/src/DEBIAN/postinst b/src/DEBIAN/postinst deleted file mode 100755 index c16693c..0000000 --- a/src/DEBIAN/postinst +++ /dev/null @@ -1,34 +0,0 @@ -#!/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.log - chown www-data:zabbix /var/log/zabbix/php.log - chmod 644 /var/log/zabbix/php.log -fi - -# Set permissions on sudoers file -chmod 440 /etc/sudoers.d/zabbix-php-user - -# 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.log" -echo "Template file: /usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.xml" -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 \ No newline at end of file diff --git a/src/DEBIAN/prerm b/src/DEBIAN/prerm deleted file mode 100755 index 44eaba7..0000000 --- a/src/DEBIAN/prerm +++ /dev/null @@ -1,15 +0,0 @@ -#!/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 \ No newline at end of file diff --git a/src/etc/logrotate.d/zabbix-php b/src/etc/logrotate.d/zabbix-php index f4ae19a..d3c9368 100644 --- a/src/etc/logrotate.d/zabbix-php +++ b/src/etc/logrotate.d/zabbix-php @@ -1,4 +1,4 @@ -/var/log/zabbix/php.log { +/var/log/zabbix/php.exceptions.log { daily missingok rotate 30 @@ -13,4 +13,4 @@ # Signal zabbix-agent to reopen log files /bin/systemctl reload zabbix-agent.service > /dev/null 2>&1 || true endscript -} \ No newline at end of file +} diff --git a/src/etc/php/8.3/fpm/conf.d/99-zabbix-php.conf b/src/etc/php/8.3/fpm/conf.d/99-zabbix-php.conf deleted file mode 100644 index 47e5605..0000000 --- a/src/etc/php/8.3/fpm/conf.d/99-zabbix-php.conf +++ /dev/null @@ -1,11 +0,0 @@ -; Zabbix PHP Exception Monitoring Configuration -; This configuration enables automatic exception logging for Zabbix monitoring - -; Auto-prepend the Zabbix exception handler to all PHP files -auto_prepend_file = /usr/lib/zabbix-php.php - -; Ensure error reporting is enabled -log_errors = On - -; Optional: Set custom error log for debugging (in addition to Zabbix logging) -; error_log = /var/log/php/error.log \ No newline at end of file diff --git a/src/usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.xml b/src/usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.xml deleted file mode 100644 index 15dd1c8..0000000 --- a/src/usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - 6.4 - 2025-09-29T00:00:00Z - - - 7df96b18c230490a9a0a9e2307226338 - Templates/Applications - - - - - - - - adf96b18c230490a9a0a9e2307226341 - PHP Exception Severity - - - 1 - Fatal Error - - - 2 - Warning - - - 3 - Notice - - - - - \ No newline at end of file diff --git a/src/usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.yaml b/src/usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.yaml new file mode 100644 index 0000000..5fc12ae --- /dev/null +++ b/src/usr/share/doc/zabbix-php-monitoring/zabbix_template_php_exceptions.yaml @@ -0,0 +1,121 @@ +zabbix_export: + version: '6.4' + template_groups: + - uuid: 7df96b18c230490a9a0a9e2307226338 + name: 'Templates/Applications' + templates: + - uuid: c770cff7c4bf49e6b2b0e7a5f3d2c4a1 + template: 'PHP Exceptions Monitoring' + name: 'PHP Exceptions Monitoring' + description: 'Template for monitoring PHP exceptions with deduplication via UserParameter' + groups: + - name: 'Templates/Applications' + macros: + - macro: '{$PHP.LOG.FILE}' + value: '/var/log/zabbix/php.exceptions.log' + description: 'Path to PHP exception log file' + items: + - uuid: 8df96b18c230490a9a0a9e2307226339 + name: 'PHP Exception Monitor' + type: ZABBIX_PASSIVE + key: 'php.exception.latest' + delay: 30s + history: 7d + value_type: TEXT + description: 'Monitor PHP exceptions from log file via UserParameter' + preprocessing: + - type: JAVASCRIPT + parameters: + - | + // Parse JSON from UserParameter (already last line) + try { + // Debug: Return original value if empty + if (!value || value === '' || value.trim() === '') { + return 'No exceptions logged yet'; + } + + // Try to parse JSON (UserParameter gives us just the last line) + var entry = JSON.parse(value); + + // Format stacktrace with line numbers + var formattedStack = 'No stacktrace available'; + if (entry.stacktrace && entry.stacktrace.length > 0) { + formattedStack = entry.stacktrace.split('\n').map(function(line, index) { + return (index + 1) + ': ' + line.trim(); + }).join('\n'); + } + + // Return nicely formatted text (not JSON) + return '=== PHP EXCEPTION ===\n' + + 'Message: ' + (entry.message || 'No message') + '\n' + + 'File: ' + (entry.file || 'unknown') + '\n' + + 'Line: ' + (entry.line || 0) + '\n' + + 'Host: ' + (entry.host || 'unknown') + '\n' + + 'Time: ' + (entry.timestamp || 'unknown') + '\n' + + 'ID: ' + (entry.unique_id || 'unknown') + '\n\n' + + '=== STACKTRACE ===\n' + + formattedStack; + + } catch (e) { + // Return error info for debugging + return 'JSON Parse Error: ' + e.message + '\n\nOriginal value:\n' + value; + } + triggers: + - uuid: 9df96b18c230490a9a0a9e2307226350 + expression: 'length(last(/PHP Exceptions Monitoring/php.exception.latest)) > 15' + name: 'PHP Exception Detected' + event_name: 'New PHP Exception Logged' + priority: HIGH + description: | + =============================================== + PHP EXCEPTION DETAILS + =============================================== + + Raw Exception Data: + {ITEM.LASTVALUE} + + =============================================== + STACKTRACE AND FULL DETAILS + =============================================== + + This section contains the complete exception information including: + - Exception message and location + - Full stacktrace with line numbers + - Request context (host, URI, user agent) + - Unique identifier for deduplication + - Timestamp of occurrence + + Click on "Latest Data" for this item to see the formatted JSON. + + Note: This alert requires manual acknowledgment. + manual_close: 'YES' + tags: + - tag: scope + value: application + - tag: component + value: php + - uuid: 8df96b18c230490a9a0a9e2307226340 + name: 'PHP Exception Log Size' + type: ZABBIX_PASSIVE + key: 'php.exception.log.size' + delay: 30s + history: 7d + description: 'Size of PHP exception log file (bytes) - for monitoring purposes' + - uuid: 8df96b18c230490a9a0a9e2307226341 + name: 'PHP Exception Log Accessible' + type: ZABBIX_PASSIVE + key: 'php.exception.log.accessible' + delay: 300s + history: 7d + description: 'Check if PHP exception log is accessible (1=yes, 0=no)' + triggers: + - uuid: 9df96b18c230490a9a0a9e2307226341 + expression: 'last(/PHP Exceptions Monitoring/php.exception.log.accessible) = 0' + name: 'PHP Exception Log Not Accessible' + priority: HIGH + description: 'PHP exception log file is not accessible' + tags: + - tag: scope + value: availability + - tag: component + value: php diff --git a/zabbix_template_php_exceptions.yaml b/zabbix_template_php_exceptions.yaml deleted file mode 100644 index 6348586..0000000 --- a/zabbix_template_php_exceptions.yaml +++ /dev/null @@ -1,68 +0,0 @@ -zabbix_export: - version: '6.4' - template_groups: - - uuid: 7df96b18c230490a9a0a9e2307226338 - name: 'Templates/Applications' - templates: - - uuid: c770cff7c4bf49e6b2b0e7a5f3d2c4a1 - template: 'PHP Exceptions Monitoring' - name: 'PHP Exceptions Monitoring' - description: 'Template for monitoring PHP exceptions with deduplication' - groups: - - name: 'Templates/Applications' - macros: - - macro: '{$PHP.LOG.FILE}' - value: '/var/log/zabbix/php.exceptions.log' - description: 'Path to PHP exception log file' - items: - - uuid: 8df96b18c230490a9a0a9e2307226339 - name: 'PHP Exception Monitor' - type: ZABBIX_PASSIVE - key: 'logrt[/var/log/zabbix/php.exceptions.log]' - delay: 30s - history: 7d - trends: '0' - value_type: LOG - description: 'Monitor PHP exceptions from log file' - triggers: - - uuid: 9df96b18c230490a9a0a9e2307226340 - expression: 'logeventid(/PHP Exceptions Monitoring/logrt[/var/log/zabbix/php.exceptions.log])' - name: 'PHP Exception occurred' - event_name: 'PHP Exception: {ITEM.LASTVALUE}' - priority: WARNING - description: | - A PHP exception has occurred. - Details: {ITEM.LASTVALUE} - manual_close: 'YES' - tags: - - tag: scope - value: application - - tag: component - value: php - preprocessing: - - type: REGEX - parameters: - - '^(.*)$' - - '\1' - - type: JAVASCRIPT - parameters: - - | - // Parse JSON log entry and format for display - try { - var entry = JSON.parse(value); - var formattedStack = entry.stacktrace.split('\n').map(function(line, index) { - return (index + 1) + ': ' + line.trim(); - }).join('\n'); - - return JSON.stringify({ - host: entry.host, - file: entry.file, - line: entry.line, - message: entry.message, - stacktrace: formattedStack, - timestamp: entry.timestamp, - unique_id: entry.unique_id - }); - } catch (e) { - return value; - }