2013-06-03 16:56:08 +02:00
|
|
|
<?php
|
2013-06-07 13:29:11 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-28 16:47:30 +02:00
|
|
|
/**
|
2013-07-15 12:26:10 +02:00
|
|
|
* This file is part of Icinga 2 Web.
|
|
|
|
*
|
|
|
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
2013-06-28 16:47:30 +02:00
|
|
|
* 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>
|
2013-07-15 12:26:10 +02:00
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
2013-06-28 16:47:30 +02:00
|
|
|
*/
|
2013-06-07 13:29:11 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-03 16:56:08 +02:00
|
|
|
|
|
|
|
namespace Icinga\Protocol\Commandpipe;
|
|
|
|
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
2013-08-01 17:48:36 +02:00
|
|
|
* Container for comment information that can be send to icinga's external command pipe
|
|
|
|
*
|
2013-06-07 13:29:11 +02:00
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
class Comment implements IComment
|
|
|
|
{
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
2013-08-01 17:48:36 +02:00
|
|
|
* Whether the persistent flag should be submitted with this command
|
|
|
|
*
|
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
|
|
|
|
|
|
|
/**
|
2013-08-01 17:48:36 +02:00
|
|
|
* The author of this comment
|
|
|
|
*
|
|
|
|
* @var string
|
2013-06-07 13:29:11 +02:00
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
public $author = "";
|
2013-06-07 13:29:11 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-01 17:48:36 +02:00
|
|
|
* The comment text to use
|
|
|
|
*
|
|
|
|
* @var string
|
2013-06-07 13:29:11 +02:00
|
|
|
*/
|
2013-06-03 16:56:08 +02:00
|
|
|
public $comment = "";
|
|
|
|
|
2013-06-07 13:29:11 +02:00
|
|
|
/**
|
2013-08-01 17:48:36 +02:00
|
|
|
* 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
|
2013-06-07 13:29:11 +02:00
|
|
|
*/
|
|
|
|
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
|
|
|
/**
|
2013-08-01 17:48:36 +02:00
|
|
|
* 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
|
2013-06-07 13:29:11 +02:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|