I am currently creating a module to display special matadata from individual hosts. Basically, this also works with fake data. I skiped this because I was not able to get the daten. Most of it is JS for the frontend. To my luck I am missing a list of hosts that have a specific host.var set. But I seem to be too stupid for PHP and can’t get a host site from either the Monitring module or the Icinga\Data\Db module. Unfortunately I have not managed to debug this either.
Does anyone have a suggestion for an IndexController or a separate Xcontroller that I can use to return this data to the view?
Gladly also with filter or build the SQL myelf.
Hi,
thanks for your fast response. Upload is not needed.
I like to have a application controller like indexController with:
namespace Icinga\Module\myname\Controllers;
use Icinga\Web\Controller;
use this;
use that;
class IndexController extends Controller
{
public function indexAction()
{
$hosts=(QueryHosts from a Backend like IDO or MonitoringModule)
$this->view->hosts = $hosts;
}
}
And a view like index.phtml
<script>
var hosts = <?php echo json_encode($this->hosts); ?>;
</script>
Thanks for your time. At the moment I couldn’t share it, and I don’t know if it would be possible later. I understand you and will try to see if I can make progress myself. The module might grow into a version that someone else can use.
If you want query your onw data from icinagdb, you can use this example.
<?php
namespace Icinga\Module\MyModule\Controllers;
use Icinga\Web\Controller;
use Icinga\Data\Db\DbConnection;
class IndexController extends Controller
{
public function indexAction()
{
$db = DbConnection::fromResourceName('icingadb');
$query = $db->select()
->from(['h' => 'host'], ['host_name' => 'name', 'host_display_name' => 'display_name', ])
->join(array('hv' => 'host_customvar'), 'h.id = hv.host_id', array('host_id' => 'hv.host_id' ))
->join(array('v' => 'customvar'), 'hv.customvar_id = v.id', array('customvar_name' => 'name', 'customvar_value' => 'value'))
->join(array('hs' => 'host_state'), 'hs.host_id = h.id', array('hard_state' => 'hard_state'))
->where('v.name', 'mycustomvar' )
->order('h.name ASC');
$results = $db->fetchAll($query);
echo $results; // or do some other fancy stuff
}
}
This is only an example and returns only one specific custom var of any host when the custom var is set. But this is my usecase… As an alternative you can use hasMany or belongsTo to define relations in the controller, but this is not implemented in my code yet.