Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitoring/commands: Add (ENABLE|DISABLE)_NOTIFICATIONS/DISABLE_NOTIF…
…ICATIONS_EXPIRE_TIME commands `ToggleNotifications' is the command object for enabling/disabling host and service notifications on an Icinga instance with an optional expire time for disabling notifications. refs #6593
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
modules/monitoring/library/Monitoring/Command/Instance/ToggleNotifications.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
// {{{ICINGA_LICENSE_HEADER}}} | ||
// {{{ICINGA_LICENSE_HEADER}}} | ||
|
||
namespace Icinga\Module\Monitoring\Command\Instance; | ||
|
||
use Icinga\Module\Monitoring\Command\Common\ToggleFeature; | ||
|
||
/** | ||
* Enable/disable host and service notifications on an Icinga instance | ||
*/ | ||
class ToggleNotifications extends ToggleFeature | ||
{ | ||
/** | ||
* The time when notifications should be re-enabled after disabling | ||
* | ||
* @var int|null Unix timestamp | ||
*/ | ||
protected $expireTime; | ||
|
||
/** | ||
* Disable notifications with optional expire time | ||
* | ||
* @param int|null $expireTime The Unix timestamp when notifications should be re-enabled after disabling | ||
* | ||
* @return $this | ||
*/ | ||
public function disable($expireTime = null) | ||
{ | ||
$this->expireTime = $expireTime !== null ? (int) $expireTime : null; | ||
return parent::disable(); | ||
} | ||
|
||
/** | ||
* (non-PHPDoc) | ||
* @see \Icinga\Module\Monitoring\Command\IcingaCommand::getCommandString() For the method documentation. | ||
*/ | ||
public function getCommandString() | ||
{ | ||
if ($this->enable === true) { | ||
return 'ENABLE_NOTIFICATIONS'; | ||
} | ||
if ($this->expireTime !== null) { | ||
return sprintf( | ||
'%s;%u;%u', | ||
'DISABLE_NOTIFICATIONS_EXPIRE_TIME', | ||
time(), // Schedule time. According to the Icinga documentation schedule time has no effect currently | ||
// and should be set to the current timestamp. | ||
$this->expireTime | ||
); | ||
} | ||
return 'DISABLE_NOTIFICATIONS'; | ||
} | ||
} |