diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index b6ded87fd..7fa0fd5e4 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -183,8 +183,13 @@ public function countDirectUses() array('n' => 'icinga_notification'), array('cnt' => 'COUNT(*)') )->where('n.command_id = ?', $id); + $qc = $db->select()->from( + ['c' => 'icinga_command_inheritance'], + ['cnt' => 'COUNT(*)'] + )->where('c.parent_command_id = ?', $id); + $query = $db->select()->union( - [$qh, $qs, $qn], + [$qh, $qs, $qn, $qc], DbSelect::SQL_UNION_ALL ); diff --git a/library/Director/Resolver/CommandUsage.php b/library/Director/Resolver/CommandUsage.php index 49fc31b34..3ba3f1b75 100644 --- a/library/Director/Resolver/CommandUsage.php +++ b/library/Director/Resolver/CommandUsage.php @@ -44,6 +44,7 @@ public function getLinks() 'host' => ['check_command', 'event_command'], 'service' => ['check_command', 'event_command'], 'notification' => ['command'], + 'command' => ['command'], ]; $types = [ 'host' => [ @@ -60,6 +61,10 @@ public function getLinks() 'template' => $this->translate('%d Notification Template(s)'), 'apply' => $this->translate('%d Notification Apply Rule(s)'), ], + 'command' => [ + 'object' => $this->translate('%d Commands(s)'), + 'template' => $this->translate('%d Command Templates(s)'), + ], ]; $urlSuffix = [ @@ -93,10 +98,21 @@ protected function fetchFor($table, $rels, $objectTypes) foreach ($objectTypes as $type) { $columns[$type] = "COALESCE(SUM(CASE WHEN object_type = '$type' THEN 1 ELSE 0 END), 0)"; } - $query = $this->db->select()->from("icinga_$table", $columns); - foreach ($rels as $rel) { - $query->orWhere("{$rel}_id = ?", $id); + if ($table === "command") { + $query = $this->db->select()->from(array('c' => 'icinga_' . $table), $columns)->join(array('ici' => 'icinga_command_inheritance'), + 'ici.command_id = c.id', + array()); + + foreach ($rels as $rel) { + $query->orWhere("parent_{$rel}_id = ?", $id); + } + } else { + $query = $this->db->select()->from("icinga_$table", $columns); + + foreach ($rels as $rel) { + $query->orWhere("{$rel}_id = ?", $id); + } } return $this->db->fetchRow($query); diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index 1440ef45a..0e1c75bde 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -474,6 +474,18 @@ protected function eventuallyFilterCommand(ZfQueryBasedTable $table) $command->getAutoincId() ); break; + case 'command': + $table->getQuery() + ->join( + ['ici' => 'icinga_command_inheritance'], + 'ici.command_id = o.id', + [] + )->where( + 'ici.parent_command_id = ?', + $command->getAutoincId() + ); + + break; } }