2016-03-18 12:56:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Tables;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Objects\IcingaHost;
|
|
|
|
use Icinga\Module\Director\Web\Table\QuickTable;
|
|
|
|
|
|
|
|
class IcingaHostServiceTable extends QuickTable
|
|
|
|
{
|
2016-06-16 14:50:24 +02:00
|
|
|
protected $title;
|
|
|
|
|
2016-03-18 12:56:57 +01:00
|
|
|
protected $host;
|
|
|
|
|
2016-09-08 13:25:48 +02:00
|
|
|
protected $inheritedBy;
|
|
|
|
|
2016-03-18 12:56:57 +01:00
|
|
|
protected $searchColumns = array(
|
|
|
|
'service',
|
|
|
|
);
|
|
|
|
|
|
|
|
public function getColumns()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'id' => 's.id',
|
|
|
|
'host_id' => 's.host_id',
|
|
|
|
'host' => 'h.object_name',
|
|
|
|
'service' => 's.object_name',
|
|
|
|
'object_type' => 's.object_type',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-16 14:50:24 +02:00
|
|
|
public function setTitle($title)
|
|
|
|
{
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-03-18 12:56:57 +01:00
|
|
|
public function setHost(IcingaHost $host)
|
|
|
|
{
|
|
|
|
$this->host = $host;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:25:48 +02:00
|
|
|
public function setInheritedBy(IcingaHost $host)
|
|
|
|
{
|
|
|
|
$this->inheritedBy = $host;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-03-18 12:56:57 +01:00
|
|
|
protected function getActionUrl($row)
|
|
|
|
{
|
2016-09-08 13:25:48 +02:00
|
|
|
if ($target = $this->inheritedBy) {
|
|
|
|
$params = array(
|
|
|
|
'name' => $target->object_name,
|
|
|
|
'service' => $row->service,
|
|
|
|
'inheritedFrom' => $row->host,
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->url('director/host/inheritedservice', $params);
|
|
|
|
}
|
|
|
|
|
2016-03-18 12:56:57 +01:00
|
|
|
if ($row->object_type === 'apply') {
|
|
|
|
$params['id'] = $row->id;
|
|
|
|
} else {
|
|
|
|
$params = array('name' => $row->service);
|
|
|
|
if ($row->host !== null) {
|
|
|
|
$params['host'] = $row->host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->url('director/service', $params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitles()
|
|
|
|
{
|
|
|
|
$view = $this->view();
|
|
|
|
return array(
|
2016-06-16 14:50:24 +02:00
|
|
|
'service' => $this->title ?: $view->translate('Servicename'),
|
2016-03-18 12:56:57 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUnfilteredQuery()
|
|
|
|
{
|
|
|
|
$db = $this->connection()->getConnection();
|
|
|
|
$query = $db->select()->from(
|
|
|
|
array('s' => 'icinga_service'),
|
|
|
|
array()
|
|
|
|
)->joinLeft(
|
|
|
|
array('h' => 'icinga_host'),
|
|
|
|
'h.id = s.host_id',
|
|
|
|
array()
|
|
|
|
);
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBaseQuery()
|
|
|
|
{
|
|
|
|
return $this->getUnfilteredQuery()->where(
|
|
|
|
's.host_id = ?',
|
|
|
|
$this->host->id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|