commit
8d4bc479f7
|
@ -0,0 +1,163 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
|
||||
/**
|
||||
* Base class for any concrete command implementation
|
||||
*/
|
||||
abstract class Command
|
||||
{
|
||||
/**
|
||||
* Whether hosts are ignored in case of a host- or servicegroup
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $withoutHosts = false;
|
||||
|
||||
/**
|
||||
* Whether services are ignored in case of a host- or servicegroup
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $withoutServices = false;
|
||||
|
||||
/**
|
||||
* Whether child hosts are going to be included in case of a host command
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $withChildren = false;
|
||||
|
||||
/**
|
||||
* Whether only services are going to be included in case of a host command
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $onlyServices = false;
|
||||
|
||||
/**
|
||||
* Set whether this command should only affect the services of a host- or servicegroup
|
||||
*
|
||||
* @param bool $state
|
||||
* @return self
|
||||
*/
|
||||
public function excludeHosts($state = true)
|
||||
{
|
||||
$this->withoutHosts = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this command should only affect the hosts of a host- or servicegroup
|
||||
*
|
||||
* @param bool $state
|
||||
* @return self
|
||||
*/
|
||||
public function excludeServices($state = true)
|
||||
{
|
||||
$this->withoutServices = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this command should also affect all children hosts of a host
|
||||
*
|
||||
* @param bool $state
|
||||
* @return self
|
||||
*/
|
||||
public function includeChildren($state = true)
|
||||
{
|
||||
$this->withChildren = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this command only affects the services associated with a particular host
|
||||
*
|
||||
* @param bool $state
|
||||
* @return self
|
||||
*/
|
||||
public function excludeHost($state = true)
|
||||
{
|
||||
$this->onlyServices = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's arguments in the order expected by the actual command definition
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getArguments();
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
abstract public function getHostCommand($hostname);
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host and service being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
abstract public function getServiceCommand($hostname, $servicename);
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given hostgroup being inserted
|
||||
*
|
||||
* @param string $hostgroup The name of the hostgroup to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getHostgroupCommand($hostgroup)
|
||||
{
|
||||
throw new ProgrammingError(get_class($this) . ' does not provide a hostgroup command');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given servicegroup being inserted
|
||||
*
|
||||
* @param string $servicegroup The name of the servicegroup to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getServicegroupCommand($servicegroup)
|
||||
{
|
||||
throw new ProgrammingError(get_class($this) . ' does not provide a servicegroup command');
|
||||
}
|
||||
}
|
|
@ -139,13 +139,14 @@ class CommandPipe
|
|||
/**
|
||||
* Send a command to the icinga pipe
|
||||
*
|
||||
* @param \Icinga\Protocol\Commandpipe\CommandType $command
|
||||
* @param array $objects
|
||||
* @param Command $command
|
||||
* @param array $objects
|
||||
*/
|
||||
public function sendCommand(CommandType $command, array $objects)
|
||||
public function sendCommand(Command $command, array $objects)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
if (isset($object->service_description)) {
|
||||
$objectType = $this->getObjectType($object);
|
||||
if ($objectType === self::TYPE_SERVICE) {
|
||||
$this->transport->send($command->getServiceCommand($object->host_name, $object->service_description));
|
||||
} else {
|
||||
$this->transport->send($command->getHostCommand($object->host_name));
|
||||
|
@ -169,74 +170,6 @@ class CommandPipe
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit passive check result for all provided objects
|
||||
*
|
||||
* @param array $objects An array of hosts and services to submit the passive check result to
|
||||
* @param int $state The state to set for the monitoring objects
|
||||
* @param string $output The output string to set as the check result
|
||||
* @param string $perfdata The optional perfdata to submit as the check result
|
||||
*/
|
||||
public function submitCheckResult($objects, $state, $output, $perfdata = "")
|
||||
{
|
||||
if ($perfdata) {
|
||||
$output = $output."|".$perfdata;
|
||||
}
|
||||
foreach ($objects as $object) {
|
||||
if (isset($object->service_description)) {
|
||||
$this->send(
|
||||
"PROCESS_SERVICE_CHECK_RESULT;$object->host_name;$object->service_description;$state;$output"
|
||||
);
|
||||
} else {
|
||||
$this->send("PROCESS_HOST_CHECK_RESULT;$object->host_name;$state;$output");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reschedule a forced check for all provided objects
|
||||
*
|
||||
* @param array $objects An array of hosts and services to reschedule
|
||||
* @param int|bool $time The time to submit, if empty time() will be used
|
||||
* @param bool $withChilds Whether only childs should be rescheduled
|
||||
*/
|
||||
public function scheduleForcedCheck($objects, $time = false, $withChilds = false)
|
||||
{
|
||||
if (!$time) {
|
||||
$time = time();
|
||||
}
|
||||
$base = "SCHEDULE_FORCED_";
|
||||
foreach ($objects as $object) {
|
||||
if (isset($object->service_description)) {
|
||||
$this->send($base . "SVC_CHECK;$object->host_name;$object->service_description;$time");
|
||||
} else {
|
||||
$this->send($base . 'HOST_' . ($withChilds ? 'SVC_CHECKS' : 'CHECK') . ";$object->host_name;$time");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reschedule a check for all provided objects
|
||||
*
|
||||
* @param array $objects An array of hosts and services to reschedule
|
||||
* @param int|bool $time The time to submit, if empty time() will be used
|
||||
* @param bool $withChilds Whether only childs should be rescheduled
|
||||
*/
|
||||
public function scheduleCheck($objects, $time = false, $withChilds = false)
|
||||
{
|
||||
if (!$time) {
|
||||
$time = time();
|
||||
}
|
||||
$base = "SCHEDULE_";
|
||||
foreach ($objects as $object) {
|
||||
if (isset($object->service_description)) {
|
||||
$this->send($base . "SVC_CHECK;$object->host_name;$object->service_description;$time");
|
||||
} else {
|
||||
$this->send($base . 'HOST_' . ($withChilds ? 'SVC_CHECKS' : 'CHECK') . ";$object->host_name;$time");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the submitted comments
|
||||
*
|
||||
|
@ -301,26 +234,6 @@ class CommandPipe
|
|||
return self::TYPE_HOST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a downtime for all provided objects
|
||||
*
|
||||
* @param array $objects An array of monitoring objects to schedule the downtime for
|
||||
* @param Downtime $downtime The downtime object to schedule
|
||||
*/
|
||||
public function scheduleDowntime($objects, Downtime $downtime)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
if ($type == self::TYPE_SERVICE) {
|
||||
$this->send(
|
||||
sprintf($downtime->getFormatString($type), $object->host_name, $object->service_description)
|
||||
);
|
||||
} else {
|
||||
$this->send(sprintf($downtime->getFormatString($type), $object->host_name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove downtimes for objects
|
||||
*
|
||||
|
@ -617,35 +530,6 @@ class CommandPipe
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send custom host and/or service notifications
|
||||
*
|
||||
* @param array $objects Affected monitoring objects
|
||||
* @param CustomNotification $notification
|
||||
*/
|
||||
public function sendCustomNotification(array $objects, CustomNotification $notification)
|
||||
{
|
||||
foreach ($objects as $hostOrService) {
|
||||
if (isset($hostOrService->service_description) && isset($hostOrService->host_name)) {
|
||||
// Assume service
|
||||
$command = sprintf(
|
||||
$notification->getFormatString(self::TYPE_SERVICE),
|
||||
$hostOrService->host_name,
|
||||
$hostOrService->service_description
|
||||
);
|
||||
} elseif (isset($hostOrService->host_name)) {
|
||||
// Assume host
|
||||
$command = sprintf(
|
||||
$notification->getFormatString(self::TYPE_HOST),
|
||||
$hostOrService->host_name
|
||||
);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$this->send($command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable notifications for all services of the provided hosts
|
||||
*
|
||||
|
@ -715,24 +599,6 @@ class CommandPipe
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay notifications for all provided hosts and services for $time seconds
|
||||
*
|
||||
* @param array $objects An array of hosts and services
|
||||
* @param int $time The number of seconds to delay notifications for
|
||||
*/
|
||||
public function delayNotification($objects, $time)
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
$type = $this->getObjectType($object);
|
||||
if ($type === self::TYPE_SERVICE) {
|
||||
$this->send('DELAY_SVC_NOTIFICATION;'.$object->host_name.';'.$object->service_description.';'.$time);
|
||||
} else {
|
||||
$this->send('DELAY_HOST_NOTIFICATION;'.$object->host_name.';'.$time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transport handler that handles actual sending of commands
|
||||
*
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Interface definition for command objects processed by the CommandPipe
|
||||
*/
|
||||
interface CommandType
|
||||
{
|
||||
}
|
|
@ -29,7 +29,7 @@
|
|||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Container for comment information that can be send to icinga's external command pipe
|
||||
* Container for comment information that can be send to Icinga's external command pipe
|
||||
*/
|
||||
class Comment
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ class Comment
|
|||
* @param bool $ignorePersistentFlag Whether the persistent flag should be included or not
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters($ignorePersistentFlag = false)
|
||||
public function getArguments($ignorePersistentFlag = false)
|
||||
{
|
||||
if ($ignorePersistentFlag) {
|
||||
return array($this->author, $this->content);
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Custom notification about hosts or services sent to Icinga's command pipe
|
||||
*/
|
||||
class CustomNotification
|
||||
{
|
||||
/**
|
||||
* Notification comment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Notification author
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $author;
|
||||
|
||||
/**
|
||||
* Whether to force the notification to be sent out, regardless of the time restrictions, whether or not
|
||||
* notifications are enabled, etc.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $forced;
|
||||
|
||||
/**
|
||||
* Whether the notification is sent out to all normal (non-escalated) and escalated contacts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $broadcast;
|
||||
|
||||
/**
|
||||
* 1 = Broadcast (send notification to all normal and all escalated contacts for the host)
|
||||
*/
|
||||
const NOTIFY_BROADCAST = 1;
|
||||
|
||||
/**
|
||||
* 2 = Forced (notification is sent out regardless of current time, whether or not notifications are enabled, etc.)
|
||||
*/
|
||||
const NOTIFY_FORCED = 2;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $author Notification author
|
||||
* @param string $comment Notification comment
|
||||
* @param bool $forced Whether to force the notification to be sent out, regardless of the time
|
||||
* restrictions, whether or not notifications are enabled, etc.
|
||||
* @param bool $broadcast Whether the notification is sent out to all normal (non-escalated) and escalated
|
||||
* contacts
|
||||
*/
|
||||
public function __construct($author, $comment, $forced = false, $broadcast = false)
|
||||
{
|
||||
$this->author = $author;
|
||||
$this->comment = $comment;
|
||||
$this->forced = $forced;
|
||||
$this->broadcast = $broadcast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Custom Notification command format string according to if its sent to a host or a service
|
||||
*
|
||||
* @param string $type Identifier for either host or service
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidCommandException When the given type is unknown
|
||||
* @see \Icinga\Protocol\Commandpipe\CommandPipe::TYPE_HOST
|
||||
* @see \Icinga\Protocol\Commandpipe\CommandPipe::TYPE_SERVICE
|
||||
*/
|
||||
public function getFormatString($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case CommandPipe::TYPE_HOST:
|
||||
$format = '%s';
|
||||
break;
|
||||
case CommandPipe::TYPE_SERVICE:
|
||||
$format = '%s;%s';
|
||||
break;
|
||||
default:
|
||||
throw new InvalidCommandException('Custom Notifications can only apply on hosts and services');
|
||||
}
|
||||
|
||||
$options = 0;
|
||||
if ($this->forced) {
|
||||
$options |= self::NOTIFY_FORCED;
|
||||
}
|
||||
if ($this->broadcast) {
|
||||
$options |= self::NOTIFY_BROADCAST;
|
||||
}
|
||||
|
||||
// Build the command
|
||||
$command = 'SEND_CUSTOM_' . $type . '_NOTIFICATION;'
|
||||
. $format . ';'
|
||||
. $options . ';'
|
||||
. $this->author . ';'
|
||||
. $this->comment;
|
||||
return $command;
|
||||
}
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Protocol\Commandpipe;
|
||||
|
||||
/**
|
||||
* Container class containing downtime information
|
||||
*
|
||||
*/
|
||||
class Downtime
|
||||
{
|
||||
/**
|
||||
* Propagate this downtime for all child objects
|
||||
*/
|
||||
const TYPE_WITH_CHILDREN = 'AND_PROPAGATE_';
|
||||
|
||||
/**
|
||||
* Propagate this downtime for all child objects as triggered downtime
|
||||
*/
|
||||
const TYPE_WITH_CHILDREN_TRIGGERED = 'AND_PROPAGATE_TRIGGERED_';
|
||||
|
||||
/**
|
||||
* Schedule downtime for the services of the given hos
|
||||
*/
|
||||
const TYPE_HOST_SVC = 'HOST_SVC';
|
||||
|
||||
/**
|
||||
* Timestamp representing the downtime's start
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $startTime;
|
||||
|
||||
/**
|
||||
* Timestamp representing the downtime's end
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $endTime;
|
||||
|
||||
/**
|
||||
* Whether this is a fixed downtime
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $fixed = false;
|
||||
|
||||
/**
|
||||
* The duration of the downtime in seconds if flexible
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $duration;
|
||||
|
||||
/**
|
||||
* The comment object of the downtime
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
public $comment;
|
||||
|
||||
/**
|
||||
* The downtime id that triggers this downtime (0 = no triggered downtime)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $trigger_id = 0;
|
||||
|
||||
/**
|
||||
* Internal information for the exact type of the downtime
|
||||
*
|
||||
* E.g. with children, with children and triggered, services etc.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $subtype = '';
|
||||
|
||||
/**
|
||||
* Create a new downtime container
|
||||
*
|
||||
* @param int $start A timestamp that defines the downtime's start time
|
||||
* @param int $end A timestamp that defines the downtime's end time
|
||||
* @param Comment $comment A comment that will be used when scheduling the downtime
|
||||
* @param int $duration The duration of this downtime in seconds.
|
||||
* Duration > 0 will make this a flexible downtime
|
||||
* @param int $trigger_id An id of the downtime that triggers this downtime.
|
||||
* 0 means this is not a triggered downtime
|
||||
*/
|
||||
public function __construct($start, $end, Comment $comment, $duration = 0, $trigger_id = 0)
|
||||
{
|
||||
$this->startTime = $start;
|
||||
$this->endTime = $end;
|
||||
$this->comment = $comment;
|
||||
if ($duration == 0) {
|
||||
$this->fixed = true;
|
||||
}
|
||||
$this->duration = intval($duration);
|
||||
$this->trigger_id = intval($trigger_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the SCHEDULE_?_DOWNTIME representing this class for the given $type
|
||||
*
|
||||
* @param string $type CommandPipe::TYPE_SERVICE to trigger a service downtime or CommandPipe::TYPE_HOST to
|
||||
* trigger a host downtime
|
||||
* @return string A schedule downtime command representing the state of this class
|
||||
*
|
||||
*/
|
||||
public function getFormatString($type)
|
||||
{
|
||||
if ($this->subtype == self::TYPE_HOST_SVC) {
|
||||
$type = "";
|
||||
}
|
||||
return 'SCHEDULE_'
|
||||
. $this->subtype
|
||||
. $type
|
||||
. '_DOWNTIME;'
|
||||
. '%s;'
|
||||
. ($type == CommandPipe::TYPE_SERVICE ? '%s;' : '')
|
||||
. $this->startTime . ';'
|
||||
. $this->endTime . ';'
|
||||
. ($this->fixed ? '1' : '0') . ';'
|
||||
. $this->trigger_id . ';'
|
||||
. $this->duration . ';'
|
||||
. $this->comment->author . ';'
|
||||
. $this->comment->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the exact type of this downtime (see the TYPE_ constants)
|
||||
*
|
||||
* @param $type The type of to use for this downtime
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
$this->subtype = $type;
|
||||
}
|
||||
}
|
|
@ -280,7 +280,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$this->target->scheduleCheck($this->view->objects);
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$this->target->submitCheckResult($this->view->objects, $form->getState(), $form->getOutput(), $form->getPerformancedata());
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$this->target->sendCustomNotification($this->view->objects, $form->getCustomNotification());
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,7 +435,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$this->target->scheduleDowntime($this->view->objects, $form->getDowntime());
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$this->target->scheduleDowntime($this->view->objects, $form->getDowntime());
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -518,19 +518,12 @@ class Monitoring_CommandController extends ActionController
|
|||
$form = new RescheduleNextCheckForm();
|
||||
$form->setRequest($this->getRequest());
|
||||
$form->setConfiguration(Config::app());
|
||||
|
||||
$form->setWithChildren(true);
|
||||
|
||||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
if ($form->isForced()) {
|
||||
$this->target->scheduleForcedCheck($this->view->objects, time());
|
||||
$this->target->scheduleForcedCheck($this->view->objects, time(), true);
|
||||
} else {
|
||||
$this->target->scheduleCheck($this->view->objects, time());
|
||||
$this->target->scheduleCheck($this->view->objects, time(), true);
|
||||
}
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -717,7 +710,7 @@ class Monitoring_CommandController extends ActionController
|
|||
$this->setForm($form);
|
||||
|
||||
if ($form->IsSubmittedAndValid() === true) {
|
||||
$this->target->delayNotification($this->view->objects, $form->getDelayTime());
|
||||
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use \Icinga\Protocol\Commandpipe\CustomNotification;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Module\Monitoring\Command\CustomNotificationCommand;
|
||||
|
||||
/**
|
||||
* For for command CustomNotification
|
||||
|
@ -97,15 +98,17 @@ class CustomNotificationForm extends CommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Create Custom Notification from request data
|
||||
* Create the command object to send custom notifications
|
||||
*
|
||||
* @return CustomNotification
|
||||
* @return CustomNotificationCommand
|
||||
*/
|
||||
public function getCustomNotification()
|
||||
public function createCommand()
|
||||
{
|
||||
return new CustomNotification(
|
||||
$this->getAuthorName(),
|
||||
$this->getValue('comment'),
|
||||
return new CustomNotificationCommand(
|
||||
new Comment(
|
||||
$this->getAuthorName(),
|
||||
$this->getValue('comment')
|
||||
),
|
||||
$this->getValue('forced'),
|
||||
$this->getValue('broadcast')
|
||||
);
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
||||
|
||||
/**
|
||||
* Form for the delay notification command
|
||||
*/
|
||||
|
@ -76,12 +78,12 @@ class DelayNotificationForm extends CommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the currently set delay time in seconds
|
||||
* Create the command object to delay notifications
|
||||
*
|
||||
* @return integer
|
||||
* @return DelayNotificationCommand
|
||||
*/
|
||||
public function getDelayTime()
|
||||
public function createCommand()
|
||||
{
|
||||
return $this->getValue('minutes') * 60;
|
||||
return new DelayNotificationCommand($this->getValue('minutes') * 60);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,10 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use \Zend_Form_Element_Checkbox;
|
||||
use \Icinga\Web\Form\Element\DateTimePicker;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use Zend_Form_Element_Checkbox;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
||||
|
||||
/**
|
||||
* Form for scheduling checks
|
||||
|
@ -90,12 +91,16 @@ class RescheduleNextCheckForm extends WithChildrenCommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Return whether this is a forced check (force is checked)
|
||||
* Create the command object to schedule checks
|
||||
*
|
||||
* @return bool
|
||||
* @return ScheduleCheckCommand
|
||||
*/
|
||||
public function isForced()
|
||||
public function createCommand()
|
||||
{
|
||||
return $this->getValue('forcecheck') == true;
|
||||
$command = new ScheduleCheckCommand(
|
||||
$this->getValue('checktime'),
|
||||
$this->getValue('forcecheck')
|
||||
);
|
||||
return $command->excludeHost($this->getWithChildren());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Form\Command;
|
||||
|
||||
use \Zend_Form_Element_Text;
|
||||
use \Zend_Validate_GreaterThan;
|
||||
use \Zend_Validate_Digits;
|
||||
use \Icinga\Web\Form\Element\DateTimePicker;
|
||||
use \Icinga\Protocol\Commandpipe\Downtime;
|
||||
use \Icinga\Protocol\Commandpipe\Comment;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use \Icinga\Module\Monitoring\Backend;
|
||||
use Zend_Form_Element_Text;
|
||||
use Zend_Validate_GreaterThan;
|
||||
use Zend_Validate_Digits;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand;
|
||||
|
||||
/**
|
||||
* Form for scheduling downtimes
|
||||
|
@ -100,7 +100,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
)->fetchAll();
|
||||
|
||||
$options = array(
|
||||
'0' => 'No Triggered Downtime '
|
||||
'0' => 'No Triggered Downtime'
|
||||
);
|
||||
foreach ($downtimes as $downtime) {
|
||||
$dt = DateTimeFactory::create($downtime->downtime_scheduled_start_time);
|
||||
|
@ -159,10 +159,6 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @TODO: Display downtime list (Bug #4496)
|
||||
*
|
||||
*/
|
||||
$this->addElement(
|
||||
'select',
|
||||
'triggered',
|
||||
|
@ -328,43 +324,27 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Create Downtime from request Data
|
||||
* Create ScheduleDowntimeCommand object
|
||||
*
|
||||
* @return Downtime
|
||||
* @return ScheduleDowntimeCommand
|
||||
*/
|
||||
public function getDowntime()
|
||||
public function createCommand()
|
||||
{
|
||||
|
||||
$comment = new Comment(
|
||||
$this->getRequest()->getUser()->getUsername(),
|
||||
$this->getValue('comment')
|
||||
);
|
||||
$duration = 0;
|
||||
if ($this->getValue('type') === self::TYPE_FLEXIBLE) {
|
||||
$duration = ($this->getValue('hours') * 3600) + ($this->getValue('minutes') * 60);
|
||||
}
|
||||
$starttime = $this->getValue('starttime');
|
||||
$endtime = $this->getValue('endtime');
|
||||
|
||||
$downtime = new Downtime(
|
||||
$starttime,
|
||||
$endtime,
|
||||
$comment,
|
||||
$duration,
|
||||
// TODO: Add support for host-/servicegroups and services only (#4588)
|
||||
$command = new ScheduleDowntimeCommand(
|
||||
$this->getValue('starttime'),
|
||||
$this->getValue('endtime'),
|
||||
new Comment(
|
||||
$this->getRequest()->getUser()->getUsername(),
|
||||
$this->getValue('comment')
|
||||
),
|
||||
$this->getValue('type') === self::TYPE_FLEXIBLE,
|
||||
$this->getValue('hours') * 3600 + $this->getValue('minutes') * 60,
|
||||
$this->getValue('triggered')
|
||||
);
|
||||
if (!$this->getWithChildren()) {
|
||||
switch ($this->getValue('childobjects')) {
|
||||
case 1:
|
||||
$downtime->setType(Downtime::TYPE_WITH_CHILDREN_TRIGGERED);
|
||||
break;
|
||||
case 2:
|
||||
$downtime->setType(Downtime::TYPE_WITH_CHILDREN);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$downtime->setType(Downtime::TYPE_HOST_SVC);
|
||||
}
|
||||
return $downtime;
|
||||
return $command->includeChildren(
|
||||
$this->getWithChildren(),
|
||||
$this->getValue('childobjects') === 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,32 +184,16 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the entered object state as an integer
|
||||
* Create the submit passive checkresult command object
|
||||
*
|
||||
* @return int
|
||||
* @return SubmitPassiveCheckresultCommand
|
||||
*/
|
||||
public function getState()
|
||||
public function createCommand()
|
||||
{
|
||||
return intval($this->getValue('pluginstate'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entered check output as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->getValue('checkoutput');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the entered performance data as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPerformancedata()
|
||||
{
|
||||
return $this->getValue('performancedata');
|
||||
return new SubmitPassiveCheckresultCommand(
|
||||
$this->getValue('pluginstate'),
|
||||
$this->getValue('checkoutput'),
|
||||
$this->getValue('performancedata')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,13 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Command for acknowledging an object
|
||||
*/
|
||||
class AcknowledgeCommand extends BaseCommand
|
||||
class AcknowledgeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* When this acknowledgement should expire
|
||||
|
@ -83,11 +84,12 @@ class AcknowledgeCommand extends BaseCommand
|
|||
* Set the time when this acknowledgement should expire
|
||||
*
|
||||
* @param int $expireTime The time as UNIX timestamp or -1 if it shouldn't expire
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setExpire($expireTime)
|
||||
{
|
||||
$this->expireTime = intval($expireTime);
|
||||
$this->expireTime = (int) $expireTime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -95,6 +97,7 @@ class AcknowledgeCommand extends BaseCommand
|
|||
* Set the comment for this acknowledgement
|
||||
*
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setComment(Comment $comment)
|
||||
|
@ -107,6 +110,7 @@ class AcknowledgeCommand extends BaseCommand
|
|||
* Set whether the notify flag of this acknowledgment should be set
|
||||
*
|
||||
* @param bool $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setNotify($state)
|
||||
|
@ -119,6 +123,7 @@ class AcknowledgeCommand extends BaseCommand
|
|||
* Set whether this acknowledgement is of type sticky
|
||||
*
|
||||
* @param bool $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setSticky($state)
|
||||
|
@ -130,16 +135,17 @@ class AcknowledgeCommand extends BaseCommand
|
|||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
* @see Command::getArguments()
|
||||
*/
|
||||
public function getParameters()
|
||||
public function getArguments()
|
||||
{
|
||||
$parameters = array_merge(
|
||||
array(
|
||||
$this->sticky ? '2' : '0',
|
||||
$this->notify ? '1' : '0'
|
||||
),
|
||||
$this->comment->getParameters()
|
||||
$this->comment->getArguments()
|
||||
);
|
||||
|
||||
if ($this->expireTime > -1) {
|
||||
|
@ -150,28 +156,32 @@ class AcknowledgeCommand extends BaseCommand
|
|||
}
|
||||
|
||||
/**
|
||||
* @param String $hostname The name of the host to create the command for for
|
||||
* Return the command as a string with the given host being inserted
|
||||
*
|
||||
* @return String The command string to return for the host
|
||||
* @see BaseCommand::getHostCommand()
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
$parameters = $this->getParameters();
|
||||
$parameters = $this->getArguments();
|
||||
return sprintf('ACKNOWLEDGE_HOST_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '')
|
||||
. implode(';', array_merge(array($hostname), $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $hostname The name of the host to create the command for
|
||||
* @param String $servicename The name of the service to create the command for
|
||||
* Return the command as a string with the given host and service being inserted
|
||||
*
|
||||
* @return String The command string to return for the service
|
||||
* @see BaseCommand::getServiceCommand()
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getServiceCommand()
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
$parameters = $this->getParameters();
|
||||
$parameters = $this->getArguments();
|
||||
return sprintf('ACKNOWLEDGE_SVC_PROBLEM%s;', $this->expireTime > -1 ? '_EXPIRE' : '')
|
||||
. implode(';', array_merge(array($hostname, $servicename), $parameters));
|
||||
}
|
||||
|
|
|
@ -28,14 +28,15 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Icinga Command for adding comments
|
||||
*
|
||||
* @see BaseCommand
|
||||
* @see Command
|
||||
*/
|
||||
class AddCommentCommand extends BaseCommand
|
||||
class AddCommentCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The comment associated to this command
|
||||
|
@ -58,6 +59,7 @@ class AddCommentCommand extends BaseCommand
|
|||
* Set the comment for this command
|
||||
*
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setComment(Comment $comment)
|
||||
|
@ -66,27 +68,36 @@ class AddCommentCommand extends BaseCommand
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $hostname The name of the host to create the command for for
|
||||
*
|
||||
* @return String The command string to return for the host
|
||||
* @see BaseCommand::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
public function getArguments()
|
||||
{
|
||||
return sprintf('ADD_HOST_COMMENT;%s;', $hostname) . implode(';', $this->comment->getParameters());
|
||||
return $this->comment->getArguments();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $hostname The name of the host to create the command for
|
||||
* @param String $servicename The name of the service to create the command for
|
||||
* Return the command as a string with the given host being inserted
|
||||
*
|
||||
* @return String The command string to return for the service
|
||||
* @see BaseCommand::getServiceCommand()
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
return sprintf('ADD_HOST_COMMENT;%s;', $hostname) . implode(';', $this->getArguments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host and service being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getServiceCommand()
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
return sprintf('ADD_SVC_COMMENT;%s;%s;', $hostname, $servicename)
|
||||
. implode(';', $this->comment->getParameters());
|
||||
. implode(';', $this->getArguments());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
|
||||
/**
|
||||
* Command to send a custom notification
|
||||
*/
|
||||
class CustomNotificationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The comment associated with this notification
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Whether this notification is forced
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $forced;
|
||||
|
||||
/**
|
||||
* Whether this notification is also sent to escalation-contacts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $broadcast;
|
||||
|
||||
/**
|
||||
* Initialise a new custom notification command object
|
||||
*
|
||||
* @param Comment $comment The comment for this notification
|
||||
* @param bool $forced Whether this notificatin is forced
|
||||
* @param bool $broadcast Whether this notification is sent to all contacts
|
||||
*/
|
||||
public function __construct(Comment $comment, $forced = false, $broadcast = false)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
$this->forced = $forced;
|
||||
$this->broadcast = $broadcast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment for this notification
|
||||
*
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setComment(Comment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this notification is forced
|
||||
*
|
||||
* @param bool $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setForced($state)
|
||||
{
|
||||
$this->forced = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this notification is sent to all contacts
|
||||
*
|
||||
* @param bool $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setBroadcast($state)
|
||||
{
|
||||
$this->broadcast = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
* @return array
|
||||
* @see Command::getArguments()
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
$options = 0;
|
||||
if ($this->forced) {
|
||||
$options |= 2;
|
||||
}
|
||||
if ($this->broadcast) {
|
||||
$options |= 1;
|
||||
}
|
||||
return array_merge(array($options), $this->comment->getArguments(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
return 'SEND_CUSTOM_HOST_NOTIFICATION;' . implode(';', array_merge(array($hostname), $this->getArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host and service being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getServiceCommand()
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
return 'SEND_CUSTOM_SVC_NOTIFICATION;' . implode(
|
||||
';',
|
||||
array_merge(
|
||||
array($hostname, $servicename),
|
||||
$this->getArguments()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -28,36 +28,65 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Exception\NotImplementedError;
|
||||
use Icinga\Protocol\Commandpipe\CommandType;
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Base class for any concrete command implementation
|
||||
*
|
||||
* Provides some example methods and often used routines. When implementing
|
||||
* a new command one is encouraged to override one of those examples.
|
||||
* Command to delay a notification
|
||||
*/
|
||||
class BaseCommand implements CommandType
|
||||
class DelayNotificationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Return the parameters in the right order for this command
|
||||
* The delay in seconds
|
||||
*
|
||||
* @return array
|
||||
* @var int
|
||||
*/
|
||||
public function getParameters()
|
||||
private $delay;
|
||||
|
||||
/**
|
||||
* Initialise a new delay notification command object
|
||||
*
|
||||
* @param int $delay How long, in seconds, notifications should be delayed
|
||||
*/
|
||||
public function __construct($delay)
|
||||
{
|
||||
throw new NotImplementedError();
|
||||
$this->delay = $delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how long notifications should be delayed
|
||||
*
|
||||
* @param int $seconds In seconds
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setDelay($seconds)
|
||||
{
|
||||
$this->delay = (int) $seconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
* @return array
|
||||
* @see Command::getArguments()
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return array($this->delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
throw new NotImplementedError();
|
||||
return 'DELAY_HOST_NOTIFICATION;' . implode(';', array_merge(array($hostname), $this->getArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,32 +94,18 @@ class BaseCommand implements CommandType
|
|||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getServiceCommand()
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
throw new NotImplementedError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given hostgroup being inserted
|
||||
*
|
||||
* @param string $hostgroup The name of the hostgroup to insert
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getHostgroupCommand($hostgroup)
|
||||
{
|
||||
throw new NotImplementedError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given servicegroup being inserted
|
||||
*
|
||||
* @param string $servicegroup The name of the servicegroup to insert
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getServicegroupCommand($servicegroup)
|
||||
{
|
||||
throw new NotImplementedError();
|
||||
return 'DELAY_SVC_NOTIFICATION;' . implode(
|
||||
';',
|
||||
array_merge(
|
||||
array($hostname, $servicename),
|
||||
$this->getArguments()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Command to schedule checks
|
||||
*/
|
||||
class ScheduleCheckCommand extends Command
|
||||
{
|
||||
/**
|
||||
* When this check is scheduled
|
||||
*
|
||||
* @var int The time as UNIX timestamp
|
||||
*/
|
||||
private $checkTime;
|
||||
|
||||
/**
|
||||
* Whether this check is forced
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $forced;
|
||||
|
||||
/**
|
||||
* Initialises a new command object to schedule checks
|
||||
*
|
||||
* @param int $checkTime The time as UNIX timestamp
|
||||
* @param bool $forced Whether this check is forced
|
||||
*/
|
||||
public function __construct($checkTime, $forced = false)
|
||||
{
|
||||
$this->checkTime = $checkTime;
|
||||
$this->forced = $forced;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set when to schedule this check
|
||||
*
|
||||
* @param int $checkTime The time as UNIX timestamp
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setCheckTime($checkTime)
|
||||
{
|
||||
$this->checkTime = (int) $checkTime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this check is forced
|
||||
*
|
||||
* @param bool $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setForced($state)
|
||||
{
|
||||
$this->forced = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
* @return array
|
||||
* @see Command::getArguments()
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return array($this->checkTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given host or all of it's services
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
return sprintf(
|
||||
'SCHEDULE%s_HOST_%s;',
|
||||
$this->forced ? '_FORCED' : '',
|
||||
$this->onlyServices ? 'SVC_CHECKS' : 'CHECK'
|
||||
) . implode(';', array_merge(array($hostname), $this->getArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given service
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getServiceCommand()
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
return sprintf('SCHEDULE%s_SVC_CHECK;', $this->forced ? '_FORCED' : '')
|
||||
. implode(';', array_merge(array($hostname, $servicename), $this->getArguments()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Command for scheduling a new downtime
|
||||
*/
|
||||
class ScheduleDowntimeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* When this downtime should start
|
||||
*
|
||||
* @var int The time as UNIX timestamp
|
||||
*/
|
||||
private $startTime;
|
||||
|
||||
/**
|
||||
* When this downtime should end
|
||||
*
|
||||
* @var int The time as UNIX timestamp
|
||||
*/
|
||||
private $endTime;
|
||||
|
||||
/**
|
||||
* The comment associated with this downtime
|
||||
*
|
||||
* @var Comment
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* Whether this is a fixed or flexible downtime
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $fixed;
|
||||
|
||||
/**
|
||||
* The duration to use when this downtime is a flexible one
|
||||
*
|
||||
* @var int In seconds
|
||||
*/
|
||||
private $duration;
|
||||
|
||||
/**
|
||||
* The ID of the downtime which triggers this one
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $triggerId;
|
||||
|
||||
/**
|
||||
* Whether this downtime should trigger children hosts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $triggerChildren;
|
||||
|
||||
/**
|
||||
* Set when to start this downtime
|
||||
*
|
||||
* @param int $startTime
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setStart($startTime)
|
||||
{
|
||||
$this->startTime = (int) $startTime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set when to end this downtime
|
||||
*
|
||||
* @param int $endTime
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setEnd($endTime)
|
||||
{
|
||||
$this->endTime = (int) $endTime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment for this downtime
|
||||
*
|
||||
* @param Comment $comment
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setComment(Comment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this downtime is fixed or flexible
|
||||
*
|
||||
* @param bool $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setFixed($state)
|
||||
{
|
||||
$this->fixed = (bool) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the duration of this downtime
|
||||
*
|
||||
* @param int $duration
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setDuration($duration)
|
||||
{
|
||||
$this->duration = (int) $duration;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the triggering id for this downtime
|
||||
*
|
||||
* @param int $triggerId
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setTriggerId($triggerId)
|
||||
{
|
||||
$this->triggerId = (int) $triggerId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise a new command object to schedule a downtime
|
||||
*
|
||||
* @param int $startTime When to start this downtime as UNIX timestamp
|
||||
* @param int $endTime When to end this downtime as UNIX timestamp
|
||||
* @param Comment $comment The comment to use for this downtime
|
||||
* @param bool $fixed Whether this downtime is fixed or flexible
|
||||
* @param int $duration How long in seconds this downtime should apply if flexible
|
||||
* @param int $triggerId The ID of the triggering downtime
|
||||
*/
|
||||
public function __construct($startTime, $endTime, Comment $comment, $fixed = true, $duration = 0, $triggerId = 0)
|
||||
{
|
||||
$this->startTime = $startTime;
|
||||
$this->endTime = $endTime;
|
||||
$this->comment = $comment;
|
||||
$this->fixed = $fixed;
|
||||
$this->duration = $duration;
|
||||
$this->triggerId = $triggerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include all children hosts with this command
|
||||
*
|
||||
* @param bool $state
|
||||
* @param bool $trigger Whether children are triggered by this downtime
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function includeChildren($state = true, $trigger = false) {
|
||||
$this->triggerChildren = (bool) $trigger;
|
||||
return parent::includeChildren($state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
* @return array
|
||||
* @see Command::getArguments()
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return array_merge(
|
||||
array(
|
||||
$this->startTime,
|
||||
$this->endTime,
|
||||
$this->fixed ? '1' : '0',
|
||||
$this->triggerId,
|
||||
$this->duration
|
||||
),
|
||||
$this->comment->getArguments(true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given host
|
||||
*
|
||||
* @param type $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
if ($this->withChildren) {
|
||||
return sprintf('SCHEDULE_AND_PROPAGATE%s_HOST_DOWNTIME;', $this->triggerChildren ? '_TRIGGERED' : '')
|
||||
. implode(';', array_merge(array($hostname), $this->getArguments()));
|
||||
} else {
|
||||
return sprintf('SCHEDULE_HOST%s_DOWNTIME;', $this->onlyServices ? '_SVC' : '')
|
||||
. implode(';', array_merge(array($hostname), $this->getArguments()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given service
|
||||
*
|
||||
* @param type $hostname The name of the host to insert
|
||||
* @param type $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
return 'SCHEDULE_SVC_DOWNTIME;' . implode(
|
||||
';',
|
||||
array_merge(
|
||||
array($hostname, $servicename),
|
||||
$this->getArguments()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given hostgroup
|
||||
*
|
||||
* @param type $hostgroup The name of the hostgroup to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getHostgroupCommand($hostgroup)
|
||||
{
|
||||
return sprintf('SCHEDULE_HOSTGROUP_%s_DOWNTIME;', $this->withoutHosts ? 'SVC' : 'HOST')
|
||||
. implode(';', array_merge(array($hostgroup), $this->getArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given servicegroup
|
||||
*
|
||||
* @param type $servicegroup The name of the servicegroup to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getServicegroupCommand($servicegroup)
|
||||
{
|
||||
return sprintf('SCHEDULE_SERVICEGROUP_%s_DOWNTIME;', $this->withoutServices ? 'HOST' : 'SVC')
|
||||
. implode(';', array_merge(array($servicegroup), $this->getArguments()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
<?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}}}
|
||||
|
||||
namespace Icinga\Module\Monitoring\Command;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Command;
|
||||
|
||||
/**
|
||||
* Command to submit passive check results
|
||||
*/
|
||||
class SubmitPassiveCheckresultCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The plugin-state that is being reported
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $state;
|
||||
|
||||
/**
|
||||
* The output that is included
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* The performance data that is included
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $perfData;
|
||||
|
||||
/**
|
||||
* Initialises a new command object to submit a passive check result
|
||||
*
|
||||
* @param int $state The plugin-state to report
|
||||
* @param string $output The plugin-output to include
|
||||
* @param string $perfData The performance data to include
|
||||
*/
|
||||
public function __construct($state, $output, $perfData)
|
||||
{
|
||||
$this->state = $state;
|
||||
$this->output = $output;
|
||||
$this->perfData = $perfData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which plugin-state is being reported
|
||||
*
|
||||
* @param int $state
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setState($state)
|
||||
{
|
||||
$this->state = (int) $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plugin-output to include in the result
|
||||
*
|
||||
* @param string $output
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setOutput($output)
|
||||
{
|
||||
$this->output = (string) $output;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the performance data to include in the result
|
||||
*
|
||||
* @param string $perfData
|
||||
* @return self
|
||||
*/
|
||||
public function setPerformanceData($perfData)
|
||||
{
|
||||
$this->perfData = (string) $perfData;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
* @return array
|
||||
* @see Command::getArguments()
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return array(
|
||||
$this->state,
|
||||
$this->perfData ? $this->output . '|' . $this->perfData : $this->output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getHostCommand()
|
||||
*/
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
return 'PROCESS_HOST_CHECK_RESULT;' . implode(';', array_merge(array($hostname), $this->getArguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string with the given host and service being inserted
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param string $servicename The name of the service to insert
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
* @see Command::getServiceCommand()
|
||||
*/
|
||||
public function getServiceCommand($hostname, $servicename)
|
||||
{
|
||||
return 'PROCESS_SERVICE_CHECK_RESULT;' . implode(
|
||||
';',
|
||||
array_merge(
|
||||
array($hostname, $servicename),
|
||||
$this->getArguments()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
||||
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Comment.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/CommandType.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/CommandPipe.php");
|
||||
require_once('../../modules/monitoring/library/Monitoring/Command/BaseCommand.php');
|
||||
require_once('../../modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php');
|
||||
|
||||
class AcknowledgementTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAcknowledgeHostMessage()
|
||||
{
|
||||
$ack = new AcknowledgeCommand(new Comment("author", "commentdata"));
|
||||
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM;foo;0;0;0;author;commentdata", $ack->getHostCommand('foo'));
|
||||
|
||||
$ack->setExpire(1000);
|
||||
$this->assertEquals("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;bar;0;0;0;1000;author;commentdata", $ack->getHostCommand('bar'));
|
||||
}
|
||||
|
||||
public function testAcknowledgeServiceMessage()
|
||||
{
|
||||
$ack = new AcknowledgeCommand(new Comment("author", "commentdata"));
|
||||
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM;foo;bar;0;0;0;author;commentdata", $ack->getServiceCommand('foo', 'bar'));
|
||||
|
||||
$ack->setExpire(1000);
|
||||
$this->assertEquals("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;bar;foo;0;0;0;1000;author;commentdata", $ack->getServiceCommand('bar', 'foo'));
|
||||
}
|
||||
}
|
|
@ -1,34 +1,58 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{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}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
require_once("./library/Icinga/LibraryLoader.php");
|
||||
require_once('./library/Icinga/LibraryLoader.php');
|
||||
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
class CommandPipeLoader extends LibraryLoader {
|
||||
|
||||
public static function requireLibrary()
|
||||
{
|
||||
require_once("Zend/Config.php");
|
||||
require_once("Zend/Log.php");
|
||||
require_once("../../library/Icinga/Application/Logger.php");
|
||||
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Comment.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/CommandType.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/CommandPipe.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Downtime.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/PropertyModifier.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Transport/Transport.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php");
|
||||
require_once("../../library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php");
|
||||
require_once('../../library/Icinga/Protocol/Commandpipe/CustomNotification.php');
|
||||
require_once('../../modules/monitoring/library/Monitoring/Command/BaseCommand.php');
|
||||
require_once('../../modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php');
|
||||
require_once('../../modules/monitoring/library/Monitoring/Command/AddCommentCommand.php');
|
||||
require_once('Zend/Config.php');
|
||||
require_once('Zend/Log.php');
|
||||
require_once(realpath('../../library/Icinga/Application/Logger.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Command.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Comment.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/CommandPipe.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/PropertyModifier.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Transport/Transport.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/AddCommentCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/ScheduleDowntimeCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php'));
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -1,35 +1,61 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{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}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
require_once(__DIR__.'/CommandPipeLoader.php');
|
||||
require_once(realpath(__DIR__ . '/CommandPipeLoader.php'));
|
||||
CommandPipeLoader::requireLibrary();
|
||||
|
||||
use Zend_Config;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Protocol\Commandpipe\CustomNotification;
|
||||
use Icinga\Protocol\Commandpipe\Downtime as Downtime;
|
||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||
use Icinga\Protocol\Ldap\Exception;
|
||||
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
||||
use Icinga\Module\Monitoring\Command\AddCommentCommand;
|
||||
use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand;
|
||||
use Icinga\Module\Monitoring\Command\CustomNotificationCommand;
|
||||
use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
||||
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
||||
use Icinga\Module\Monitoring\Command\SubmitPassiveCheckresultCommand;
|
||||
|
||||
if(!defined("EXTCMD_TEST_BIN"))
|
||||
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
||||
if (!defined('EXTCMD_TEST_BIN')) {
|
||||
define('EXTCMD_TEST_BIN', './bin/extcmd_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Several tests for the command pipe component
|
||||
*
|
||||
* Uses the helper script extcmd_test, which is basically the extracted command
|
||||
* parser functions from the icinga core
|
||||
*
|
||||
*
|
||||
*/
|
||||
class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
||||
class CommandPipeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Return the path of the test pipe used in these tests
|
||||
|
@ -38,7 +64,7 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function getPipeName()
|
||||
{
|
||||
return sys_get_temp_dir()."/icinga_test_pipe";
|
||||
return sys_get_temp_dir() . '/icinga_test_pipe';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,8 +80,8 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$cfg = new Zend_Config(
|
||||
array(
|
||||
"path" => $tmpPipe,
|
||||
"name" => "test"
|
||||
'path' => $tmpPipe,
|
||||
'name' => 'test'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -63,7 +89,8 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up for the local test pipe, but with ssh as the transport layer
|
||||
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up
|
||||
* for the local test pipe, but with ssh as the transport layer
|
||||
*
|
||||
* @return Commandpipe
|
||||
*/
|
||||
|
@ -75,12 +102,12 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$cfg = new Zend_Config(
|
||||
array(
|
||||
"path" => $tmpPipe,
|
||||
"user" => "vagrant",
|
||||
"password" => "vagrant",
|
||||
"host" => 'localhost',
|
||||
"port" => 22,
|
||||
"name" => "test"
|
||||
'path' => $tmpPipe,
|
||||
'user' => 'vagrant',
|
||||
'password' => 'vagrant',
|
||||
'host' => 'localhost',
|
||||
'port' => 22,
|
||||
'name' => 'test'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -89,11 +116,11 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
/**
|
||||
* Remove the testpipe if it exists
|
||||
*
|
||||
*/
|
||||
private function cleanup() {
|
||||
if(file_exists($this->getPipeName()))
|
||||
if (file_exists($this->getPipeName())) {
|
||||
unlink($this->getPipeName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,39 +137,43 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
* (optional, leave it to just test for the return code)
|
||||
* @param bool $command The commandstring to send (optional, leave it for using the command pipe content)
|
||||
*/
|
||||
private function assertCommandSucceeded($expectedString = false,$command = false) {
|
||||
private function assertCommandSucceeded($expectedString = false, $command = false) {
|
||||
$resultCode = null;
|
||||
$resultArr = array();
|
||||
$receivedCmd = exec(EXTCMD_TEST_BIN." ".escapeshellarg($command ? $command : file_get_contents($this->getPipeName())),$resultArr,$resultCode);
|
||||
$this->assertEquals(0, $resultCode, "Submit of external command returned error : ".$receivedCmd);
|
||||
if (!$expectedString)
|
||||
return;
|
||||
$this->assertEquals(
|
||||
$expectedString,
|
||||
$receivedCmd,
|
||||
'Asserting that the command icinga received matches the command we send'
|
||||
$receivedCmd = exec(EXTCMD_TEST_BIN . ' ' . escapeshellarg(
|
||||
$command ? $command : file_get_contents($this->getPipeName())),
|
||||
$resultArr,
|
||||
$resultCode
|
||||
);
|
||||
$this->assertEquals(0, $resultCode, 'Submit of external command returned error : ' . $receivedCmd);
|
||||
if ($expectedString) {
|
||||
$this->assertEquals(
|
||||
$expectedString,
|
||||
$receivedCmd,
|
||||
'Asserting that the command icinga received matches the command we send'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether a single host acknowledgment is serialized and send correctly
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testAcknowledgeSingleHost()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
||||
$ack = new AcknowledgeCommand(new Comment('I can', 'sends teh ack'));
|
||||
$pipe->sendCommand(
|
||||
$ack,
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "hostA"
|
||||
'host_name' => 'hostA'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
||||
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack');
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -153,37 +184,37 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether multiple host and service acknowledgments are serialized and send correctly
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testAcknowledgeMultipleObjects()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
||||
$pipe->getTransport()->setOpenMode("a");
|
||||
$ack = new AcknowledgeCommand(new Comment('I can', 'sends teh ack'));
|
||||
$pipe->getTransport()->setOpenMode('a');
|
||||
$pipe->sendCommand(
|
||||
$ack,
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "hostA"
|
||||
'host_name' => 'hostA'
|
||||
),(object) array(
|
||||
"host_name" => "hostB"
|
||||
'host_name' => 'hostB'
|
||||
),(object) array(
|
||||
"host_name" => "hostC"
|
||||
'host_name' => 'hostC'
|
||||
),(object) array(
|
||||
"host_name" => "hostC",
|
||||
"service_description" => "svc"
|
||||
'host_name' => 'hostC',
|
||||
'service_description' => 'svc'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$result = explode("\n", file_get_contents($this->getPipeName()));
|
||||
$this->assertCount(5, $result, "Asserting the correct number of commands being written to the command pipe");
|
||||
$this->assertCount(5, $result, 'Asserting the correct number of commands being written to the command pipe');
|
||||
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack", $result[0]);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostB;0;0;0;I can;sends teh ack", $result[1]);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostC;0;0;0;I can;sends teh ack", $result[2]);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_SVC_PROBLEM;hostC;svc;0;0;0;I can;sends teh ack", $result[3]);
|
||||
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack', $result[0]);
|
||||
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostB;0;0;0;I can;sends teh ack', $result[1]);
|
||||
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostC;0;0;0;I can;sends teh ack', $result[2]);
|
||||
$this->assertCommandSucceeded('ACKNOWLEDGE_SVC_PROBLEM;hostC;svc;0;0;0;I can;sends teh ack', $result[3]);
|
||||
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
|
@ -204,17 +235,17 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
$pipe->sendCommand(
|
||||
new AddCommentCommand(
|
||||
new Comment(
|
||||
"Autor",
|
||||
"Comment"
|
||||
'Autor',
|
||||
'Comment'
|
||||
)
|
||||
),
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "hostA"
|
||||
'host_name' => 'hostA'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded("ADD_HOST_COMMENT;hostA;0;Autor;Comment");
|
||||
$this->assertCommandSucceeded('ADD_HOST_COMMENT;hostA;0;Autor;Comment');
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -225,18 +256,20 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether removing all hostcomments is correctly serialized and send to the command pipe
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemoveAllHostComment()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$pipe->removeComment(array(
|
||||
(object) array(
|
||||
"host_name" => "test"
|
||||
$pipe->removeComment(
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'test'
|
||||
)
|
||||
)
|
||||
));
|
||||
$this->assertCommandSucceeded("DEL_ALL_HOST_COMMENTS;test");
|
||||
);
|
||||
$this->assertCommandSucceeded('DEL_ALL_HOST_COMMENTS;test');
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -247,14 +280,21 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether removing a single host comment is correctly serialized and send to the command pipe
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemoveSpecificComment()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$pipe->removeComment(array((object) array("comment_id"=>34,"host_name"=>"test")));
|
||||
$this->assertCommandSucceeded("DEL_HOST_COMMENT;34");
|
||||
$pipe->removeComment(
|
||||
array(
|
||||
(object) array(
|
||||
'comment_id' => 34,
|
||||
'host_name' => 'test'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('DEL_HOST_COMMENT;34');
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -265,38 +305,57 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether a multiple reschedules for services and hosts are correctly serialized and send to the commandpipe
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testScheduleChecks()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$pipe->getTransport()->setOpenMode("a"); // append so we have multiple results
|
||||
$t = time();
|
||||
// normal reschedule
|
||||
$pipe->scheduleCheck(array(
|
||||
(object) array("host_name"=>"test"),
|
||||
(object) array("host_name"=>"test","service_description"=>"svc1")
|
||||
),$t);
|
||||
// forced
|
||||
$pipe->scheduleForcedCheck(array(
|
||||
(object) array("host_name"=>"test"),
|
||||
(object) array("host_name"=>"test","service_description"=>"svc1")
|
||||
),$t);
|
||||
// forced, recursive
|
||||
$pipe->scheduleForcedCheck(array(
|
||||
(object) array("host_name"=>"test"),
|
||||
),$t,true);
|
||||
$pipe->getTransport()->setOpenMode('a'); // append so we have multiple results
|
||||
$command = new ScheduleCheckCommand(5000);
|
||||
$pipe->sendCommand(
|
||||
$command,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'test'
|
||||
),
|
||||
(object) array(
|
||||
'host_name' => 'test',
|
||||
'service_description' => 'svc1'
|
||||
)
|
||||
)
|
||||
);
|
||||
$command->setForced(true);
|
||||
$pipe->sendCommand(
|
||||
$command,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'test'
|
||||
),
|
||||
(object) array(
|
||||
'host_name' => 'test',
|
||||
'service_description' => 'svc1'
|
||||
)
|
||||
)
|
||||
);
|
||||
$command->excludeHost();
|
||||
$pipe->sendCommand(
|
||||
$command,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'test'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
$this->assertCount(6,$result, "Asserting a correct number of commands being written to the commandpipe");
|
||||
|
||||
$this->assertCommandSucceeded("SCHEDULE_HOST_CHECK;test;".$t,$result[0]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_SVC_CHECK;test;svc1;".$t,$result[1]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_FORCED_HOST_CHECK;test;".$t,$result[2]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_FORCED_SVC_CHECK;test;svc1;".$t,$result[3]);
|
||||
$this->assertCommandSucceeded("SCHEDULE_FORCED_HOST_SVC_CHECKS;test;".$t,$result[4]);
|
||||
$result = explode("\n", file_get_contents($this->getPipeName()));
|
||||
$this->assertCount(6, $result, 'Asserting a correct number of commands being written to the commandpipe');
|
||||
|
||||
$this->assertCommandSucceeded('SCHEDULE_HOST_CHECK;test;5000', $result[0]);
|
||||
$this->assertCommandSucceeded('SCHEDULE_SVC_CHECK;test;svc1;5000', $result[1]);
|
||||
$this->assertCommandSucceeded('SCHEDULE_FORCED_HOST_CHECK;test;5000', $result[2]);
|
||||
$this->assertCommandSucceeded('SCHEDULE_FORCED_SVC_CHECK;test;svc1;5000', $result[3]);
|
||||
$this->assertCommandSucceeded('SCHEDULE_FORCED_HOST_SVC_CHECKS;test;5000', $result[4]);
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -307,36 +366,39 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether modifying monitoringflags of a host and service is correctly serialized and send to the command pipe
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testObjectStateModifications()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$pipe->getTransport()->setOpenMode("a");
|
||||
$pipe->setMonitoringProperties(array(
|
||||
$pipe->getTransport()->setOpenMode('a');
|
||||
$pipe->setMonitoringProperties(
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
'host_name' => 'Testhost'
|
||||
),
|
||||
(object) array(
|
||||
"host_name" => "host",
|
||||
"service_description" => "svc"
|
||||
'host_name' => 'host',
|
||||
'service_description' => 'svc'
|
||||
)
|
||||
), new MONFLAG(array(
|
||||
MONFLAG::ACTIVE => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::PASSIVE => MONFLAG::STATE_ENABLE,
|
||||
MONFLAG::NOTIFICATIONS => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::EVENTHANDLER => MONFLAG::STATE_ENABLE,
|
||||
MONFLAG::FLAPPING => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::FRESHNESS => MONFLAG::STATE_ENABLE,
|
||||
))
|
||||
), new MONFLAG(
|
||||
array(
|
||||
MONFLAG::ACTIVE => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::PASSIVE => MONFLAG::STATE_ENABLE,
|
||||
MONFLAG::NOTIFICATIONS => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::EVENTHANDLER => MONFLAG::STATE_ENABLE,
|
||||
MONFLAG::FLAPPING => MONFLAG::STATE_DISABLE,
|
||||
MONFLAG::FRESHNESS => MONFLAG::STATE_ENABLE,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
$result = explode("\n", file_get_contents($this->getPipeName()));
|
||||
array_pop($result); // remove empty last line
|
||||
$this->assertCount(12,$result, "Asserting a correct number of commands being written to the commandpipe");
|
||||
$this->assertCount(12, $result, 'Asserting a correct number of commands being written to the commandpipe');
|
||||
foreach ($result as $command) {
|
||||
$this->assertCommandSucceeded(false,$command);
|
||||
$this->assertCommandSucceeded(false, $command);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
@ -349,16 +411,16 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether enabling and disabling global notifications are send correctly to the pipe
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGlobalNotificationTrigger()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$pipe->enableGlobalNotifications();
|
||||
$this->assertCommandSucceeded("ENABLE_NOTIFICATIONS;");
|
||||
$this->assertCommandSucceeded('ENABLE_NOTIFICATIONS;');
|
||||
$pipe->disableGlobalNotifications();
|
||||
$this->assertCommandSucceeded("DISABLE_NOTIFICATIONS;");
|
||||
$this->assertCommandSucceeded('DISABLE_NOTIFICATIONS;');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -369,28 +431,84 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether host and servicedowntimes are correctly scheduled
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testScheduleDowntime()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$downtime = new Downtime(25, 26, new Comment("me", "test"));
|
||||
$pipe->scheduleDowntime(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
$downtime = new ScheduleDowntimeCommand(25, 26, new Comment('me', 'test'));
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
),$downtime);
|
||||
$this->assertCommandSucceeded("SCHEDULE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test");
|
||||
);
|
||||
$this->assertCommandSucceeded('SCHEDULE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test');
|
||||
|
||||
$pipe->scheduleDowntime(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost",
|
||||
"service_description" => "svc"
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost',
|
||||
'service_description' => 'svc'
|
||||
)
|
||||
)
|
||||
),$downtime);
|
||||
$this->assertCommandSucceeded("SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;1;0;0;me;test");
|
||||
);
|
||||
$this->assertCommandSucceeded('SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;1;0;0;me;test');
|
||||
|
||||
$downtime->excludeHost();
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('SCHEDULE_HOST_SVC_DOWNTIME;Testhost;25;26;1;0;0;me;test');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether propagated host downtimes are correctly scheduled
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSchedulePropagatedDowntime()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$downtime = new ScheduleDowntimeCommand(25, 26, new Comment('me', 'test'));
|
||||
$downtime->includeChildren();
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test');
|
||||
|
||||
$downtime->includeChildren(true, true);
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded(
|
||||
'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -401,33 +519,35 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether the removal of downtimes is correctly serialized and send to the commandpipe for hosts and services
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testRemoveDowntime()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$pipe->getTransport()->setOpenMode("a");
|
||||
$pipe->removeDowntime(array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
),
|
||||
(object) array(
|
||||
"host_name" => "host",
|
||||
"service_description" => "svc"
|
||||
),
|
||||
(object) array(
|
||||
"host_name" => "host",
|
||||
"service_description" => "svc",
|
||||
"downtime_id" => 123
|
||||
$pipe->getTransport()->setOpenMode('a');
|
||||
$pipe->removeDowntime(
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
),
|
||||
(object) array(
|
||||
'host_name' => 'host',
|
||||
'service_description' => 'svc'
|
||||
),
|
||||
(object) array(
|
||||
'host_name' => 'host',
|
||||
'service_description' => 'svc',
|
||||
'downtime_id' => 123
|
||||
)
|
||||
)
|
||||
));
|
||||
$result = explode("\n",file_get_contents($this->getPipeName()));
|
||||
);
|
||||
$result = explode("\n", file_get_contents($this->getPipeName()));
|
||||
array_pop($result); // remove empty last line
|
||||
$this->assertCount(3,$result, "Asserting a correct number of commands being written to the commandpipe");
|
||||
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;Testhost",$result[0]);
|
||||
$this->assertCommandSucceeded("DEL_DOWNTIME_BY_HOST_NAME;host;svc",$result[1]);
|
||||
$this->assertCommandSucceeded("DEL_SVC_DOWNTIME;123",$result[2]);
|
||||
$this->assertCount(3, $result, 'Asserting a correct number of commands being written to the commandpipe');
|
||||
$this->assertCommandSucceeded('DEL_DOWNTIME_BY_HOST_NAME;Testhost', $result[0]);
|
||||
$this->assertCommandSucceeded('DEL_DOWNTIME_BY_HOST_NAME;host;svc', $result[1]);
|
||||
$this->assertCommandSucceeded('DEL_SVC_DOWNTIME;123', $result[2]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
|
@ -439,22 +559,23 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether custom servicenotifications are correctly send to the commandpipe without options
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSendCustomServiceNotification()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$notification = new CustomNotification('Author', 'Comment');
|
||||
$pipe->sendCustomNotification(array(
|
||||
(object) array(
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
$notification = new CustomNotificationCommand(new Comment('Author', 'Comment'));
|
||||
$pipe->sendCommand(
|
||||
$notification,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
)
|
||||
)
|
||||
), $notification);
|
||||
$this->assertCommandSucceeded(
|
||||
'SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;0;Author;Comment'
|
||||
);
|
||||
$this->assertCommandSucceeded('SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;0;Author;Comment');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -465,22 +586,99 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test whether custom hostnotifications are correctly send to the commandpipe with a varlist of options
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSendCustomHostNotificationWithOptions()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$notification = new CustomNotification('Author', 'Comment', true, true);
|
||||
$pipe->sendCustomNotification(array(
|
||||
(object) array(
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
$notification = new CustomNotificationCommand(new Comment('Author', 'Comment'), true, true);
|
||||
$pipe->sendCommand(
|
||||
$notification,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
)
|
||||
)
|
||||
), $notification);
|
||||
$this->assertCommandSucceeded(
|
||||
'SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;3;Author;Comment'
|
||||
);
|
||||
$this->assertCommandSucceeded('SEND_CUSTOM_SVC_NOTIFICATION;Host;Service;3;Author;Comment');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether commands to delay notifications are being sent to the commandpipe
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testDelayNotification()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$delay = new DelayNotificationCommand(300);
|
||||
$pipe->sendCommand(
|
||||
$delay,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('DELAY_SVC_NOTIFICATION;Host;Service;300');
|
||||
|
||||
$pipe->sendCommand(
|
||||
$delay,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Host'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('DELAY_HOST_NOTIFICATION;Host;300');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether commands to submit passive check results are being sent to the commandpipe
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSubmitPassiveCheckresult()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$result = new SubmitPassiveCheckresultCommand(0, 'foo', 'bar');
|
||||
$pipe->sendCommand(
|
||||
$result,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Host',
|
||||
'service_description' => 'Service'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('PROCESS_SERVICE_CHECK_RESULT;Host;Service;0;foo|bar');
|
||||
|
||||
$result->setOutput('foobar');
|
||||
$result->setPerformanceData('');
|
||||
$pipe->sendCommand(
|
||||
$result,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Host'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('PROCESS_HOST_CHECK_RESULT;Host;0;foobar');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -491,26 +689,24 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Test sending of commands via SSH (currently disabled)
|
||||
*
|
||||
* @throws \Exception|Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSSHCommands()
|
||||
{
|
||||
$this->markTestSkipped("This test assumes running in a vagrant VM with key-auth");
|
||||
$this->markTestSkipped('This test assumes running in a vagrant VM with key-auth');
|
||||
|
||||
if (!is_dir("/vagrant")) {
|
||||
}
|
||||
$pipe = $this->getSSHTestPipe();
|
||||
try {
|
||||
$ack = new AcknowledgeCommand(new Comment("I can", "sends teh ack"));
|
||||
$ack = new AcknowledgeCommand(new Comment('I can', 'sends teh ack'));
|
||||
$pipe->sendCommand(
|
||||
$ack,
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "hostA"
|
||||
'host_name' => 'hostA'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded("ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack");
|
||||
$this->assertCommandSucceeded('ACKNOWLEDGE_HOST_PROBLEM;hostA;0;0;0;I can;sends teh ack');
|
||||
} catch(Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
@ -518,4 +714,3 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
$this->cleanup();
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreStop
|
||||
|
|
Loading…
Reference in New Issue