Your module has to have a dependency to the monitoring module, as this component provides the IDO backend and specific functions to retrieve values from tables there. That's the first thing to know about these things.
Meaning to say, your e.g. ListController could look like this in application/controllers/ListController.php
- use Icinga\Module\Monitoring\Controller;
- class ListController extends Controller
- {
- public function indexAction()
- {
- $this->view->services = $this->backend->select()->from('servicestatus', [
- 'host_name',
- 'service_description',
- ])
- }
- }
Display More
Code is stolen from https://github.com/Icinga/icin…ollers/ListController.php for example, but there are also other modules which do implement such.
You also need to ensure to apply restrictions to these calls, otherwise your module will show all data. Best is to e.g. copy the one's the monitoring module would apply itself. Though your module can provide its own restrictions.
In order to simply test the view, add a new html snippet into application/views/scripts/list/index.phtml
- <div class="content">
- <?php
- if ($services->hasResult()) {
- foreach ($services->peekAhead($compact) as $service) {
- echo "Host: " + $service->host_name + " Service: " + $service->service_description + "<br>":
- }
- }
Stolen from https://github.com/Icinga/icin…ripts/list/services.phtml in an abstracted way.
Did not test the above, but that's how gather data from controllers and put them into views from my experience. Still learning a lot myself.
JoNe
provided a link lately here as well: Einige Fragen zu Modulen/Zend-Syntax im IcingaWeb2