monitoring/commands: Add object command classes

refs #6593
This commit is contained in:
Eric Lippmann 2014-09-11 17:18:07 +02:00
parent 92571599df
commit 3845301dfb
14 changed files with 1179 additions and 0 deletions

View File

@ -0,0 +1,145 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Acknowledge a host or service problem
*/
class AcknowledgeProblemCommand extends WithCommentCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
/**
* Whether the acknowledgement is sticky
*
* Sticky acknowledgements remain until the host or service recovers. Non-sticky acknowledgements will be
* automatically removed when the host or service state changes.
*
* @var bool
*/
protected $sticky = false;
/**
* Whether to send a notification about the acknowledgement
* @var bool
*/
protected $notify = false;
/**
* Whether the comment associated with the acknowledgement is persistent
*
* Persistent comments are not lost the next time the monitoring host restarts.
*
* @var bool
*/
protected $persistent = false;
/**
* Optional time when the acknowledgement should expire
*
* @var int|null
*/
protected $expireTime;
/**
* Set whether the acknowledgement is sticky
*
* @param bool $sticky
*
* @return $this
*/
public function setSticky($sticky = true)
{
$this->sticky = (bool) $sticky;
return $this;
}
/**
* Is the acknowledgement sticky?
*
* @return bool
*/
public function getSticky()
{
return $this->sticky;
}
/**
* Set whether to send a notification about the acknowledgement
*
* @param bool $notify
*
* @return $this
*/
public function setNotify($notify = true)
{
$this->notify = (bool) $notify;
return $this;
}
/**
* Get whether to send a notification about the acknowledgement
*
* @return bool
*/
public function getNotify()
{
return $this->notify;
}
/**
* Set whether the comment associated with the acknowledgement is persistent
*
* @param bool $persistent
*
* @return $this
*/
public function setPersistent($persistent = true)
{
$this->persistent = (bool) $persistent;
return $this;
}
/**
* Is the comment associated with the acknowledgement is persistent?
*
* @return bool
*/
public function getPersistent()
{
return $this->persistent;
}
/**
* Set the time when the acknowledgement should expire
*
* @param int $expireTime
*
* @return $this
*/
public function setExpireTime($expireTime)
{
$this->expireTime = (int) $expireTime;
return $this;
}
/**
* Get the time when the acknowledgement should expire
*
* @return int|null
*/
public function getExpireTime()
{
return $this->expireTime;
}
}

View File

@ -0,0 +1,50 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Add a comment to a host or service
*/
class AddCommentCommand extends WithCommentCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
/**
* Whether the comment is persistent
*
* Persistent comments are not lost the next time the monitoring host restarts.
*/
protected $persistent;
/**
* Set whether the comment is persistent
*
* @param bool $persistent
*
* @return $this
*/
public function setPersistent($persistent = true)
{
$this->persistent = $persistent;
return $this;
}
/**
* Is the comment persistent?
*
* @return bool
*/
public function getPersistent()
{
return $this->persistent;
}
}

View File

@ -0,0 +1,50 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Delete a host or service comment
*/
class DeleteCommentCommand extends ObjectCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
/**
* ID of the comment that is to be deleted
*
* @var int
*/
protected $commentId;
/**
* Set the ID of the comment that is to be deleted
*
* @param int $commentId
*
* @return $this
*/
public function setCommentId($commentId)
{
$this->commentId = (int) $commentId;
return $this;
}
/**
* Get the ID of the comment that is to be deleted
*
* @return int
*/
public function getCommentId()
{
return $this->commentId;
}
}

View File

@ -0,0 +1,50 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Delete a host or service downtime
*/
class DeleteDowntimeCommand extends ObjectCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
/**
* ID of the downtime that is to be deleted
*
* @var int
*/
protected $downtimeId;
/**
* Set the ID of the downtime that is to be deleted
*
* @param int $downtimeId
*
* @return $this
*/
public function setDowntimeId($downtimeId)
{
$this->downtimeId = (int) $downtimeId;
return $this;
}
/**
* Get the ID of the downtime that is to be deleted
*
* @return int
*/
public function getDowntimeId()
{
return $this->downtimeId;
}
}

View File

