2013-09-04 16:21:44 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring\Command;
|
|
|
|
|
2013-09-16 14:44:59 +02:00
|
|
|
use Icinga\Protocol\Commandpipe\Command;
|
2013-09-04 16:21:44 +02:00
|
|
|
use Icinga\Protocol\Commandpipe\Comment;
|
|
|
|
|
2013-09-04 18:07:24 +02:00
|
|
|
/**
|
|
|
|
* Icinga Command for adding comments
|
|
|
|
*
|
2013-09-16 14:44:59 +02:00
|
|
|
* @see Command
|
2013-09-04 18:07:24 +02:00
|
|
|
*/
|
2013-09-16 14:44:59 +02:00
|
|
|
class AddCommentCommand extends Command
|
2013-09-04 16:21:44 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The comment associated to this command
|
|
|
|
*
|
|
|
|
* @var Comment
|
|
|
|
*/
|
|
|
|
private $comment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise a new command object to add comments
|
|
|
|
*
|
|
|
|
* @param Comment $comment The comment to use for this acknowledgement
|
|
|
|
*/
|
|
|
|
public function __construct(Comment $comment)
|
|
|
|
{
|
|
|
|
$this->comment = $comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the comment for this command
|
|
|
|
*
|
|
|
|
* @param Comment $comment
|
2013-09-05 10:54:48 +02:00
|
|
|
*
|
2013-09-04 16:21:44 +02:00
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setComment(Comment $comment)
|
|
|
|
{
|
|
|
|
$this->comment = $comment;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-09-16 14:46:18 +02:00
|
|
|
public function getArguments()
|
2013-09-16 14:39:14 +02:00
|
|
|
{
|
2013-09-16 14:46:18 +02:00
|
|
|
return $this->comment->getArguments();
|
2013-09-16 14:39:14 +02:00
|
|
|
}
|
|
|
|
|
2013-09-04 16:21:44 +02:00
|
|
|
/**
|
2013-09-05 10:54:48 +02:00
|
|
|
* 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
|
2013-09-16 14:44:59 +02:00
|
|
|
* @see Command::getHostCommand()
|
2013-09-04 16:21:44 +02:00
|
|
|
*/
|
|
|
|
public function getHostCommand($hostname)
|
|
|
|
{
|
2013-09-16 14:46:18 +02:00
|
|
|
return sprintf('ADD_HOST_COMMENT;%s;', $hostname) . implode(';', $this->getArguments());
|
2013-09-04 16:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-05 10:54:48 +02:00
|
|
|
* 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
|
2013-09-16 14:44:59 +02:00
|
|
|
* @see Command::getServiceCommand()
|
2013-09-04 16:21:44 +02:00
|
|
|
*/
|
|
|
|
public function getServiceCommand($hostname, $servicename)
|
|
|
|
{
|
|
|
|
return sprintf('ADD_SVC_COMMENT;%s;%s;', $hostname, $servicename)
|
2013-09-16 14:46:18 +02:00
|
|
|
. implode(';', $this->getArguments());
|
2013-09-04 16:21:44 +02:00
|
|
|
}
|
|
|
|
}
|