mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 08:14:03 +02:00
parent
fef8370d5f
commit
7045148f93
@ -170,30 +170,6 @@ class CommandPipe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 = "")
|
|
||||||
{
|
|
||||||
if ($perfdata) {
|
|
||||||
$output = $output."|".$perfdata;
|
|
||||||
}
|
|
||||||
foreach ($objects as $object) {
|
|
||||||
if (isset($object->service_description)) {
|
|
||||||
$this->send(
|
|
||||||
"PROCESS_SERVICE_CHECK_RESULT;$object->host_name;$object->service_description;$state;$output"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$this->send("PROCESS_HOST_CHECK_RESULT;$object->host_name;$state;$output");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the submitted comments
|
* Removes the submitted comments
|
||||||
*
|
*
|
||||||
|
@ -302,7 +302,7 @@ class Monitoring_CommandController extends ActionController
|
|||||||
$this->setForm($form);
|
$this->setForm($form);
|
||||||
|
|
||||||
if ($form->IsSubmittedAndValid() === true) {
|
if ($form->IsSubmittedAndValid() === true) {
|
||||||
$this->target->submitCheckResult($this->view->objects, $form->getState(), $form->getOutput(), $form->getPerformancedata());
|
$this->target->sendCommand($form->createCommand(), $this->view->objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,32 +184,16 @@ class SubmitPassiveCheckResultForm extends CommandForm
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the entered object state as an integer
|
* Create the submit passive checkresult command object
|
||||||
*
|
*
|
||||||
* @return int
|
* @return SubmitPassiveCheckresultCommand
|
||||||
*/
|
*/
|
||||||
public function getState()
|
public function createCommand()
|
||||||
{
|
{
|
||||||
return intval($this->getValue('pluginstate'));
|
return new SubmitPassiveCheckresultCommand(
|
||||||
}
|
$this->getValue('pluginstate'),
|
||||||
|
$this->getValue('checkoutput'),
|
||||||
/**
|
$this->getValue('performancedata')
|
||||||
* Return the entered check output as a string
|
);
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getOutput()
|
|
||||||
{
|
|
||||||
return $this->getValue('checkoutput');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the entered performance data as a string
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getPerformancedata()
|
|
||||||
{
|
|
||||||
return $this->getValue('performancedata');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
/**
|
||||||
|
* This file is part of Icinga 2 Web.
|
||||||
|
*
|
||||||
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||||
|
* 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>
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||||
|
* @author Icinga Development Team <info@icinga.org>
|
||||||
|
*/
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to submit passive check results
|
||||||
|
*/
|
||||||
|
class SubmitPassiveCheckresultCommand extends BaseCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The plugin-state that is being reported
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output that is included
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The performance data that is included
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $perfData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises a new command object to submit a passive check result
|
||||||
|
*
|
||||||
|
* @param int $state The plugin-state to report
|
||||||
|
* @param string $output The plugin-output to include
|
||||||
|
* @param string $perfData The performance data to include
|
||||||
|
*/
|
||||||
|
public function __construct($state, $output, $perfData)
|
||||||
|
{
|
||||||
|
$this->state = $state;
|
||||||
|
$this->output = $output;
|
||||||
|
$this->perfData = $perfData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set which plugin-state is being reported
|
||||||
|
*
|
||||||
|
* @param int $state
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setState($state)
|
||||||
|
{
|
||||||
|
$this->state = intval($state);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the plugin-output to include in the result
|
||||||
|
*
|
||||||
|
* @param string $output
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setOutput($output)
|
||||||
|
{
|
||||||
|
$this->output = (string) $output;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the performance data to include in the result
|
||||||
|
*
|
||||||
|
* @param string $perfData
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setPerformanceData($perfData)
|
||||||
|
{
|
||||||
|
$this->perfData = (string) $perfData;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this command's parameters properly arranged in an array
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @see BaseCommand::getParameters()
|
||||||
|
*/
|
||||||
|
public function getParameters()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
$this->state,
|
||||||
|
$this->perfData ? $this->output . '|' . $this->perfData : $this->output
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* @see BaseCommand::getHostCommand()
|
||||||
|
*/
|
||||||
|
public function getHostCommand($hostname)
|
||||||
|
{
|
||||||
|
return 'PROCESS_HOST_CHECK_RESULT;' . implode(';', array_merge(array($hostname), $this->getParameters()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* @see BaseCommand::getServiceCommand()
|
||||||
|
*/
|
||||||
|
public function getServiceCommand($hostname, $servicename)
|
||||||
|
{
|
||||||
|
return 'PROCESS_SERVICE_CHECK_RESULT;' . implode(
|
||||||
|
';',
|
||||||
|
array_merge(
|
||||||
|
array($hostname, $servicename),
|
||||||
|
$this->getParameters()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -55,5 +55,6 @@ class CommandPipeLoader extends LibraryLoader {
|
|||||||
require_once('../../modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php');
|
require_once('../../modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php');
|
||||||
require_once('../../modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php');
|
require_once('../../modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php');
|
||||||
require_once('../../modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php');
|
require_once('../../modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php');
|
||||||
|
require_once('../../modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand;
|
|||||||
use Icinga\Module\Monitoring\Command\CustomNotificationCommand;
|
use Icinga\Module\Monitoring\Command\CustomNotificationCommand;
|
||||||
use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
use Icinga\Module\Monitoring\Command\DelayNotificationCommand;
|
||||||
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
use Icinga\Module\Monitoring\Command\ScheduleCheckCommand;
|
||||||
|
use Icinga\Module\Monitoring\Command\SubmitPassiveCheckresultCommand;
|
||||||
|
|
||||||
if (!defined("EXTCMD_TEST_BIN")) {
|
if (!defined("EXTCMD_TEST_BIN")) {
|
||||||
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
define("EXTCMD_TEST_BIN", "./bin/extcmd_test");
|
||||||
@ -577,6 +578,45 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether commands to submit passive check results are being sent to the commandpipe
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function testSubmitPassiveCheckresult()
|
||||||
|
{
|
||||||
|
$pipe = $this->getLocalTestPipe();
|
||||||
|
try {
|
||||||
|
$result = new SubmitPassiveCheckresultCommand(0, 'foo', 'bar');
|
||||||
|
$pipe->sendCommand(
|
||||||
|
$result,
|
||||||
|
array(
|
||||||
|
(object) array(
|
||||||
|
'host_name' => 'Host',
|
||||||
|
'service_description' => 'Service'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertCommandSucceeded('PROCESS_SERVICE_CHECK_RESULT;Host;Service;0;foo|bar');
|
||||||
|
|
||||||
|
$result->setOutput('foobar');
|
||||||
|
$result->setPerformanceData('');
|
||||||
|
$pipe->sendCommand(
|
||||||
|
$result,
|
||||||
|
array(
|
||||||
|
(object) array(
|
||||||
|
'host_name' => 'Host'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertCommandSucceeded('PROCESS_HOST_CHECK_RESULT;Host;0;foobar');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->cleanup();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
$this->cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test sending of commands via SSH (currently disabled)
|
* Test sending of commands via SSH (currently disabled)
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user