@ -0,0 +1,62 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
use Icinga\Module\Monitoring\Command\IcingaCommand;
use Icinga\Module\Monitoring\Object\MonitoredObject;
/**
* Base class for commands that involve a monitored object, i.e. a host or service
*/
abstract class ObjectCommand extends IcingaCommand
{
/**
* Type host
*/
const TYPE_HOST = MonitoredObject::TYPE_HOST;
/**
* Type service
*/
const TYPE_SERVICE = MonitoredObject::TYPE_SERVICE;
/**
* Allowed Icinga object types for the command
*
* @var string[]
*/
protected $allowedObjects = array();
/**
* Involved object
*
* @var MonitoredObject
*/
protected $object;
/**
* Set the involved object
*
* @param MonitoredObject $object
*
* @return $this
*/
public function setObject(MonitoredObject $object)
{
$object->assertOneOf($this->allowedObjects);
$this->object = $object;
return $this;
}
/**
* Get the involved object
*
* @return MonitoredObject
*/
public function getObject()
{
return $this->object;
}
}

View File

@ -0,0 +1,177 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
use InvalidArgumentException;
use LogicException;
/**
* Submit a passive check result for a host or service
*/
class ProcessCheckResultCommand extends ObjectCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
/**
* Host up
*/
const HOST_UP = 0;
/**
* Host down
*/
const HOST_DOWN = 1;
/**
* Host unreachable
*/
const HOST_UNREACHABLE = 2;
/**
* Service ok
*/
const SERVICE_OK = 0;
/**
* Service warning
*/
const SERVICE_WARNING = 1;
/**
* Service critical
*/
const SERVICE_CRITICAL = 2;
/**
* Service unknown
*/
const SERVICE_UNKNOWN = 3;
/**
* Possible status codes for passive host and service checks
*
* @var array
*/
public static $statusCodes = array(
self::TYPE_HOST => array(
self::HOST_UP, self::HOST_DOWN, self::HOST_UNREACHABLE
),
self::TYPE_SERVICE => array(
self::SERVICE_OK, self::SERVICE_WARNING, self::SERVICE_CRITICAL, self::SERVICE_UNKNOWN
)
);
/**
* Status code of the host or service check result
*
* @var int
*/
protected $status;
/**
* Text output of the host or service check result
*
* @var string
*/
protected $output;
/**
* Optional performance data of the host or service check result
*
* @var string
*/
protected $performanceData;
/**
* Set the status code of the host or service check result
*
* @param int $status
*
* @return $this
*
* @throws LogicException If the object is null
* @throws InvalidArgumentException If status is not one of the valid status codes for the object's type
*/
public function setStatus($status)
{
if ($this->object === null) {
throw new LogicException('You\'re required to call setObject() before calling setStatus()');
}
$status = (int) $status;
if (! in_array($status, self::$statusCodes[$this->object->getType()])) {
throw new InvalidArgumentException(sprintf(
'The status code %u you provided is not one of the valid status codes for type %s',
$status,
$this->object->getType()
));
}
$this->status = $status;
return $this;
}
/**
* Get the status code of the host or service check result
*
* @return int
*/
public function getStatus()
{
return $this->status;
}
/**
* Set the text output of the host or service check result
*
* @param string $output
*
* @return $this
*/
public function setOutput($output)
{
$this->output = (string) $output;
return $this;
}
/**
* Get the text output of the host or service check result
*
* @return string
*/
public function getOutput()
{
return $this->output;
}
/**
* Set the performance data of the host or service check result
*
* @param string $performanceData
*
* @return $this
*/
public function setPerformanceData($performanceData)
{
$this->performanceData = (string) $performanceData;
return $this;
}
/**
* Get the performance data of the host or service check result
*
* @return string
*/
public function getPerformanceData()
{
return $this->performanceData;
}
}

View File

@ -0,0 +1,49 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Schedule and propagate host downtime
*/
class PropagateHostDowntimeCommand extends ScheduleServiceDowntimeCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST
);
/**
* Whether the downtime for child hosts are all set to be triggered by this' host downtime
*
* @var bool
*/
protected $triggered = false;
/**
* Set whether the downtime for child hosts are all set to be triggered by this' host downtime
*
* @param bool $triggered
*
* @return $this
*/
public function setTriggered($triggered = true)
{
$this->triggered = (bool) $triggered;
return $this;
}
/**
* Get whether the downtime for child hosts are all set to be triggered by this' host downtime
*
* @return bool
*/
public function getTriggered()
{
return $this->triggered;
}
}

View File

@ -0,0 +1,20 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Remove a problem acknowledgement from a host or service
*/
class RemoveAcknowledgementCommand extends ObjectCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
}

View File

