This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MikoPBX module that integrates Zabbix Agent (built from source as v6.0.44) for monitoring Asterisk PBX metrics. Collects active calls, channels, SIP peer/trunk status, uptime, and version info via asterisk[<metric>] UserParameter keys.
- Module ID: ModuleZabbixAgent5
- Namespace:
Modules\ModuleZabbixAgent5 - Min PBX version: 2025.1.1
- PHP: 8.4 with Phalcon 5.x
- License: GPL-3.0-or-later
JS compilation (source → compiled with inline sourcemaps):
/Users/nb/PhpstormProjects/mikopbx/MikoPBXUtils/node_modules/.bin/babel \
public/assets/js/src/module-zabbix-agent5-index.js \
--out-dir public/assets/js \
--source-maps inline \
--presets airbnbPHP quality check — no test suite; use phpstan after PHP changes.
CI (.github/workflows/build.yml): Inherits from mikopbx/.github-workflows shared workflow. Compiles Zabbix Agent 6.0.44 statically for amd64 (Dockerfile.amd64) and arm64 (Dockerfile.arm64, cross-compiled), placing binaries at bin/zabbix_agentd and bin/zabbix_agentd_arm. Build Dockerfiles live in .github/build/zabbix-agent-builder/. Triggers on push to master and develop.
- Web UI → User edits
zabbix_agentd.confin ACE editor (Volt template + JS) - Controller (
saveAction) → savesconfigContenttom_ModuleZabbixAgent5table - Config hook (
modelsEventChangeData) detects DB change → callsZabbixAgent5Main::startService() - Service manager writes config to
/etc/custom_modules/ModuleZabbixAgent5/zabbix_agentd.confand restartszabbix_agentd - Zabbix agent calls
bin/asterisk-stats.sh <function>via UserParameter — shell functions for simple metrics (uptime, version, calls via CLI), delegates tophp -f Lib/AsteriskInfo.php <method>for API-based metrics (SIP peers, trunks, call direction counts) - Cron runs
bin/zabbix-safe-script.shevery 5 min as a health check to restart agent if not running
Lib/ZabbixAgent5Conf.php(extendsConfigClass) — lifecycle hooks: start/stop service on enable/disable, restart on DB change, firewall rules (port 10050), cron task registrationLib/ZabbixAgent5Main.php— core service manager: directory setup, config loading (DB → fallback tobin/zabbix_agentd_default.conf), start/stop viaProcesses::processWorkerLib/AsteriskInfo.php— standalone CLI script (not autoloaded) that collects Asterisk metrics via MikoPBX REST API v3 (/pbxcore/api/v3/pbx-status:getActiveCalls,/pbxcore/api/v3/sip:getStatuses,/pbxcore/api/v3/sip-providers:getStatuses). Invoked asphp -f AsteriskInfo.php <methodName> [args]by shell scriptsLib/MikoPBXVersion.php— Phalcon 5 helper (Di, Validation, Logger class resolution)Setup/PbxExtensionSetup.php— empty, inherits all default install/uninstall behavior
WorkerZabbixAgent5Main.php— Beanstalk message queue listenerWorkerZabbixAgent5AMI.php— Asterisk Manager Interface event listener (filtersInterceptionUserEvent)
Both workers require Globals.php (via require_once) and are started as CLI processes with cli_set_process_title.
- Model:
Models/ModuleZabbixAgent5.php— tablem_ModuleZabbixAgent5, fields:id,configContent(LONGTEXT) - Controller:
App/Controllers/ModuleZabbixAgent5Controller.php—indexActionrenders ACE editor,saveActionhandles POST - Form:
App/Forms/ModuleZabbixAgent5Form.php— two hidden fields (id,configContent) - View:
App/Views/index.volt— Volt template, uses ACE editor withjuliasyntax mode for config highlighting - JS:
public/assets/js/src/module-zabbix-agent5-index.js— initializes ACE editor (monokai theme), hooks into MikoPBXFormobject for save
- Config:
/etc/custom_modules/ModuleZabbixAgent5/zabbix_agentd.conf - Logs:
/storage/usbdisk1/mikopbx/log/ModuleZabbixAgent5/ - PID:
/var/run/custom_modules/ModuleZabbixAgent5/
- PSR-4 autoloading from root:
Modules\ModuleZabbixAgent5\→/ - JS source in
public/assets/js/src/, compiled output inpublic/assets/js/ - 29 translation files in
Messages/— PHP arrays withmodzbx_prefix keys; add translations to all locale files when adding new strings - Shell scripts in
bin/must use busybox-compatible syntax (MikoPBX runs on a minimal Linux — no bash, use/bin/shwith/bin/busyboxcommands) AsteriskInfo.phpis a CLI-invoked script withrequire_once 'Globals.php'— it bootstraps outside the MikoPBX autoloader- Zabbix agent binaries (
bin/zabbix_agentd,bin/zabbix_agentd_arm) are gitignored — built by CI only - Zabbix template UUIDs (
bin/zbx_export_templates.yaml): everyuuid:value MUST be valid UUIDv4 (32 hex chars, no dashes, 13th char =4, 17th char one of8 9 a b). Zabbix server rejects import with "Invalid parameter /1/uuid: UUIDv4 is expected" if any UUID breaks this rule. When adding or editing template items, groups, triggers, graphs, or discovery rules — always generate proper UUIDv4. Verify with:grep 'uuid:' bin/zbx_export_templates.yaml | awk '{print $3}' | while read u; do v="${u:12:1}"; r="${u:16:1}"; if [ "$v" != "4" ]; then echo "BAD: $u"; elif [ "$r" != "8" ] && [ "$r" != "9" ] && [ "$r" != "a" ] && [ "$r" != "b" ]; then echo "BAD: $u"; fi; done