How bgmot/zabbix-module-hosts-tree works
Project Type and Purpose
• This is a Zabbix extension module (plugin) written in PHP and JavaScript.
• Its purpose is to integrate with the Zabbix server UI and provide a new “Hosts Tree” view under Monitoring → Hosts Tree.
High-Level Components
a. Zabbix Core
• The host monitoring platform that loads modules via its module API.
b. Module Loader & Manifest
• manifest.json: informs Zabbix about menu items, entry points, permissions.
• Module.php: bootstraps the module, registers hook handlers.
c. Controllers (actions/)
• CControllerBGHost.php: primary controller for host tree data.
• CControllerBGHostView.php: handles initial page render.
• CControllerBGHostViewRefresh.php: AJAX refresh endpoint.
d. Views & Partials
• views/module.monitoring.bghost.view.php: template for main page.
• views/module.monitoring.bghost.view.refresh.php: partial for live updates.
• partials/js/monitoring.host.view.refresh.js.php: JS function to poll/refresh.
• partials/module.monitoring.host.view.html.php: HTML snippet for tree.
e. Static Assets
• CSS: views/css/bghost.css
• JS: views/js/monitoring.host.view.js.php
Interactions and Data Flow
1) User clicks “Hosts Tree” in Zabbix UI → Zabbix invokes Module.php to handle the menu route.
2) Zabbix module loader dispatches to CControllerBGHostView → gathers group/host data via Zabbix API/DB.
3) Controller returns a view template (module.monitoring.bghost.view.php) plus CSS/JS links to browser.
4) Front-end JS (monitoring.host.view.js) runs in user’s browser, draws the tree.
5) Periodically or on demand, JS calls the refresh endpoint (CControllerBGHostViewRefresh) via AJAX → returns updated HTML from partials/js/monitoring.host.view.refresh.js.php.
6) Browser injects updated tree fragment.
Architectural Patterns & Design Principles
• Plugin Architecture: self-contained module loaded by Zabbix at startup.
• MVC-style separation:
• Model: Zabbix API/DB calls within controllers.
• View: PHP templates & partials.
• Controller: action classes.
• Progressive Enhancement: initial full render + AJAX partial refresh.
• Single Responsibility: each controller and partial serves one purpose (render vs. refresh).