Code style and comment fixes

refs #4441
This commit is contained in:
Jannis Moßhammer 2013-08-01 17:48:36 +02:00 committed by Marius Hein
parent 81c2f3b9de
commit 4f1e6ec720
11 changed files with 385 additions and 111 deletions

View File

@ -32,33 +32,43 @@ use \Icinga\Protocol\Commandpipe\Exception\InvalidCommandException;
use \Icinga\Protocol\Commandpipe\Comment;
/**
* Class Acknowledgement
* @package Icinga\Protocol\Commandpipe
* Container for a host/service Acknowledgement
*
*/
class Acknowledgement implements IComment
{
/**
* The expire time of this acknowledgement or -1 if no expire time is used
*
* @var int
*/
public $expireTime = -1;
private $expireTime = -1;
/**
* Whether to set the notify flag of the acknowledgment
*
* @var bool
*/
public $notify = false;
private $notify = false;
/**
* The comment text of this acknowledgment
*
* @var Comment|null
*/
public $comment = null;
private $comment = null;
/**
* true if this is a sticky acknowledgment
*
* @var bool
*/
public $sticky;
/**
* @param int $time
* Set the expire time of this acknowledgment to $time
*
* @param int $time The new expire time as a UNIX timestamp
*/
public function setExpireTime($time)
{
@ -66,7 +76,9 @@ class Acknowledgement implements IComment
}
/**
* @param boolean $bool
* Set the notify flag of this object
*
* @param boolean $bool True if notify should be set, otherwise false
*/
public function setNotify($bool)
{
@ -74,10 +86,12 @@ class Acknowledgement implements IComment
}
/**
* @param Comment $comment
* @param bool $notify
* @param $expire
* @param bool $sticky
* Create a new acknowledgment container
*
* @param Comment $comment The comment to use for the acknowledgement
* @param bool $notify Whether to set the notify flag
* @param $expire The expire time or -1 of not expiring
* @param bool $sticky Whether to set the sticky flag
*/
public function __construct(Comment $comment, $notify = false, $expire = -1, $sticky = false)
{
@ -88,9 +102,10 @@ class Acknowledgement implements IComment
}
/**
* @param $type
* @return string
* @throws Exception\InvalidCommandException
* Return the ACKNOWLEDGE_?_PROBLEM string to be used for submitting an external icinga command
*
* @param $type Either CommandPipe::TYPE_HOST or CommandPipe:: TYPE_SERVICE
* @return string The command string to be submitted to the command pipe
*/
public function getFormatString($type)
{

View File

@ -35,14 +35,24 @@ use Icinga\Protocol\Commandpipe\Transport\LocalPipe;
use Icinga\Protocol\Commandpipe\Transport\SecureShell;
/**
* Class CommandPipe
* @package Icinga\Protocol\Commandpipe
* Class to the access icinga CommandPipe via a @see Icinga\Protocol\Commandpipe\Transport.php
*
* Will be configured using the instances.ini
*/
class CommandPipe
{
/**
* The name of this class as defined in the instances.ini
*
* @var string
*/
private $name = "";
/**
* The underlying @see Icinga\Protocol\Commandpipe\Transport.php class handling communication with icinga
*
* @var Icinga\Protocol\Commandpipe\Transport
*/
private $transport = null;
/**
@ -87,6 +97,8 @@ class CommandPipe
const NOTIFY_INCREMENT = 4;
/**
* Create a new CommandPipe class which accesses the icinga.cmd pipe as defined in $config
*
* @param \Zend_Config $config
*/
public function __construct(\Zend_Config $config)
@ -95,11 +107,17 @@ class CommandPipe
$this->name = $config->name;
}
private function getTransportForConfiguration(\Zend_Config $config, $transport = null)
/**
* Setup the @see Icinga\Protocol\Commandpipe\Transport.php class that will be used for accessing the command pipe
*
* Currently this method uses SecureShell when a host is given, otherwise it assumes the pipe is accessible
* via the machines filesystem
*
* @param \Zend_Config $config The configuration as defined in the instances.ini
*/
private function getTransportForConfiguration(\Zend_Config $config)
{
if ($transport != null) {
$this->transport = $transport;
} else if (isset($config->host)) {
if (isset($config->host)) {
$this->transport = new SecureShell();
$this->transport->setEndpoint($config);
} else {
@ -109,8 +127,11 @@ class CommandPipe
}
/**
* @param $command
* @throws \RuntimeException
* Send the command string $command to the icinga pipe
*
* This method just delegates the send command to the underlying transport
*
* @param String $command The command string to send, without the timestamp
*/
public function send($command)
{
@ -118,8 +139,12 @@ class CommandPipe
}
/**
* @param $objects
* @param IComment $acknowledgementOrComment
* Acknowledge a set of monitoring objects
*
* $objects can be a mixed array of host and service objects
*
* @param array $objects An array of host and service objects
* @param IComment $acknowledgementOrComment An acknowledgement or comment object to use as the comment
*/
public function acknowledge($objects, IComment $acknowledgementOrComment)
{
@ -139,7 +164,9 @@ class CommandPipe
}
/**
* @param $objects
* Remove the acknowledgements of the provided objects
*
* @param array $objects An array of mixed service and host objects whose acknowledgments will be removed
*/
public function removeAcknowledge($objects)
{
@ -153,9 +180,12 @@ class CommandPipe
}
/**
* @param $objects
* @param $state
* @param $output
* 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 = "")
{
@ -172,9 +202,11 @@ class CommandPipe
}
/**
* @param $objects
* @param bool $time
* @param bool $withChilds
* 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)
{
@ -192,9 +224,11 @@ class CommandPipe
}
/**
* @param $objects
* @param bool $time
* @param bool $withChilds
* 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)
{
@ -212,8 +246,10 @@ class CommandPipe
}
/**
* @param array $objects
* @param Comment $comment
* Add a comment to all submitted objects
*
* @param array $objects An array of hosts and services to add a comment for
* @param Comment $comment The comment object to add
*/
public function addComment(array $objects, Comment $comment)
{
@ -230,7 +266,10 @@ class CommandPipe
}
/**
* @param $objectsOrComments
* Removes the submitted comments
*
* @param array $objectsOrComments An array of hosts and services (to remove all their comments)
* or single comment objects to remove
*/
public function removeComment($objectsOrComments)
{
@ -258,6 +297,7 @@ class CommandPipe
}
/**
* Globally enable notifications for this instance
*
*/
public function enableGlobalNotifications()
@ -266,6 +306,7 @@ class CommandPipe
}
/**
* Globally disable notifications for this instance
*
*/
public function disableGlobalNotifications()
@ -274,8 +315,10 @@ class CommandPipe
}
/**
* @param $object
* @return string
* Return the object type of the provided object (TYPE_SERVICE or TYPE_HOST)
*
* @param $object The object to identify
* @return string TYPE_SERVICE or TYPE_HOST
*/
private function getObjectType($object)
{
@ -287,8 +330,10 @@ class CommandPipe
}
/**
* @param $objects
* @param Downtime $downtime
* 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)
{
@ -305,8 +350,10 @@ class CommandPipe
}
/**
* @param $objects
* @param int $starttime
* Remove downtimes for objects
*
* @param array $objects An array containing hosts, service or downtime objects
* @param int $starttime An optional starttime to use for the DEL_DOWNTIME_BY_HOST_NAME command
*/
public function removeDowntime($objects, $starttime = 0)
{
@ -328,6 +375,7 @@ class CommandPipe
}
/**
* Restart the icinga instance
*
*/
public function restartIcinga()
@ -336,8 +384,10 @@ class CommandPipe
}
/**
* @param $objects
* @param PropertyModifier $flags
* Modify monitoring flags for the provided objects
*
* @param array $objects An arry of service and/or host objects to modify
* @param PropertyModifier $flags The Monitoring attributes to modify
*/
public function setMonitoringProperties($objects, PropertyModifier $flags)
{
@ -354,7 +404,9 @@ class CommandPipe
}
/**
* @param $objects
* Enable active checks for all provided objects
*
* @param array $objects An array containing services and hosts to enable active checks for
*/
public function enableActiveChecks($objects)
{
@ -369,7 +421,9 @@ class CommandPipe
}
/**
* @param $objects
* Disable active checks for all provided objects
*
* @param array $objects An array containing services and hosts to disable active checks
*/
public function disableActiveChecks($objects)
{
@ -384,7 +438,9 @@ class CommandPipe
}
/**
* @param $objects
* Enable passive checks for all provided objects
*
* @param array $objects An array containing services and hosts to enable passive checks for
*/
public function enablePassiveChecks($objects)
{
@ -399,7 +455,9 @@ class CommandPipe
}
/**
* @param $objects
* Enable passive checks for all provided objects
*
* @param array $objects An array containing services and hosts to enable passive checks for
*/
public function disablePassiveChecks($objects)
{
@ -414,7 +472,10 @@ class CommandPipe
}
/**
* @param $objects
* Enable flap detection for all provided objects
*
* @param array $objects An array containing services and hosts to enable flap detection
*
*/
public function enableFlappingDetection($objects)
{
@ -429,7 +490,10 @@ class CommandPipe
}
/**
* @param $objects
* Disable flap detection for all provided objects
*
* @param array $objects An array containing services and hosts to disable flap detection
*
*/
public function disableFlappingDetection($objects)
{
@ -444,7 +508,10 @@ class CommandPipe
}
/**
* @param $objects
* Enable notifications for all provided objects
*
* @param array $objects An array containing services and hosts to enable notification
*
*/
public function enableNotifications($objects)
{
@ -459,7 +526,10 @@ class CommandPipe
}
/**
* @param $objects
* Disable flap detection for all provided objects
*
* @param array $objects An array containing services and hosts to disable notifications
*
*/
public function disableNotifications($objects)
{
@ -474,7 +544,9 @@ class CommandPipe
}
/**
* @param $objects
* Enable freshness checks for all provided objects
*
* @param array $objects An array of hosts and/or services
*/
public function enableFreshnessChecks($objects)
{
@ -489,7 +561,9 @@ class CommandPipe
}
/**
* @param $objects
* Disable freshness checks for all provided objects
*
* @param array $objects An array of hosts and/or services
*/
public function disableFreshnessChecks($objects)
{
@ -504,7 +578,9 @@ class CommandPipe
}
/**
* @param $objects
* Enable event handler for all provided objects
*
* @param array $objects An array of hosts and/or services
*/
public function enableEventHandler($objects)
{
@ -519,7 +595,9 @@ class CommandPipe
}
/**
* @param $objects
* Disable event handler for all provided objects
*
* @param array $objects An array of hosts and/or services
*/
public function disableEventHandler($objects)
{
@ -534,7 +612,9 @@ class CommandPipe
}
/**
* @param $objects
* Enable performance data parsing for all provided objects
*
* @param array $objects An array of hosts and/or services
*/
public function enablePerfdata($objects)
{
@ -548,6 +628,11 @@ class CommandPipe
);
}
/**
* Disable performance data parsing for all provided objects
*
* @param array $objects An array of hosts and/or services
*/
public function disablePerfdata($objects)
{
$this->setMonitoringProperties(
@ -560,6 +645,11 @@ class CommandPipe
);
}
/**
* Start obsessing over provided services/hosts
*
* @param array $objects An array of hosts and/or services
*/
public function startObsessing($objects)
{
foreach ($objects as $object) {
@ -573,6 +663,11 @@ class CommandPipe
}
}
/**
* Stop obsessing over provided services/hosts
*
* @param array $objects An array of hosts and/or services
*/
public function stopObsessing($objects)
{
foreach ($objects as $object) {
@ -615,6 +710,11 @@ class CommandPipe
}
}
/**
* Disable notifications for all services of the provided hosts
*
* @param array $objects An array of hosts
*/
public function disableNotificationsForServices($objects)
{
foreach ($objects as $host) {
@ -623,6 +723,11 @@ class CommandPipe
}
}
/**
* Enable notifications for all services of the provided hosts
*
* @param array $objects An array of hosts
*/
public function enableNotificationsForServices($objects)
{
foreach ($objects as $host) {
@ -631,6 +736,11 @@ class CommandPipe
}
}
/**
* Disable active checks for all services of the provided hosts
*
* @param array $objects An array of hosts
*/
public function disableActiveChecksWithChildren($objects)
{
foreach ($objects as $host) {
@ -639,6 +749,11 @@ class CommandPipe
}
}
/**
* Enable active checks for all services of the provided hosts
*
* @param array $objects An array of hosts
*/
public function enableActiveChecksWithChildren($objects)
{
foreach ($objects as $host) {
@ -647,6 +762,11 @@ class CommandPipe
}
}
/**
* Rest modified attributes for all provided objects
*
* @param array $objects An array of hosts and services
*/
public function resetAttributes($objects)
{
foreach ($objects as $object) {
@ -659,6 +779,12 @@ 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) {

View File

@ -29,30 +29,38 @@
namespace Icinga\Protocol\Commandpipe;
/**
* Class Comment
* @package Icinga\Protocol\Commandpipe
* Container for comment information that can be send to icinga's external command pipe
*
*/
class Comment implements IComment
{
/**
* Whether the persistent flag should be submitted with this command
*
* @var bool
*/
public $persistent = false;
/**
* @var string
* The author of this comment
*
* @var string
*/
public $author = "";
/**
* @var string
* The comment text to use
*
* @var string
*/
public $comment = "";
/**
* @param $author
* @param $comment
* @param bool $persistent
* Create a new comment object
*
* @param string $author The author name to use for this object
* @param string $comment The comment text to use
* @param bool $persistent Whether this comment should persist icinga restarts
*/
public function __construct($author, $comment, $persistent = false)
{
@ -62,9 +70,13 @@ class Comment implements IComment
}
/**
* @param $type
* @return string
* @throws InvalidCommandException
* Return this comment as an ADD_?_COMMENT external command string that can directly be send to the command pipe
*
* @param string $type either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE
*
* @return string The ADD_HOST_COMMENT or ADD_SVC_COMMENT command, without the timestamp
*
* @throws InvalidCommandException When $type is unknown
*/
public function getFormatString($type)
{

View File

@ -29,51 +29,83 @@
namespace Icinga\Protocol\Commandpipe;
/**
* Class Downtime
* @package Icinga\Protocol\Commandpipe
* Container class containing downtime information
*
*/
class Downtime
{
const TYPE_WITH_CHILDREN = 'AND_PROPAGATE_';
const TYPE_WITH_CHILDREN_TRIGERRED = 'AND_PROPAGATE_TRIGGERED_';
const TYPE_HOST_SVC = 'HOST_SVC';
/**
* @var mixed
* 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_TRIGERRED = '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;
/**
* @var mixed
* Timestamp representing the downtime's end
*
* @var int
*/
public $endTime;
/**
* @var mixed
* Whether this is a fixed downtime
*
* @var boolean
*/
private $fixed = false;
/**
* @var mixed
* The duration of the downtime in seconds if flexible
*
* @var int
*/
public $duration;
/**
* @var mixed
* 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 (with children, with children and triggered, services etc.)
*
* @var string
*/
private $subtype = '';
/**
* @param $start
* @param $end
* @param Comment $comment
* @param int $duration
* 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)
{
@ -88,8 +120,12 @@ class Downtime
}
/**
* @param $type
* @return string
* 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)
{
@ -111,6 +147,11 @@ class Downtime
. $this->comment->comment;
}
/**
* 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;

View File

@ -29,8 +29,7 @@
namespace Icinga\Protocol\Commandpipe\Exception;
/**
* Class InvalidCommandException
* @package Icinga\Protocol\Commandpipe\Exception
* Exception class for unknown/invalid external commands
*/
class InvalidCommandException extends \Exception
{

View File

@ -29,8 +29,8 @@
namespace Icinga\Protocol\Commandpipe;
/**
* Class IComment
* @package Icinga\Protocol\Commandpipe
* Interface flagging a class as being a comment
*
*/
interface IComment
{

View File

@ -29,61 +29,62 @@
namespace Icinga\Protocol\Commandpipe;
/**
* Class PropertyModifier
* @package Icinga\Protocol\Commandpipe
* Container class to modify a few monitoring attributes at oncee
*
*/
class PropertyModifier
{
/**
*
* Set an attribute to be enabled in the command
*/
const STATE_ENABLE = 1;
/**
*
* Set an attribute to be disabled in the command
*/
const STATE_DISABLE = 0;
/**
*
* Set an attribute to not be modified in the command
*/
const STATE_KEEP = -1;
/**
*
* Template for enabling/disabling flap detection
*/
const FLAPPING = "%s_FLAP_DETECTION";
/**
*
* Template for enabling/disabling active checks
*/
const ACTIVE = "%s_CHECK";
/**
*
* Template for enabling/disabling passive checks
*/
const PASSIVE = "PASSIVE_%s_CHECKS";
/**
*
* Template for enabling/disabling notification
*/
const NOTIFICATIONS = "%s_NOTIFICATIONS";
/**
*
* Template for enabling/disabling freshness checks
*/
const FRESHNESS = "%s_FRESHNESS_CHECKS";
/**
*
* Template for enabling/disabling event handler
*/
const EVENTHANDLER = "%s_EVENT_HANDLER";
/**
* The state that will be applied when fetching this container for an object
*
* @var array
*/
public $flags = array(
private $flags = array(
self::FLAPPING => self::STATE_KEEP,
self::ACTIVE => self::STATE_KEEP,
self::PASSIVE => self::STATE_KEEP,
@ -93,7 +94,9 @@ class PropertyModifier
);
/**
* @param array $flags
* Create a new PropertyModified object using the given flags
*
* @param array $flags Flags to enable/disable/keep different monitoring attributes
*/
public function __construct(array $flags)
{
@ -105,8 +108,10 @@ class PropertyModifier
}
/**
* @param $type
* @return array
* Return this object as a template for the given object type
*
* @param $type Either CommandPipe::TYPE_HOST or CommandPipe::TYPE_SERVICE
* @return array An array of external command templates for the given type representing the containers state
*/
public function getFormatString($type)
{

View File

@ -3,16 +3,37 @@
namespace Icinga\Protocol\Commandpipe\Transport;
use Icinga\Application\Logger;
/**
* CommandPipe Transport class that writes to a file accessible by the filesystem
*
*/
class LocalPipe implements Transport
{
/**
* The path of the icinga commandpipe
*
* @var String
*/
private $path;
/**
* The mode to use for fopen()
*
* @var string
*/
private $openMode = "w";
/**
* @see Transport::setEndpoint()
*/
public function setEndpoint(\Zend_Config $config)
{
$this->path = isset($config->path) ? $config->path : '/usr/local/icinga/var/rw/icinga.cmd';
}
/**
* @see Transport::send()
*/
public function send($message)
{
Logger::debug('Attempting to send external icinga command %s to local command file ', $message, $this->path);
@ -25,6 +46,11 @@ class LocalPipe implements Transport
fclose($file);
}
/**
* Overwrite the open mode (useful for testing)
*
* @param string $mode A open mode supported by fopen()
*/
public function setOpenMode($mode)
{
$this->openMode = $mode;

View File

@ -4,14 +4,45 @@ namespace Icinga\Protocol\Commandpipe\Transport;
use Icinga\Application\Logger;
/**
* Command pipe transport class that uses ssh for connecting to a remote filesystem with the icinga.cmd pipe
* The remote host must have KeyAuth enabled for this user
*
*/
class SecureShell implements Transport
{
/**
* The remote host to connect to
*
* @var string
*/
private $host = 'localhost';
private $path = "/usr/local/icinga/var/rw/icinga.cmd";
private $port = 22;
private $user = null;
private $password = null;
/**
* The location of the icinga pipe on the remote host
*
* @var string
*/
private $path = "/usr/local/icinga/var/rw/icinga.cmd";
/**
* The SSH port of the remote host
*
* @var int
*/
private $port = 22;
/**
* The user to authenticate with on the remote host
*
* @var String
*/
private $user = null;
/**
* @see Transport::setEndpoint()
*
*/
public function setEndpoint(\Zend_Config $config)
{
$this->host = isset($config->host) ? $config->host : "localhost";
@ -21,6 +52,10 @@ class SecureShell implements Transport
$this->path = isset($config->path) ? $config->path : "/usr/local/icinga/var/rw/icinga.cmd";
}
/**
* @see Transport::send()
*
*/
public function send($command)
{
$retCode = 0;

View File

@ -2,8 +2,23 @@
namespace Icinga\Protocol\Commandpipe\Transport;
/**
* Interface for Transport classes handling the concrete access to the command pipe
*
*/
interface Transport
{
/**
* Overwrite the target file of this Transport class using the given config from instances.ini
*
* @param \Zend_Config $config A configuration file containing a 'path' setting
*/
public function setEndpoint(\Zend_Config $config);
/**
* Write the given external command to the command pipe
*
* @param string $message The command to send, without the timestamp (this will be added here)
*/
public function send($message);
}

View File

@ -359,7 +359,7 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
"host_name" => "Testhost"
)
),$downtime);
$this->assertCommandSucceeded("SCHEDULE_HOST_DOWNTIME;Testhost;25;26;0;0;0;me;test");
$this->assertCommandSucceeded("SCHEDULE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test");
$pipe->scheduleDowntime(array(
(object) array(
@ -367,7 +367,7 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
"service_description" => "svc"
)
),$downtime);
$this->assertCommandSucceeded("SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;0;0;0;me;test");
$this->assertCommandSucceeded("SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;1;0;0;me;test");
} catch (Exception $e) {
$this->cleanup();