Skip to content

Commit 699d0d4

Browse files
authored
Add AI coding instructions for Syslog Plugin (#239)
1 parent 82cf8ce commit 699d0d4

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Cacti Syslog Plugin - AI Coding Instructions
2+
3+
## Project Context
4+
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.
5+
- **Language:** PHP (compatible with Cacti's supported versions).
6+
- **Database:** MySQL/MariaDB.
7+
- **Framework:** Cacti Plugin Architecture.
8+
9+
## Architecture & Data Flow
10+
- **Dual Database Support:** The plugin can store data in the main Cacti database OR a dedicated syslog database.
11+
- **Critical:** ALWAYS use the `syslog_db_*` wrapper functions (defined in `database.php`) for all database operations. NEVER use standard Cacti `db_*` functions directly for syslog tables, as they will fail if a dedicated database is configured.
12+
- **Integration:** The plugin integrates with Cacti via hooks defined in `setup.php`.
13+
- **Poller Integration:** Background processes (`syslog_process.php`, `syslog_removal.php`) are triggered by Cacti's poller or run independently.
14+
15+
## Critical Developer Workflows
16+
17+
### Database Interactions
18+
- **Read:** `syslog_db_fetch_assoc($sql)`, `syslog_db_fetch_cell($sql)`
19+
- **Write:** `syslog_db_execute($sql)`, `syslog_db_execute_prepared($sql, $params)`
20+
- **Connection:** Managed via `$syslog_cnn` global.
21+
- **Schema:** Tables are defined/updated in `setup.php` (`syslog_setup_table_new`).
22+
23+
### Cacti Integration Patterns
24+
- **Hooks:** Register hooks in `plugin_syslog_install()` in `setup.php`.
25+
- Example: `api_plugin_register_hook('syslog', 'top_header_tabs', 'syslog_show_tab', 'setup.php');`
26+
- **Permissions:** Register realms in `setup.php`.
27+
- Example: `api_plugin_register_realm('syslog', 'syslog.php', 'Syslog User', 1);`
28+
- **UI:** Follow Cacti's UI patterns (top tabs, breadcrumbs, filter bars).
29+
30+
### Configuration
31+
- **Config File:** `config.php` (derived from `config.php.dist`).
32+
- **Globals:** The plugin relies heavily on global variables:
33+
- `$config`: Cacti configuration.
34+
- `$syslogdb_default`: Name of the syslog database.
35+
- `$syslog_cnn`: Database connection resource.
36+
37+
## Coding Conventions
38+
- **Localization:** Wrap all user-facing strings in `__('string', 'syslog')`. The second argument `'syslog'` is the text domain.
39+
- **Error Handling:** Use `raise_message($id)` or `raise_message('id', 'message', MESSAGE_LEVEL_*)` for UI feedback.
40+
- **Remote Pollers:** Logic for syncing rules to remote pollers is handled in `functions.php` (e.g., `syslog_sync_save`). Check `read_config_option('syslog_remote_enabled')`.
41+
42+
## Clean as You Code
43+
- **Refactoring:** When touching legacy code, modernize it where safe (e.g., replace `array()` with `[]`, improve variable naming).
44+
- **Type Safety:** Add type hints to function arguments and return types where possible, ensuring backward compatibility with supported PHP versions.
45+
- **Cleanup:** Remove unused variables and commented-out code blocks found in the modified sections.
46+
47+
## DBA & Query Optimization
48+
- **Query Analysis:** Always review SQL queries for performance. Suggest indexes if filtering by non-indexed columns.
49+
- **Prepared Statements:** Prefer `syslog_db_execute_prepared` over string concatenation for security and performance.
50+
- **Optimization:** Identify and suggest improvements for N+1 query problems or inefficient joins, especially in poller-related scripts (`syslog_process.php`).
51+
52+
## Key Files
53+
- `setup.php`: Plugin installation, hook registration, and schema updates.
54+
- `database.php`: Database abstraction layer wrappers (`syslog_db_*`).
55+
- `config.php.dist`: Template for database configuration.
56+
- `functions.php`: Core logic and utility functions.
57+
- `syslog.php`: Main UI entry point.

0 commit comments

Comments
 (0)