* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team */ // {{{ICINGA_LICENSE_HEADER}}} use \Icinga\Web\Controller\ActionController; use \Icinga\Module\Monitoring\Backend; use \Icinga\Module\Monitoring\Object\Host; use \Icinga\Module\Monitoring\Object\Service; use \Icinga\Module\Monitoring\Form\Command\MultiCommandFlagForm; use \Icinga\Web\Form; /** * Displays aggregations collections of multiple objects. */ class Monitoring_MultiController extends ActionController { public function init() { $this->view->queries = $this->getDetailQueries(); $this->backend = Backend::createBackend($this->_getParam('backend')); } public function hostAction() { $hosts = array(); $hostnames = array(); $comments = array(); $downtimes = array(); $errors = array(); foreach ($this->view->queries as $index => $query) { if (!array_key_exists('host', $query)) { $errors[] = 'Query ' . $index . ' misses property host.'; continue; } $host = Host::fetch($this->backend, $query['host']); foreach ($host->comments as $comment) { $comments[$comment->comment_id] = null; } if ($host->host_in_downtime) { $downtimes[] += $host->host_in_downtime; } $hostnames[] = $host->host_name; $hosts[] = $host; } $this->view->objects = $this->view->hosts = $hosts; $this->view->comments = array_keys($comments); $this->view->hostnames = $hostnames; $this->view->downtimes = $downtimes; $this->view->errors = $errors; $this->handleConfigurationForm(); $this->view->form->setAction('/icinga2-web/monitoring/multi/host'); } public function serviceAction() { $services = array(); $comments = array(); $downtimes = array(); $errors = array(); foreach ($this->view->queries as $index => $query) { if (!array_key_exists('host', $query)) { $errors[] = 'Query ' . $index . ' misses property host.'; continue; } if (!array_key_exists('service', $query)) { $errors[] = 'Query ' . $index . ' misses property service.'; continue; } $service = Service::fetch($this->backend, $query['host'], $query['service']); foreach ($service->comments as $comment) { $comments[$comment->comment_id] = null; } if ($service->service_in_downtime) { $downtimes[] += $service->service_in_downtime; } $hostnames[] = $service->host_name; $services[] = $service; } $this->view->objects = $this->view->services = $services; $this->view->comments = array_keys($comments); $this->view->downtimes = $downtimes; $this->view->errors = $errors; $this->handleConfigurationForm(); $this->view->form->setAction('/icinga2-web/monitoring/multi/service'); } public function notificationAction() { } public function historyAction() { } /** * Handle the form to configure configuration flags. */ private function handleConfigurationForm() { $this->view->form = $form = new MultiCommandFlagForm( array( 'passive_checks_enabled' => 'Passive Checks', 'active_checks_enabled' => 'Active Checks', 'obsessing' => 'Obsessing', 'notifications_enabled' => 'Notifications', 'event_handler_enabled' => 'Event Handler', 'flap_detection_enabled' => 'Flap Detection' ) ); $form->setRequest($this->_request); if ($form->isSubmittedAndValid()) { // TODO: Handle commands $changed = $form->getChangedValues(); } if ($this->_request->isPost() === false) { $this->view->form->initFromItems($this->view->objects); } } /** * Fetch all requests from the 'detail' parameter. * * @return array An array of request that contain * the filter arguments as properties. */ private function getDetailQueries() { $details = $this->_getAllParams(); $objects = array(); foreach ($details as $property => $values) { if (!is_array($values)) { continue; } foreach ($values as $index => $value) { if (!array_key_exists($index, $objects)) { $objects[$index] = array(); } $objects[$index][$property] = $value; } } return $objects; } }