mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
parent
431d0cfe75
commit
fca804e74e
@ -47,7 +47,7 @@ class ObjectCommand extends Command
|
|||||||
* --no-defaults Per default JSON output ships null or default
|
* --no-defaults Per default JSON output ships null or default
|
||||||
* values. This flag skips those properties
|
* values. This flag skips those properties
|
||||||
* --with-services For hosts only, also shows attached services
|
* --with-services For hosts only, also shows attached services
|
||||||
* --resolve-services For hosts only, show applied and inherited services
|
* --all-services For hosts only, show applied and inherited services
|
||||||
* too
|
* too
|
||||||
*/
|
*/
|
||||||
public function showAction()
|
public function showAction()
|
||||||
@ -57,16 +57,16 @@ class ObjectCommand extends Command
|
|||||||
$exporter = new Exporter($db);
|
$exporter = new Exporter($db);
|
||||||
$resolve = (bool) $this->params->shift('resolved');
|
$resolve = (bool) $this->params->shift('resolved');
|
||||||
$withServices = (bool) $this->params->get('with-services');
|
$withServices = (bool) $this->params->get('with-services');
|
||||||
$resolveServices = (bool) $this->params->get('resolve-services');
|
$allServices = (bool) $this->params->get('all-services');
|
||||||
if ($withServices) {
|
if ($withServices) {
|
||||||
if (!$object instanceof IcingaHost) {
|
if (!$object instanceof IcingaHost) {
|
||||||
$this->fail('--with-services is available for Hosts only');
|
$this->fail('--with-services is available for Hosts only');
|
||||||
}
|
}
|
||||||
$exporter->enableHostServices();
|
$exporter->enableHostServices();
|
||||||
}
|
}
|
||||||
if ($resolveServices) {
|
if ($allServices) {
|
||||||
if (!$object instanceof IcingaHost) {
|
if (!$object instanceof IcingaHost) {
|
||||||
$this->fail('--resolve-services is available for Hosts only');
|
$this->fail('--all-services is available for Hosts only');
|
||||||
}
|
}
|
||||||
$exporter->resolveHostServices();
|
$exporter->resolveHostServices();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ class Exporter
|
|||||||
protected $fieldReferenceLoader;
|
protected $fieldReferenceLoader;
|
||||||
|
|
||||||
protected $exportHostServices = false;
|
protected $exportHostServices = false;
|
||||||
protected $resolveHostServices = false;
|
protected $fetchAllHostServices = false;
|
||||||
protected $showDefaults = false;
|
protected $showDefaults = false;
|
||||||
protected $showIds = false;
|
protected $showIds = false;
|
||||||
protected $resolveObjects = false;
|
protected $resolveObjects = false;
|
||||||
@ -115,7 +115,7 @@ class Exporter
|
|||||||
|
|
||||||
public function resolveHostServices($enable = true)
|
public function resolveHostServices($enable = true)
|
||||||
{
|
{
|
||||||
$this->resolveHostServices = $enable;
|
$this->fetchAllHostServices = $enable;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +208,8 @@ class Exporter
|
|||||||
{
|
{
|
||||||
$table = (new ObjectsTableService($this->connection))->setHost($host);
|
$table = (new ObjectsTableService($this->connection))->setHost($host);
|
||||||
$services = $this->fetchServicesForTable($table);
|
$services = $this->fetchServicesForTable($table);
|
||||||
if ($this->resolveHostServices) {
|
if ($this->fetchAllHostServices) {
|
||||||
foreach ($this->fetchRelatedServicesForHost($host) as $service) {
|
foreach ($this->fetchAllServicesForHost($host) as $service) {
|
||||||
$services[] = $service;
|
$services[] = $service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ class Exporter
|
|||||||
return $services;
|
return $services;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fetchRelatedServicesForHost(IcingaHost $host)
|
protected function fetchAllServicesForHost(IcingaHost $host)
|
||||||
{
|
{
|
||||||
$services = [];
|
$services = [];
|
||||||
/** @var IcingaHost[] $parents */
|
/** @var IcingaHost[] $parents */
|
||||||
@ -253,12 +253,16 @@ class Exporter
|
|||||||
$services[] = $service;
|
$services[] = $service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
$this->addHostServiceSetTables($host);
|
foreach ($this->getHostServiceSetTables($host) as $service) {
|
||||||
foreach ($parents as $parent) {
|
$services[] = $service;
|
||||||
$this->addHostServiceSetTables($parent, $host);
|
|
||||||
}
|
}
|
||||||
*/
|
foreach ($parents as $parent) {
|
||||||
|
foreach ($this->getHostServiceSetTables($parent, $host) as $service) {
|
||||||
|
$services[] = $service;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$appliedSets = AppliedServiceSetLoader::fetchForHost($host);
|
$appliedSets = AppliedServiceSetLoader::fetchForHost($host);
|
||||||
foreach ($appliedSets as $set) {
|
foreach ($appliedSets as $set) {
|
||||||
$table = IcingaServiceSetServiceTable::load($set)
|
$table = IcingaServiceSetServiceTable::load($set)
|
||||||
@ -277,6 +281,41 @@ class Exporter
|
|||||||
return $services;
|
return $services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates Logic in HostController
|
||||||
|
*
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @param IcingaHost|null $affectedHost
|
||||||
|
* @return IcingaServiceSetServiceTable[]
|
||||||
|
*/
|
||||||
|
protected function getHostServiceSetTables(IcingaHost $host, IcingaHost $affectedHost = null)
|
||||||
|
{
|
||||||
|
$tables = [];
|
||||||
|
$db = $this->connection;
|
||||||
|
if ($affectedHost === null) {
|
||||||
|
$affectedHost = $host;
|
||||||
|
}
|
||||||
|
if ($host->get('id') === null) {
|
||||||
|
return $tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $db->getDbAdapter()->select()
|
||||||
|
->from(['ss' => 'icinga_service_set'], 'ss.*')
|
||||||
|
->join(['hsi' => 'icinga_service_set_inheritance'], 'hsi.parent_service_set_id = ss.id', [])
|
||||||
|
->join(['hs' => 'icinga_service_set'], 'hs.id = hsi.service_set_id', [])
|
||||||
|
->where('hs.host_id = ?', $host->get('id'));
|
||||||
|
|
||||||
|
$sets = IcingaServiceSet::loadAll($db, $query, 'object_name');
|
||||||
|
/** @var IcingaServiceSet $set*/
|
||||||
|
foreach ($sets as $name => $set) {
|
||||||
|
$tables[] = IcingaServiceSetServiceTable::load($set)
|
||||||
|
->setHost($host)
|
||||||
|
->setAffectedHost($affectedHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tables;
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadTemplateName($table, $id)
|
protected function loadTemplateName($table, $id)
|
||||||
{
|
{
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user