@ -0,0 +1,49 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Schedule a host check
*/
class ScheduleHostCheckCommand extends ScheduleServiceCheckCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST
);
/**
* Whether to schedule a check of all services associated with a particular host
*
* @var bool
*/
protected $ofAllServices = false;
/**
* Set whether to schedule a check of all services associated with a particular host
*
* @param bool $ofAllServices
*
* @return $this
*/
public function setOfAllServices($ofAllServices = true)
{
$this->ofAllServices = (bool) $ofAllServices;
return $this;
}
/**
* Get whether to schedule a check of all services associated with a particular host
*
* @return bool
*/
public function getOfAllServices()
{
return $this->ofAllServices;
}
}

View File

@ -0,0 +1,49 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Schedule a host downtime
*/
class ScheduleHostDowntimeCommand extends ScheduleServiceDowntimeCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST
);
/**
* Whether to schedule a downtime for all services associated with a particular host
*
* @var bool
*/
protected $forAllServices = false;
/**
* Set whether to schedule a downtime for all services associated with a particular host
*
* @param bool $forAllServices
*
* @return $this
*/
public function setForAllServices($forAllServices = true)
{
$this->forAllServices = (bool) $forAllServices;
return $this;
}
/**
* Get whether to schedule a downtime for all services associated with a particular host
*
* @return bool
*/
public function getForAllServices()
{
return $this->forAllServices;
}
}

View File

@ -0,0 +1,102 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Schedule a service check
*/
class ScheduleServiceCheckCommand extends ObjectCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_SERVICE
);
/**
* Time when the next check of a host or service is to be scheduled
*
* If active checks are disabled on a host- or service-specific or program-wide basis or the host or service is
* already scheduled to be checked at an earlier time, etc. The check may not actually be scheduled at the time
* specified. This behaviour can be overridden by setting `ScheduledCheck::$forced' to true.
*
* @var int Unix timestamp
*/
protected $checkTime;
/**
* Whether the check is forced
*
* Forced checks are performed regardless of what time it is (e.g. time period restrictions are ignored) and whether
* or not active checks are enabled on a host- or service-specific or program-wide basis.
*
* @var bool
*/
protected $forced = false;
/**
* Whether to schedule a check of all services associated with a particular host
*
* @var bool
*/
protected $ofAllServices = false;
/**
* Set the time when the next check of a host or service is to be scheduled
*
* @param int $checkTime Unix timestamp
*
* @return $this
*/
public function setCheckTime($checkTime)
{
$this->checkTime = (int) $checkTime;
return $this;
}
/**
* Get the time when the next check of a host or service is to be scheduled
*
* @return int Unix timestamp
*/
public function getCheckTime()
{
return $this->checkTime;
}
/**
* Set whether the check is forced
*
* @param bool $forced
*
* @return $this
*/
public function setForced($forced = true)
{
$this->forced = (bool) $forced;
return $this;
}
/**
* Is the check forced?
*
* @return bool
*/
public function getForced()
{
return $this->forced;
}
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\IcingaCommand::getName() For the method documentation.
*/
public function getName()
{
return 'ScheduleCheck';
}
}

View File

@ -0,0 +1,191 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Schedule a service downtime
*/
class ScheduleServiceDowntimeCommand extends AddCommentCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_SERVICE
);
/**
* Downtime starts at the exact time specified
*
* If `Downtime::$fixed' is set to false, the time between `Downtime::$start' and `Downtime::$end' at which a
* host or service transitions to a problem state determines the time at which the downtime actually starts.
* The downtime will then last for `Downtime::$duration' seconds.
*
* @var int Unix timestamp
*/
protected $start;
/**
* Downtime ends at the exact time specified
*
* If `Downtime::$fixed' is set to false, the time between `Downtime::$start' and `Downtime::$end' at which a
* host or service transitions to a problem state determines the time at which the downtime actually starts.
* The downtime will then last for `Downtime::$duration' seconds.
*
* @var int Unix timestamp
*/
protected $end;
/**
* Whether it's a fixed or flexible downtime
*
* @var bool
*/
protected $fixed = true;
/**
* ID of the downtime which triggers this downtime
*
* The start of this downtime is triggered by the start of the other scheduled host or service downtime.
*
* @var int|null
*/
protected $triggerId;
/**
* The duration in seconds the downtime must last if it's a flexible downtime
*
* If `Downtime::$fixed' is set to false, the downtime will last for the duration in seconds specified, even
* if the host or service recovers before the downtime expires.
*
* @var int|null
*/
protected $duration;
/**
* Set the time when the downtime should start
*
* @param int $start Unix timestamp
*
* @return $this
*/
public function setStart($start)
{
$this->start = (int) $start;
return $this;
}
/**
* Get the time when the downtime should start
*
* @return int Unix timestamp
*/
public function getStart()
{
return $this->start;
}
/**
* Set the time when the downtime should end
*
* @param int $end Unix timestamp
*
* @return $this
*/
public function setEnd($end)
{
$this->end = (int) $end;
return $this;
}
/**
* Get the time when the downtime should end
*
* @return int Unix timestamp
*/
public function getEnd()
{
return $this->end;
}
/**
* Set whether it's a fixed or flexible downtime
*
* @param boolean $fixed
*
* @return $this
*/
public function setFixed($fixed = true)
{
$this->fixed = (bool) $fixed;
return $this;
}
/**
* Is the downtime fixed?
*
* @return boolean
*/
public function getFixed()
{
return $this->fixed;
}
/**
* Set the ID of the downtime which triggers this downtime
*
* @param int $triggerId
*
* @return $this
*/
public function setTriggerId($triggerId)
{
$this->triggerId = (int) $triggerId;
return $this;
}
/**
* Get the ID of the downtime which triggers this downtime
*
* @return int|null
*/
public function getTriggerId()
{
return $this->triggerId;
}
/**
* Set the duration in seconds the downtime must last if it's a flexible downtime
*
* @param int $duration
*
* @return $this
*/
public function setDuration($duration)
{
$this->duration = (int) $duration;
return $this;
}
/**
* Get the duration in seconds the downtime must last if it's a flexible downtime
*
* @return int|null
*/
public function getDuration()
{
return $this->duration;
}
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\IcingaCommand::getName() For the method documentation.
*/
public function getName()
{
return 'ScheduleDowntime';
}
}

