This is the Syslog Plugin for Cacti, a PHP-based network monitoring and graphing tool. It collects, stores, and analyzes syslog messages from network devices.
- Language: PHP (compatible with Cacti's supported versions).
- Database: MySQL/MariaDB.
- Framework: Cacti Plugin Architecture.
- Dual Database Support: The plugin can store data in the main Cacti database OR a dedicated syslog database.
- Critical: ALWAYS use the
syslog_db_*wrapper functions (defined indatabase.php) for all database operations. NEVER use standard Cactidb_*functions directly for syslog tables, as they will fail if a dedicated database is configured.
- Critical: ALWAYS use the
- Integration: The plugin integrates with Cacti via hooks defined in
setup.php. - Poller Integration: Background processes (
syslog_process.php,syslog_removal.php) are triggered by Cacti's poller or run independently. - Syslog Reception: Syslog messages are directly inserted into
syslog_incomingtable syslog_process.php then processes them.
- Read:
syslog_db_fetch_assoc($sql),syslog_db_fetch_cell($sql) - Write:
syslog_db_execute($sql),syslog_db_execute_prepared($sql, $params) - Connection: Managed via
$syslog_cnnglobal. - Schema: Tables are defined/updated in
setup.php(syslog_setup_table_new).
- Hooks: Register hooks in
plugin_syslog_install()insetup.php.- Example:
api_plugin_register_hook('syslog', 'top_header_tabs', 'syslog_show_tab', 'setup.php');
- Example:
- Permissions: Register realms in
setup.php.- Example:
api_plugin_register_realm('syslog', 'syslog.php', 'Syslog User', 1);
- Example:
- UI: Follow Cacti's UI patterns (top tabs, breadcrumbs, filter bars).
- Config File:
config.php(derived fromconfig.php.dist). - Globals: The plugin relies heavily on global variables:
$config: Cacti configuration.$syslogdb_default: Name of the syslog database.$syslog_cnn: Database connection resource.
- Localization: Wrap all user-facing strings in
__('string', 'syslog'). The second argument'syslog'is the text domain. - Error Handling: Use
raise_message($id)orraise_message('id', 'message', MESSAGE_LEVEL_*)for UI feedback. - Remote Pollers: Logic for syncing rules to remote pollers is handled in
functions.php(e.g.,syslog_sync_save). Checkread_config_option('syslog_remote_enabled').
- Refactoring: When touching legacy code, modernize it where safe (e.g., replace
array()with[], improve variable naming). - Type Safety: Add type hints to function arguments and return types where possible, ensuring backward compatibility with supported PHP versions.
- Cleanup: Remove unused variables and commented-out code blocks found in the modified sections.
- Query Analysis: Always review SQL queries for performance. Suggest indexes if filtering by non-indexed columns.
- Prepared Statements: Prefer
syslog_db_execute_preparedover string concatenation for security and performance. - Optimization: Identify and suggest improvements for N+1 query problems or inefficient joins, especially in poller-related scripts (
syslog_process.php).
setup.php: Plugin installation, hook registration, and schema updates.database.php: Database abstraction layer wrappers (syslog_db_*).config.php.dist: Template for database configuration.functions.php: Core logic and utility functions.syslog.php: Main UI entry point.
Documentation & Resources