mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
Add views and behaviour to MultiController
Add views for every possible action, fix some bugs in the JavaScript multi selection, make selection hrefs in the list controllers unique to be able to handle the selection properly refs #3788
This commit is contained in:
parent
b911e8c56b
commit
8c416a51ce
@ -228,7 +228,8 @@ class Monitoring_ListController extends MonitoringController
|
||||
'notification_start_time',
|
||||
'notification_contact',
|
||||
'notification_information',
|
||||
'notification_command'
|
||||
'notification_command',
|
||||
'notification_internal_id'
|
||||
)
|
||||
)->getQuery();
|
||||
$this->view->notifications = $query->paginate();
|
||||
|
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* Icinga 2 Web - Head for multiple monitoring frontends
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use \Icinga\Module\Monitoring\Command\Meta;
|
||||
|
||||
/**
|
||||
* Class MonitoringCommands
|
||||
*
|
||||
* Helper which produces a list of command buttons
|
||||
* depending on object states
|
||||
*/
|
||||
class Zend_View_Helper_MonitoringCommands extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Fetch all monitoring commands that are currently available for *all*
|
||||
* given objects and render a html string that contains buttons to execute
|
||||
* these commands.
|
||||
*
|
||||
* NOTE: This means that if you give multiple commands, the commands that
|
||||
* are not available on every single host, will be left out.
|
||||
*
|
||||
* @param array|stdClass $object host or service object or something other
|
||||
* @param string $type small or full
|
||||
*
|
||||
* @return string The rendered html
|
||||
*/
|
||||
public function monitoringCommands($object, $type)
|
||||
{
|
||||
$commands = new Meta();
|
||||
$definitions = $commands->getCommandForObject($object, $type);
|
||||
$out = '<div>';
|
||||
$i = 0;
|
||||
|
||||
foreach ($definitions as $definition) {
|
||||
|
||||
if ($i % 5 === 0) {
|
||||
$out .= '</div><div class="command-section pull-left">';
|
||||
}
|
||||
|
||||
if ($type === Meta::TYPE_FULL) {
|
||||
$out .= '<div>';
|
||||
}
|
||||
|
||||
$out .= sprintf(
|
||||
'<button type="button" data-target="command"'
|
||||
. ' data-command-id="%1$s" class="btn %5$s"'
|
||||
. ' title="%3$s">'
|
||||
. '<i class="%4$s"></i> %2$s'
|
||||
. '</button>',
|
||||
$definition->id,
|
||||
$definition->shortDescription,
|
||||
$definition->longDescription,
|
||||
$definition->iconCls,
|
||||
($definition->btnCls) ? $definition->btnCls : 'btn-default'
|
||||
);
|
||||
|
||||
if ($type === Meta::TYPE_FULL) {
|
||||
$out .= '</div>';
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$out .= '</div>';
|
||||
|
||||
$out .= '<div class="clearfix"></div>';
|
||||
|
||||
if ($type === Meta::TYPE_FULL) {
|
||||
return '<div>'. $out. '</div>';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
@ -28,7 +28,9 @@
|
||||
// {{{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;
|
||||
/**
|
||||
* Displays aggregations collections of multiple objects.
|
||||
*/
|
||||
@ -36,31 +38,78 @@ class Monitoring_MultiController extends ActionController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->view->objects = $this->getDetailQueries();
|
||||
$this->view->queries = $this->getDetailQueries();
|
||||
$this->backend = Backend::createBackend($this->_getParam('backend'));
|
||||
}
|
||||
|
||||
public function hostAction()
|
||||
{
|
||||
$this->view->hosts = $this->_getAllParams();
|
||||
$hosts = array();
|
||||
$warnings = array();
|
||||
|
||||
foreach ($this->view->queries as $index => $query) {
|
||||
if (array_key_exists('host', $query)) {
|
||||
$host = Host::fetch($this->backend, $query['host']);
|
||||
$host->prefetch();
|
||||
$hosts[] = $host;
|
||||
} else {
|
||||
$warnings[] = 'Query ' . $index . ' misses property host.';
|
||||
}
|
||||
}
|
||||
$this->view->commands = array(
|
||||
'host' => array(
|
||||
),
|
||||
'service' => array(
|
||||
|
||||
),
|
||||
'notification' => array(
|
||||
|
||||
),
|
||||
''
|
||||
);
|
||||
|
||||
$this->view->objects = $this->view->hosts = $hosts;
|
||||
$this->view->warnings = $warnings;
|
||||
}
|
||||
|
||||
public function servicesAction()
|
||||
public function serviceAction()
|
||||
{
|
||||
$services = array();
|
||||
$warnings = array();
|
||||
|
||||
foreach ($this->view->queries as $index => $query) {
|
||||
if (!array_key_exists('host', $query)) {
|
||||
$warnings[] = 'Query ' . $index . ' misses property host.';
|
||||
continue;
|
||||
}
|
||||
if (!array_key_exists('service', $query)) {
|
||||
$warnings[] = 'Query ' . $index . ' misses property service.';
|
||||
continue;
|
||||
}
|
||||
$service = Service::fetch($this->backend, $query['host'], $query['service']);
|
||||
$service->prefetch();
|
||||
$services[] = $service;
|
||||
}
|
||||
|
||||
$this->view->objects = $this->view->services = $services;
|
||||
$this->view->warnings = $warnings;
|
||||
}
|
||||
|
||||
public function notificationsAction()
|
||||
public function notificationAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function historyAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all queries from the 'detail' parameter and prepare
|
||||
* them for further processing.
|
||||
* Fetch all requests from the 'detail' parameter.
|
||||
*
|
||||
* @return array An array containing all requests and their filter values.
|
||||
* @return array An array of request that contain
|
||||
* the filter arguments as properties.
|
||||
*/
|
||||
private function getDetailQueries()
|
||||
{
|
||||
@ -79,4 +128,6 @@ class Monitoring_MultiController extends ActionController
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
234
modules/monitoring/application/views/helpers/CommandButton.php
Normal file
234
modules/monitoring/application/views/helpers/CommandButton.php
Normal file
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
/**
|
||||
* Class Zend_View_Helper_CommandButton
|
||||
*/
|
||||
class Zend_View_Helper_CommandButton extends Zend_View_Helper_Abstracts {
|
||||
|
||||
/**
|
||||
* Available command buttons.
|
||||
*/
|
||||
const CMD_DISABLE_ACTIVE_CHECKS = 1;
|
||||
const CMD_ENABLE_ACTIVE_CHECKS = 2;
|
||||
const CMD_RESCHEDULE_NEXT_CHECK = 3;
|
||||
const CMD_SUBMIT_PASSIVE_CHECK_RESULT = 4;
|
||||
const CMD_STOP_OBSESSING = 5;
|
||||
const CMD_START_OBSESSING = 6;
|
||||
const CMD_STOP_ACCEPTING_PASSIVE_CHECKS = 7;
|
||||
const CMD_START_ACCEPTING_PASSIVE_CHECKS = 8;
|
||||
const CMD_DISABLE_NOTIFICATIONS = 9;
|
||||
const CMD_ENABLE_NOTIFICATIONS = 10;
|
||||
const CMD_SEND_CUSTOM_NOTIFICATION = 11;
|
||||
const CMD_SCHEDULE_DOWNTIME = 12;
|
||||
const CMD_SCHEDULE_DOWNTIMES_TO_ALL = 13;
|
||||
const CMD_REMOVE_DOWNTIMES_FROM_ALL = 14;
|
||||
const CMD_DISABLE_NOTIFICATIONS_FOR_ALL = 15;
|
||||
const CMD_ENABLE_NOTIFICATIONS_FOR_ALL = 16;
|
||||
const CMD_RESCHEDULE_NEXT_CHECK_TO_ALL = 17;
|
||||
const CMD_DISABLE_ACTIVE_CHECKS_FOR_ALL = 18;
|
||||
const CMD_ENABLE_ACTIVE_CHECKS_FOR_ALL = 19;
|
||||
const CMD_DISABLE_EVENT_HANDLER = 20;
|
||||
const CMD_ENABLE_EVENT_HANDLER = 21;
|
||||
const CMD_DISABLE_FLAP_DETECTION = 22;
|
||||
const CMD_ENABLE_FLAP_DETECTION = 23;
|
||||
const CMD_ADD_COMMENT = 24;
|
||||
const CMD_RESET_ATTRIBUTES = 25;
|
||||
const CMD_ACKNOWLEDGE_PROBLEM = 26;
|
||||
const CMD_REMOVE_ACKNOWLEDGEMENT = 27;
|
||||
const CMD_DELAY_NOTIFICATION = 28;
|
||||
const CMD_REMOVE_DOWNTIME = 29;
|
||||
|
||||
/**
|
||||
* Information about interface commands
|
||||
*
|
||||
* With following structure
|
||||
* <pre>
|
||||
* array(
|
||||
* self::CMD_CONSTANT_* => array(
|
||||
* '<LONG DESCRIPTION WHERE %s is the type, e.g. host or service>',
|
||||
* '<SHORT DESCRIPTION WHERE %s is the type, e.g. host or service>',
|
||||
* '[ICON CSS CLASS]',
|
||||
* '[BUTTON CSS CLASS]',
|
||||
*
|
||||
* // Maybe any other options later on
|
||||
* )
|
||||
* )
|
||||
* </pre>
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $commandInformation = array(
|
||||
self::CMD_DISABLE_ACTIVE_CHECKS => array(
|
||||
'Disable Active Checks For This %s', // Long description (mandatory)
|
||||
'Disable Active Checks', // Short description (mandatory)
|
||||
'', // Icon anything (optional)
|
||||
'' // Button css cls (optional)
|
||||
),
|
||||
self::CMD_ENABLE_ACTIVE_CHECKS => array(
|
||||
'Enable Active Checks For This %s',
|
||||
'Enable Active Checks',
|
||||
''
|
||||
),
|
||||
self::CMD_RESCHEDULE_NEXT_CHECK => array(
|
||||
'Reschedule Next Service Check',
|
||||
'Recheck',
|
||||
'',
|
||||
'btn-success'
|
||||
),
|
||||
self::CMD_SUBMIT_PASSIVE_CHECK_RESULT => array(
|
||||
'Submit Passive Check Result',
|
||||
'Submit Check Result',
|
||||
''
|
||||
),
|
||||
self::CMD_STOP_OBSESSING => array(
|
||||
'Stop Obsessing Over This %s',
|
||||
'Stop Obsessing',
|
||||
''
|
||||
),
|
||||
self::CMD_START_OBSESSING => array(
|
||||
'Start Obsessing Over This %s',
|
||||
'Start Obsessing',
|
||||
''
|
||||
),
|
||||
self::CMD_STOP_ACCEPTING_PASSIVE_CHECKS => array(
|
||||
'Stop Accepting Passive Checks For This %s',
|
||||
'Stop Passive Checks',
|
||||
''
|
||||
),
|
||||
self::CMD_START_ACCEPTING_PASSIVE_CHECKS => array(
|
||||
'Start Accepting Passive Checks For This %s',
|
||||
'Start Passive Checks',
|
||||
''
|
||||
),
|
||||
self::CMD_DISABLE_NOTIFICATIONS => array(
|
||||
'Disable Notifications For This %s',
|
||||
'Disable Notifications',
|
||||
''
|
||||
),
|
||||
self::CMD_ENABLE_NOTIFICATIONS => array(
|
||||
'Enable Notifications For This %s',
|
||||
'Enable Notifications',
|
||||
''
|
||||
),
|
||||
self::CMD_SEND_CUSTOM_NOTIFICATION => array(
|
||||
'Send Custom %s Notification',
|
||||
'Send Notification',
|
||||
''
|
||||
),
|
||||
self::CMD_SCHEDULE_DOWNTIME => array(
|
||||
'Schedule Downtime For This %s',
|
||||
'Schedule Downtime',
|
||||
''
|
||||
),
|
||||
self::CMD_SCHEDULE_DOWNTIMES_TO_ALL => array(
|
||||
'Schedule Downtime For This %s And All Services',
|
||||
'Schedule Services Downtime',
|
||||
''
|
||||
),
|
||||
self::CMD_REMOVE_DOWNTIMES_FROM_ALL => array(
|
||||
'Remove Downtime(s) For This %s And All Services',
|
||||
'Remove Downtime(s)',
|
||||
''
|
||||
),
|
||||
self::CMD_DISABLE_NOTIFICATIONS_FOR_ALL => array(
|
||||
'Disable Notification For All Service On This %s',
|
||||
'Disable Service Notifications',
|
||||
''
|
||||
),
|
||||
self::CMD_ENABLE_NOTIFICATIONS_FOR_ALL => array(
|
||||
'Enable Notification For All Service On This %s',
|
||||
'Enable Service Notifications',
|
||||
''
|
||||
),
|
||||
self::CMD_RESCHEDULE_NEXT_CHECK_TO_ALL => array(
|
||||
'Schedule a Check Of All Service On This %s',
|
||||
'Recheck All Services',
|
||||
'',
|
||||
'btn-success'
|
||||
),
|
||||
self::CMD_DISABLE_ACTIVE_CHECKS_FOR_ALL => array(
|
||||
'Disable Checks For All Services On This %s',
|
||||
'Disable Service Checks',
|
||||
''
|
||||
),
|
||||
self::CMD_ENABLE_ACTIVE_CHECKS_FOR_ALL => array(
|
||||
'Enable Checks For All Services On This %s',
|
||||
'Enable Service Checks',
|
||||
''
|
||||
),
|
||||
self::CMD_DISABLE_EVENT_HANDLER => array(
|
||||
'Disable Event Handler For This %s',
|
||||
'Disable Event Handler',
|
||||
''
|
||||
),
|
||||
self::CMD_ENABLE_EVENT_HANDLER => array(
|
||||
'Enable Event Handler For This %s',
|
||||
'Enable Event Handler',
|
||||
''
|
||||
),
|
||||
self::CMD_DISABLE_FLAP_DETECTION => array(
|
||||
'Disable Flap Detection For This %s',
|
||||
'Disable Flap Detection',
|
||||
''
|
||||
),
|
||||
self::CMD_ENABLE_FLAP_DETECTION => array(
|
||||
'Enable Flap Detection For This %s',
|
||||
'Enable Flap Detection',
|
||||
''
|
||||
),
|
||||
self::CMD_ADD_COMMENT => array(
|
||||
'Add New %s Comment',
|
||||
'Add Comment',
|
||||
''
|
||||
),
|
||||
self::CMD_RESET_ATTRIBUTES => array(
|
||||
'Reset Modified Attributes',
|
||||
'Reset Attributes',
|
||||
'',
|
||||
'btn-danger'
|
||||
),
|
||||
self::CMD_ACKNOWLEDGE_PROBLEM => array(
|
||||
'Acknowledge %s Problem',
|
||||
'Acknowledge',
|
||||
'',
|
||||
'btn-warning'
|
||||
),
|
||||
self::CMD_REMOVE_ACKNOWLEDGEMENT => array(
|
||||
'Remove %s Acknowledgement',
|
||||
'Remove Acknowledgement',
|
||||
'',
|
||||
'btn-warning'
|
||||
),
|
||||
self::CMD_DELAY_NOTIFICATION => array(
|
||||
'Delay Next %s Notification',
|
||||
'Delay Notification',
|
||||
''
|
||||
),
|
||||
);
|
||||
}
|
@ -34,11 +34,19 @@ use \Icinga\Module\Monitoring\Command\Meta;
|
||||
class Zend_View_Helper_MonitoringCommands extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* @param stdClass $object host or service object or something other
|
||||
* @param string $type small or full
|
||||
* @return string html output
|
||||
* Fetch all monitoring commands that are currently available for *all*
|
||||
* given objects and render a html string that contains buttons to execute
|
||||
* these commands.
|
||||
*
|
||||
* NOTE: This means that if you give multiple commands, the commands that
|
||||
* are not available on every single host, will be left out.
|
||||
*
|
||||
* @param array|stdClass $object host or service object or something other
|
||||
* @param string $type small or full
|
||||
*
|
||||
* @return string The rendered html
|
||||
*/
|
||||
public function monitoringCommands(\stdClass $object, $type)
|
||||
public function monitoringCommands($object, $type)
|
||||
{
|
||||
$commands = new Meta();
|
||||
$definitions = $commands->getCommandForObject($object, $type);
|
||||
|
@ -27,7 +27,8 @@
|
||||
} else {
|
||||
$detailLink = $this->href('monitoring/show/host', array(
|
||||
'host' => $notification->host_name,
|
||||
'service' => $notification->service_description
|
||||
'service' => $notification->service_description,
|
||||
'notification_id' => $notification->notification_internal_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<?php
|
@ -1,7 +1,8 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<span>Summary for <?= count($objects) ?> object(s) </span>
|
||||
<span>Execute commands for all <?= count($objects) ?> object(s) </span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?= $this->monitoringCommands($objects, \Icinga\Module\Monitoring\Command\Meta::TYPE_FULL); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -0,0 +1,12 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{{HOST_ICON}} <h1>Selected <?= count($objects) ?> hosts </h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php foreach($objects as $host) { ?>
|
||||
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $this->render('multi/components/summary.phtml') ?>
|
@ -1 +1,21 @@
|
||||
<?= $this->render('multi/components/summary.phtml'); ?>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{{HOST_ICON}} <h1>Selected <?= count($objects) ?> hosts </h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul>
|
||||
<?php foreach($this->hosts as $host) { ?>
|
||||
<li>
|
||||
<a href="<?= $this->href(
|
||||
'monitoring/show/host',
|
||||
array('host' => $host->host_name)
|
||||
);?>">
|
||||
<?= $host->host_name ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $this->render('multi/components/summary.phtml') ?>
|
||||
|
@ -0,0 +1,22 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{{SERVICE_ICON}} <h1>Selected <?= count($objects) ?> services </h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php foreach($this->services as $service) { ?>
|
||||
<li>
|
||||
<a href="<?= $this->href(
|
||||
'monitoring/show/service',
|
||||
array(
|
||||
'host' => $service->host_name,
|
||||
'service' => $service->service_description
|
||||
)
|
||||
);?>">
|
||||
<?= $service->host_name ?> <?= $service->service_description ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $this->render('multi/components/summary.phtml') ?>
|
@ -40,7 +40,8 @@ class NotificationQuery extends IdoQuery
|
||||
'notification_type' => 'n.notification_type',
|
||||
'notification_reason' => 'n.notification_reason',
|
||||
'notification_start_time' => 'n.start_time',
|
||||
'notification_information' => 'n.output'
|
||||
'notification_information' => 'n.output',
|
||||
'notification_internal_id' => 'n.notification_id'
|
||||
),
|
||||
'objects' => array(
|
||||
'host_name' => 'o.name1',
|
||||
|
@ -84,6 +84,20 @@ class Meta
|
||||
const CMD_DELAY_NOTIFICATION = 28;
|
||||
const CMD_REMOVE_DOWNTIME = 29;
|
||||
|
||||
|
||||
/**
|
||||
* The context defines which commands are related to which icinga object. This
|
||||
* is useful for narrowing down the commands to the relevant ones.
|
||||
*/
|
||||
|
||||
const CONTEXT_SERVICE = 'service';
|
||||
const CONTEXT_HOST = 'host';
|
||||
const CONTEXT_DOWNTIME = 'downtime';
|
||||
const CONTEXT_NOTIFICATION = 'notification';
|
||||
const CONTEXT_COMMENT = 'comment';
|
||||
const CONTEXT_CONTACT = 'contact';
|
||||
|
||||
|
||||
/**
|
||||
* Filter array for array displayed in small interfaces
|
||||
* @var int[]
|
||||
@ -628,38 +642,21 @@ class Meta
|
||||
/**
|
||||
* Returns the type of object
|
||||
*
|
||||
* This is made by the first key of property
|
||||
* e.g.
|
||||
* $object->host_state
|
||||
* Type is 'host'
|
||||
*
|
||||
* @param \stdClass $object
|
||||
* @return mixed
|
||||
* @param $object The object
|
||||
*
|
||||
* @return string Either 'host' or 'service'
|
||||
*/
|
||||
private function getObjectType(\stdClass $object)
|
||||
private function getObjectType($object)
|
||||
{
|
||||
$objectKeys = array_keys(get_object_vars($object));
|
||||
$firstKeys = explode('_', array_shift($objectKeys), 2);
|
||||
return array_shift($firstKeys);
|
||||
if ($object instanceof \Icinga\Module\Monitoring\Object\Host) {
|
||||
return 'host';
|
||||
} else if ($object instanceof \Icinga\Module\Monitoring\Object\Service) {
|
||||
return 'service';
|
||||
}
|
||||
|
||||
throw new ProgrammingError('Object must be either "host" or "service"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns method name based on object type
|
||||
* @param string $type
|
||||
* @return string
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*/
|
||||
private function getCommandProcessorMethod($type)
|
||||
{
|
||||
if (array_key_exists($type, self::$commandProcessorMethods)) {
|
||||
$method = self::$commandProcessorMethods[$type];
|
||||
if (is_callable(array(&$this, $method))) {
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ProgrammingError('Type has no command processor: '. $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return interface commands by object type
|
||||
@ -675,43 +672,19 @@ class Meta
|
||||
|
||||
throw new ProgrammingError('Type has no commands defined: '. $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies data objects to drop their object type
|
||||
*
|
||||
* - host_state will be state
|
||||
* - service_state will be also state
|
||||
* - And so on
|
||||
*
|
||||
* @param \stdClass $object
|
||||
* @param $type
|
||||
* @return object
|
||||
*/
|
||||
private function dropTypeAttributes(\stdClass $object, $type)
|
||||
{
|
||||
$objectData = get_object_vars($object);
|
||||
foreach ($objectData as $propertyName => $propertyValue) {
|
||||
$newProperty = str_replace($type. '_', '', $propertyName);
|
||||
$objectData[$newProperty] = $propertyValue;
|
||||
unset($objectData[$propertyName]);
|
||||
}
|
||||
return (object)$objectData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default processor for host and service objects
|
||||
*
|
||||
* Drop commands from list based on states and object properties
|
||||
*
|
||||
* @param \stdClass $object
|
||||
* @param $object
|
||||
* @param array $commands
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
private function defaultCommandProcessor(\stdClass $object, array $commands, $type)
|
||||
private function processCommand($object, array $commands, $type)
|
||||
{
|
||||
$object = $this->dropTypeAttributes($object, $type);
|
||||
|
||||
$commands = array_flip($commands);
|
||||
|
||||
if ($object->active_checks_enabled === '1') {
|
||||
@ -736,8 +709,8 @@ class Meta
|
||||
unset($commands[self::CMD_STOP_OBSESSING]);
|
||||
}
|
||||
|
||||
if ($object->state !== '0') {
|
||||
if ($object->acknowledged === '1') {
|
||||
if ($object->{$type . '_state'} !== '0') {
|
||||
if ($object->{ $type . '_acknowledged'} === '1') {
|
||||
unset($commands[self::CMD_ACKNOWLEDGE_PROBLEM]);
|
||||
} else {
|
||||
unset($commands[self::CMD_REMOVE_ACKNOWLEDGEMENT]);
|
||||
@ -767,6 +740,7 @@ class Meta
|
||||
|
||||
return array_flip($commands);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates structure to work with in interfaces
|
||||
@ -825,22 +799,88 @@ class Meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get commands for an object
|
||||
* Narrow down several sets of commands to one set that only contains
|
||||
* commands that are possible in all sets
|
||||
*
|
||||
* @param array $sets The sets of commands to narrow down.
|
||||
*
|
||||
* @returns array The merged set of commands
|
||||
*/
|
||||
private function mergeCommands(array $sets)
|
||||
{
|
||||
/*
|
||||
* Collect all occurring commands
|
||||
*/
|
||||
$merged = array();
|
||||
for ($i = 0; $i < count($sets); $i++) {
|
||||
foreach ($sets[$i] as $j => $value) {
|
||||
$merged[$sets[$i][$j]] = $j;
|
||||
}
|
||||
$sets[$i] = array_flip($sets[$i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove all commands that do not exist in every set
|
||||
*
|
||||
foreach ($merged as $command => $index) {
|
||||
foreach ($sets as $i => $set) {
|
||||
if (!array_key_exists($command, $set)) {
|
||||
unset($merged[$command]);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return array_flip($merged);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all commands that do not apply to the given context.
|
||||
*
|
||||
* @param array $commands The commands that will be reduced
|
||||
* @param string $context The context, either
|
||||
*/
|
||||
private function applyContext($commands, $context)
|
||||
{
|
||||
switch ($context) {
|
||||
case 'comment':
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get commands that are available for a set of objects. If more than one object is given,
|
||||
* the set of commands will be narrowed down to a CommandSet that is available to all
|
||||
*
|
||||
* Based on objects and interface type
|
||||
*
|
||||
* @param \stdClass $object
|
||||
* @param $interfaceType
|
||||
* @param User $user
|
||||
* @param mixed $object Retrieve the commands for
|
||||
* @param $interfaceType The interface type (Meta::TYPE_FULL or Meta::TYPE_SMALL) to determine
|
||||
* the amount of showed commands.
|
||||
* @param string $context The context that will be used to narrow down the commands.
|
||||
* @param User $user CURRENTLY NOT IMPLEMENTED!
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCommandForObject(\stdClass $object, $interfaceType, User $user = null)
|
||||
public function getCommandForObject(
|
||||
$objects,
|
||||
$interfaceType,
|
||||
$context = null,
|
||||
User $user = null
|
||||
)
|
||||
{
|
||||
$objectType = $this->getObjectType($object);
|
||||
$commands = $this->getCommandsByType($objectType);
|
||||
$method = $this->getCommandProcessorMethod($objectType);
|
||||
$commands = $this->$method($object, $commands, $objectType);
|
||||
$commands = $this->filterInterfaceType($commands, $interfaceType);
|
||||
if (!is_array($objects)) {
|
||||
$objects = array($objects);
|
||||
}
|
||||
$commands = array();
|
||||
foreach ($objects as $object) {
|
||||
$objectType = $this->getObjectType($object);
|
||||
$command = $this->getCommandsByType($objectType);
|
||||
$command = $this->processCommand($object, $command, $objectType);
|
||||
$command = $this->filterInterfaceType($command, $interfaceType);
|
||||
$commands[] = $command;
|
||||
}
|
||||
$commands = $this->mergeCommands($commands);
|
||||
$commands = $this->buildInterfaceConfiguration($commands, $objectType);
|
||||
return $commands;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class Notification extends DataView
|
||||
'notification_command',
|
||||
'host',
|
||||
'service'
|
||||
'notification_internal_id'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ function($, URI, Selectable) {
|
||||
if (!selections[i]) {
|
||||
selections[i] = [];
|
||||
}
|
||||
selections[i] = [ encodeURIComponent(key) + '=' + encodeURIComponent(value) ];
|
||||
selections[i].push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
|
||||
}
|
||||
});
|
||||
return selections;
|
||||
|
Loading…
x
Reference in New Issue
Block a user