2013-06-03 16:56:08 +02:00
|
|
|
<?php
|
2013-06-07 13:29:11 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-03 16:56:08 +02:00
|
|
|
|
|
|
|
namespace Icinga\Protocol\Commandpipe;
|
|
|
|
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
|
|
|
* Class Comment
|
|
|
|
* @package Icinga\Protocol\Commandpipe
|
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
class Comment implements IComment
|
|
|
|
{
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
public $persistent = false;
|
2013-06-07 13:29:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
public $author = "";
|
2013-06-07 13:29:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
public $comment = "";
|
|
|
|
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
|
|
|
* @param $author
|
|
|
|
* @param $comment
|
|
|
|
* @param bool $persistent
|
|
|
|
*/
|
|
|
|
public function __construct($author, $comment, $persistent = false)
|
2013-06-03 16:56:08 +02:00
|
|
|
{
|
|
|
|
$this->author = $author;
|
|
|
|
$this->comment = $comment;
|
|
|
|
$this->persistent = $persistent;
|
|
|
|
}
|
|
|
|
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
|
|
|
* @param $type
|
|
|
|
* @return string
|
|
|
|
* @throws InvalidCommandException
|
|
|
|
*/
|
|
|
|
public function getFormatString($type)
|
|
|
|
{
|
|
|
|
$params = ';' . ($this->persistent ? '1' : '0') . ';' . $this->author . ';' . $this->comment;
|
2013-06-03 16:56:08 +02:00
|
|
|
|
2013-06-07 13:29:11 +02:00
|
|
|
switch ($type) {
|
2013-06-03 16:56:08 +02:00
|
|
|
case CommandPipe::TYPE_HOST:
|
|
|
|
$typeVar = "HOST";
|
2013-06-07 13:29:11 +02:00
|
|
|
$params = ";%s" . $params;
|
2013-06-03 16:56:08 +02:00
|
|
|
break;
|
|
|
|
case CommandPipe::TYPE_SERVICE:
|
|
|
|
$typeVar = "SVC";
|
2013-06-07 13:29:11 +02:00
|
|
|
$params = ";%s;%s" . $params;
|
2013-06-03 16:56:08 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new InvalidCommandException("Acknowledgements can only apply on hosts and services ");
|
|
|
|
}
|
|
|
|
return "ADD_{$typeVar}_COMMENT$params";
|
|
|
|
}
|
2013-06-07 13:29:11 +02:00
|
|
|
}
|