ungestyled
This commit is contained in:
@@ -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 <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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -1,112 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<zabbix_export>
|
||||
<version>6.4</version>
|
||||
<date>2025-09-29T00:00:00Z</date>
|
||||
<groups>
|
||||
<group>
|
||||
<uuid>7df96b18c230490a9a0a9e2307226338</uuid>
|
||||
<name>Templates/Applications</name>
|
||||
</group>
|
||||
</groups>
|
||||
<templates>
|
||||
<template>
|
||||
<uuid>c770cff7c4bf49e6b2b0e7a5f3d2c4a1</uuid>
|
||||
<template>Template App PHP Exceptions</template>
|
||||
<name>Template App PHP Exceptions</name>
|
||||
<description>Template for monitoring PHP exceptions with deduplication</description>
|
||||
<groups>
|
||||
<group>
|
||||
<name>Templates/Applications</name>
|
||||
</group>
|
||||
</groups>
|
||||
<items>
|
||||
<item>
|
||||
<uuid>8df96b18c230490a9a0a9e2307226339</uuid>
|
||||
<name>PHP Exception Monitor</name>
|
||||
<type>ZABBIX_ACTIVE</type>
|
||||
<key>log[/var/log/zabbix/php.log]</key>
|
||||
<delay>1s</delay>
|
||||
<history>7d</history>
|
||||
<trends>0</trends>
|
||||
<value_type>LOG</value_type>
|
||||
<description>Monitor PHP exceptions from log file</description>
|
||||
<preprocessing>
|
||||
<step>
|
||||
<type>REGEX</type>
|
||||
<parameters>
|
||||
<parameter>^(.*)$</parameter>
|
||||
<parameter>\1</parameter>
|
||||
</parameters>
|
||||
</step>
|
||||
<step>
|
||||
<type>JAVASCRIPT</type>
|
||||
<parameters>
|
||||
<parameter>// 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;
|
||||
}</parameter>
|
||||
</parameters>
|
||||
</step>
|
||||
</preprocessing>
|
||||
</item>
|
||||
</items>
|
||||
<triggers>
|
||||
<trigger>
|
||||
<uuid>9df96b18c230490a9a0a9e2307226340</uuid>
|
||||
<expression>logeventid(/Template App PHP Exceptions/log[/var/log/zabbix/php.log])</expression>
|
||||
<name>PHP Exception: {ITEM.LASTVALUE}</name>
|
||||
<opdata>{ITEM.LASTVALUE}</opdata>
|
||||
<priority>WARNING</priority>
|
||||
<description>A PHP exception has occurred</description>
|
||||
<type>MULTIPLE</type>
|
||||
<manual_close>YES</manual_close>
|
||||
<correlation_mode>1</correlation_mode>
|
||||
<correlation_tag>php_exception_{ITEM.LASTVALUE.regsub(".*\"unique_id\":\"([^\"]+)\".*", "\1")}</correlation_tag>
|
||||
<dependencies/>
|
||||
</trigger>
|
||||
</triggers>
|
||||
<macros>
|
||||
<macro>
|
||||
<macro>{$PHP.LOG.FILE}</macro>
|
||||
<value>/var/log/zabbix/php.log</value>
|
||||
<description>Path to PHP exception log file</description>
|
||||
</macro>
|
||||
</macros>
|
||||
</template>
|
||||
</templates>
|
||||
<value_maps>
|
||||
<value_map>
|
||||
<uuid>adf96b18c230490a9a0a9e2307226341</uuid>
|
||||
<name>PHP Exception Severity</name>
|
||||
<mappings>
|
||||
<mapping>
|
||||
<value>1</value>
|
||||
<newvalue>Fatal Error</newvalue>
|
||||
</mapping>
|
||||
<mapping>
|
||||
<value>2</value>
|
||||
<newvalue>Warning</newvalue>
|
||||
</mapping>
|
||||
<mapping>
|
||||
<value>3</value>
|
||||
<newvalue>Notice</newvalue>
|
||||
</mapping>
|
||||
</mappings>
|
||||
</value_map>
|
||||
</value_maps>
|
||||
</zabbix_export>
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user