-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mattia Codato
committed
Jun 22, 2021
1 parent
c058359
commit 44846cd
Showing
25 changed files
with
1,110 additions
and
12 deletions.
There are no files selected for viewing
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
Binary file not shown.
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
Binary file not shown.
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
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,44 @@ | ||
<a id="Live-modification"></a>Live Modification | ||
=============================================== | ||
|
||
This chapter introduces the *Live Modification* functionality and describes how | ||
it works. | ||
|
||
*Live Modification* can be enabled by ticking the dedicated flag in the | ||
`Configuration -> Modules -> Director -> Configuration` page. | ||
|
||
Feature overview | ||
---------------- | ||
|
||
*Live Modification* manages in real-time the monitoring objects defined by the | ||
user without the necessity of a manual deployment. | ||
|
||
At object creation/update/deletion time, the Director decides if changes are | ||
eligible for the live modification. There are a few object types and properties | ||
that are not yet covered by this feature and still require a manual deployment. | ||
In those infrequent cases, however, the user will be notified that changes need | ||
to be deployed by hand. | ||
|
||
If changes are supported, they are queued in a pending state, then the | ||
Director Daemon will take care of applying the modifications through the | ||
Icinga2 API. | ||
|
||
Activity Log | ||
------------ | ||
|
||
All the real-time changes are tracked as usual in the | ||
`Director -> Activity Log` page. | ||
Each Activity Log entry has a `Live Modification` field with the following | ||
possible values: | ||
|
||
- **disabled**: if the feature is not enabled in the current installation | ||
- **scheduled**: when changes are applied in the Director, but not yet | ||
propagated to Icinga2 | ||
- **succeeded**: for all the changes already applied in monitoring | ||
configuration | ||
- **failed**: when changes are supported by the feature, but an error occurred | ||
during the propagation | ||
- **impossible**: if changes are not supported by the feature | ||
|
||
A blue badge counter will be visible in sidebar if live modifications are still | ||
pending on the system. |
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
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
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,103 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Director\Daemon; | ||
|
||
use Exception; | ||
use Icinga\Module\Director\Db; | ||
use Icinga\Module\Director\DirectorObject\IcingaModifiedAttribute; | ||
use Icinga\Module\Director\Objects\DirectorActivityLog; | ||
use React\EventLoop\LoopInterface; | ||
use function React\Promise\resolve; | ||
|
||
class LiveCreation implements DbBasedComponent | ||
{ | ||
/** @var Db */ | ||
protected $db; | ||
|
||
public function __construct(LoopInterface $loop) | ||
{ | ||
$loop->addPeriodicTimer(5, function () { | ||
if ($this->db) { | ||
$this->run(); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* @return IcingaModifiedAttribute[] | ||
*/ | ||
public function fetchPendingModifications() | ||
{ | ||
return IcingaModifiedAttribute::loadAll( | ||
$this->db, | ||
$this->db->getDbAdapter() | ||
->select()->from('icinga_modified_attribute') | ||
->where('state != ?', 'applied') | ||
->order('state') | ||
->order('id') | ||
); | ||
} | ||
|
||
public function applyModification(IcingaModifiedAttribute $modifiedAttribute) | ||
{ | ||
try { | ||
return $this->db->getDeploymentEndpoint()->api()->sendModification($modifiedAttribute); | ||
} catch (Exception $e) { | ||
return false; | ||
} | ||
} | ||
|
||
public function run() | ||
{ | ||
foreach ($this->fetchPendingModifications() as $modification) { | ||
$activityLogStatus = null; | ||
$activityId = $modification->get('activity_id'); | ||
if ($activityId !== null) { | ||
$activityLog = DirectorActivityLog::load($activityId, $this->db); | ||
} | ||
|
||
if ($this->applyModification($modification)) { | ||
if ($modification->get('state') === 'scheduled_for_reset') { | ||
$modification->delete(); | ||
} else { | ||
if ($activityId !== null && $activityLog->get('live_modification') === | ||
DirectorActivityLog::LIVE_MODIFICATION_VALUE_SCHEDULED) { | ||
$activityLogStatus = DirectorActivityLog::LIVE_MODIFICATION_VALUE_SUCCEEDED; | ||
} | ||
$modification->set('state', 'applied'); | ||
$modification->set('ts_applied', DaemonUtil::timestampWithMilliseconds()); | ||
$modification->store(); | ||
} | ||
} else { | ||
$activityLogStatus = DirectorActivityLog::LIVE_MODIFICATION_VALUE_FAILED; | ||
$modification->delete(); | ||
} | ||
|
||
if ($activityId !== null && $activityLogStatus !== null) { | ||
$activityLog->set('live_modification', $activityLogStatus); | ||
$activityLog->store($this->db); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param Db $connection | ||
* @return \React\Promise\ExtendedPromiseInterface | ||
*/ | ||
public function initDb(Db $connection) | ||
{ | ||
$this->db = $connection; | ||
|
||
return resolve(); | ||
} | ||
|
||
/** | ||
* @return \React\Promise\ExtendedPromiseInterface | ||
*/ | ||
public function stopDb() | ||
{ | ||
$this->db = null; | ||
|
||
return resolve(); | ||
} | ||
} |
Oops, something went wrong.