parent
7045148f93
commit
8e60e2dcd9
|
@ -159,10 +159,6 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @TODO: Display downtime list (Bug #4496)
|
||||
*
|
||||
*/
|
||||
$this->addElement(
|
||||
'select',
|
||||
'triggered',
|
||||
|
@ -334,8 +330,8 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
*/
|
||||
public function createCommand()
|
||||
{
|
||||
// TODO: Add support for propagation, host-/servicegroups and services only (#4588)
|
||||
return new ScheduleDowntimeCommand(
|
||||
// TODO: Add support for host-/servicegroups and services only (#4588)
|
||||
$command = new ScheduleDowntimeCommand(
|
||||
$this->getValue('starttime'),
|
||||
$this->getValue('endtime'),
|
||||
new Comment(
|
||||
|
@ -346,5 +342,9 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm
|
|||
$this->getValue('hours') * 3600 + $this->getValue('minutes') * 60,
|
||||
$this->getValue('triggered')
|
||||
);
|
||||
return $command->includeChildren(
|
||||
$this->getWithChildren(),
|
||||
$this->getValue('childobjects') === 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,13 @@ class ScheduleDowntimeCommand extends BaseCommand
|
|||
*/
|
||||
private $triggerId;
|
||||
|
||||
/**
|
||||
* Whether this downtime should trigger children hosts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $triggerChildren;
|
||||
|
||||
/**
|
||||
* Set when to start this downtime
|
||||
*
|
||||
|
@ -175,6 +182,19 @@ class ScheduleDowntimeCommand extends BaseCommand
|
|||
$this->triggerId = $triggerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include all children hosts with this command
|
||||
*
|
||||
* @param bool $state
|
||||
* @param bool $trigger Whether children are triggered by this downtime
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function includeChildren($state = true, $trigger = false) {
|
||||
$this->triggerChildren = (bool) $trigger;
|
||||
return parent::includeChildren($state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this command's parameters properly arranged in an array
|
||||
*
|
||||
|
@ -197,31 +217,21 @@ class ScheduleDowntimeCommand extends BaseCommand
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given host or all of it's services
|
||||
* Return the command as a string for the given host
|
||||
*
|
||||
* @param type $hostname The name of the host to insert
|
||||
* @param type $servicesOnly Whether this downtime is for the given host or all of it's services
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getHostCommand($hostname, $servicesOnly = false)
|
||||
public function getHostCommand($hostname)
|
||||
{
|
||||
return sprintf('SCHEDULE_HOST%s_DOWNTIME;', $servicesOnly ? '_SVC' : '')
|
||||
. implode(';', array_merge(array($hostname), $this->getParameters()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for the given host and all of it's children hosts
|
||||
*
|
||||
* @param string $hostname The name of the host to insert
|
||||
* @param bool $triggered Whether it's children are triggered
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getPropagatedHostCommand($hostname, $triggered = false)
|
||||
{
|
||||
return sprintf('SCHEDULE_AND_PROPAGATE%s_HOST_DOWNTIME;', $triggered ? '_TRIGGERED' : '')
|
||||
if ($this->withChildren) {
|
||||
return sprintf('SCHEDULE_AND_PROPAGATE%s_HOST_DOWNTIME;', $this->triggerChildren ? '_TRIGGERED' : '')
|
||||
. implode(';', array_merge(array($hostname), $this->getParameters()));
|
||||
} else {
|
||||
return sprintf('SCHEDULE_HOST%s_DOWNTIME;', $this->onlyServices ? '_SVC' : '')
|
||||
. implode(';', array_merge(array($hostname), $this->getParameters()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -244,30 +254,28 @@ class ScheduleDowntimeCommand extends BaseCommand
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for all hosts or services of the given hostgroup
|
||||
* Return the command as a string for the given hostgroup
|
||||
*
|
||||
* @param type $hostgroup The name of the hostgroup to insert
|
||||
* @param type $hostsOnly Whether only hosts or services are taken into account
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getHostgroupCommand($hostgroup, $hostsOnly = true)
|
||||
public function getHostgroupCommand($hostgroup)
|
||||
{
|
||||
return sprintf('SCHEDULE_HOSTGROUP_%s_DOWNTIME;', $hostsOnly ? 'HOST' : 'SVC')
|
||||
return sprintf('SCHEDULE_HOSTGROUP_%s_DOWNTIME;', $this->withoutHosts ? 'SVC' : 'HOST')
|
||||
. implode(';', array_merge(array($hostgroup), $this->getParameters()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the command as a string for all hosts or services of the given servicegroup
|
||||
* Return the command as a string for the given servicegroup
|
||||
*
|
||||
* @param type $servicegroup The name of the servicegroup to insert
|
||||
* @param type $hostsOnly Whether only hosts or services are taken into account
|
||||
*
|
||||
* @return string The string representation of the command
|
||||
*/
|
||||
public function getServicegroupCommand($servicegroup, $hostsOnly = true)
|
||||
public function getServicegroupCommand($servicegroup)
|
||||
{
|
||||
return sprintf('SCHEDULE_SERVICEGROUP_%s_DOWNTIME;', $hostsOnly ? 'HOST' : 'SVC')
|
||||
return sprintf('SCHEDULE_SERVICEGROUP_%s_DOWNTIME;', $this->withoutServices ? 'HOST' : 'SVC')
|
||||
. implode(';', array_merge(array($servicegroup), $this->getParameters()));
|
||||
}
|
||||
}
|
|
@ -421,27 +421,78 @@ class CommandPipeTest extends \PHPUnit_Framework_TestCase
|
|||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$downtime = new ScheduleDowntimeCommand(25, 26, new Comment("me", "test"));
|
||||
$downtime = new ScheduleDowntimeCommand(25, 26, new Comment('me', 'test'));
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost"
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded("SCHEDULE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test");
|
||||
$this->assertCommandSucceeded('SCHEDULE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test');
|
||||
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
"host_name" => "Testhost",
|
||||
"service_description" => "svc"
|
||||
'host_name' => 'Testhost',
|
||||
'service_description' => 'svc'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded("SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;1;0;0;me;test");
|
||||
$this->assertCommandSucceeded('SCHEDULE_SVC_DOWNTIME;Testhost;svc;25;26;1;0;0;me;test');
|
||||
|
||||
$downtime->excludeHost();
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('SCHEDULE_HOST_SVC_DOWNTIME;Testhost;25;26;1;0;0;me;test');
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether propagated host downtimes are correctly scheduled
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSchedulePropagatedDowntime()
|
||||
{
|
||||
$pipe = $this->getLocalTestPipe();
|
||||
try {
|
||||
$downtime = new ScheduleDowntimeCommand(25, 26, new Comment('me', 'test'));
|
||||
$downtime->includeChildren();
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded('SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test');
|
||||
|
||||
$downtime->includeChildren(true, true);
|
||||
$pipe->sendCommand(
|
||||
$downtime,
|
||||
array(
|
||||
(object) array(
|
||||
'host_name' => 'Testhost'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertCommandSucceeded(
|
||||
'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;Testhost;25;26;1;0;0;me;test'
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
$this->cleanup();
|
||||
throw $e;
|
||||
|
|
Loading…
Reference in New Issue