View File

@ -0,0 +1,114 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Enable or disable a feature of an Icinga object, i.e. host or service
*/
class ToggleObjectFeatureCommand extends ObjectCommand
{
/**
* (non-PHPDoc)
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
*/
protected $allowedObjects = array(
self::TYPE_HOST,
self::TYPE_SERVICE
);
/**
* Feature for enabling or disabling active checks of a host or service
*/
const FEATURE_ACTIVE_CHECKS = 'active_checks_enabled';
/**
* Feature for enabling or disabling passive checks of a host or service
*/
const FEATURE_PASSIVE_CHECKS = 'passive_checks_enabled';
/**
* Feature for enabling or disabling processing of host or service checks via the OCHP command for a host or service
*/
const FEATURE_OBSESSING = 'obsessing';
/**
* Feature for enabling or disabling notifications for a host or service
*
* Notifications will be sent out only if notifications are enabled on a program-wide basis as well.
*/
const FEATURE_NOTIFICATIONS = 'notifications_enabled';
/**
* Feature for enabling or disabling event handler for a host or service
*/
const FEATURE_EVENT_HANDLER = 'event_handler_enabled';
/**
* Feature for enabling or disabling flap detection for a host or service.
*
* In order to enable flap detection flap detection must be enabled on a program-wide basis as well.
*/
const FEATURE_FLAP_DETECTION = 'flap_detection_enabled';
/**
* Feature that is to be enabled or disabled
*
* @var string
*/
protected $feature;
/**
* Whether the feature should be enabled or disabled
*
* @var bool
*/
protected $enabled;
/**
* Set the feature that is to be enabled or disabled
*
* @param string $feature
*
* @return $this
*/
public function setFeature($feature)
{
$this->feature = (string) $feature;
return $this;
}
/**
* Get the feature that is to be enabled or disabled
*
* @return string
*/
public function getFeature()
{
return $this->feature;
}
/**
* Set whether the feature should be enabled or disabled
*
* @param bool $enabled
*
* @return $this
*/
public function setEnabled($enabled = true)
{
$this->enabled = (bool) $enabled;
return $this;
}
/**
* Get whether the feature should be enabled or disabled
*
* @return bool
*/
public function getEnabled()
{
return $this->enabled;
}
}

View File

@ -0,0 +1,71 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Command\Object;
/**
* Base class for commands adding comments
*/
abstract class WithCommentCommand extends ObjectCommand
{
/**
* Author of the comment
*
* @var string
*/
protected $author;
/**
* Comment
*
* @var string
*/
protected $comment;
/**
* Set the author
*
* @param string $author
*
* @return $this
*/
public function setAuthor($author)
{
$this->author = (string) $author;
return $this;
}
/**
* Get the author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set the comment
*
* @param string $comment
*
* @return $this
*/
public function setComment($comment)
{
$this->comment = (string) $comment;
return $this;
}
/**
* Get the comment
*
* @return string
*/
public function getComment()
{
return $this->comment;
}
}