summaryrefslogtreecommitdiffstats
path: root/library/Director/Dashboard/Dashlet/DeploymentDashlet.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:17:31 +0000
commitf66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch)
treefbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Dashboard/Dashlet/DeploymentDashlet.php
parentInitial commit. (diff)
downloadicingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz
icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Dashboard/Dashlet/DeploymentDashlet.php')
-rw-r--r--library/Director/Dashboard/Dashlet/DeploymentDashlet.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/library/Director/Dashboard/Dashlet/DeploymentDashlet.php b/library/Director/Dashboard/Dashlet/DeploymentDashlet.php
new file mode 100644
index 0000000..7a52793
--- /dev/null
+++ b/library/Director/Dashboard/Dashlet/DeploymentDashlet.php
@@ -0,0 +1,114 @@
+<?php
+
+namespace Icinga\Module\Director\Dashboard\Dashlet;
+
+use Exception;
+use Icinga\Module\Director\Objects\DirectorDeploymentLog;
+
+class DeploymentDashlet extends Dashlet
+{
+ protected $icon = 'wrench';
+
+ protected $undeployedActivities;
+
+ protected $lastDeployment;
+
+ public function getTitle()
+ {
+ return $this->translate('Config Deployment');
+ }
+
+ public function hasUndeployedActivities()
+ {
+ return $this->undeployedActivities() > 0;
+ }
+
+ public function undeployedActivities()
+ {
+ if ($this->undeployedActivities === null) {
+ try {
+ $this->undeployedActivities = $this->db
+ ->countActivitiesSinceLastDeployedConfig();
+ } catch (Exception $e) {
+ $this->undeployedActivities = 0;
+ }
+ }
+
+ return $this->undeployedActivities;
+ }
+
+ public function lastDeploymentFailed()
+ {
+ return ! $this->lastDeployment()->succeeded();
+ }
+
+ public function lastDeploymentPending()
+ {
+ return $this->lastDeployment()->isPending();
+ }
+
+ public function listCssClasses()
+ {
+ try {
+ if ($this->lastDeploymentFailed()) {
+ return array('state-critical');
+ } elseif ($this->lastDeploymentPending()) {
+ return array('state-pending');
+ } elseif ($this->hasUndeployedActivities()) {
+ return array('state-warning');
+ } else {
+ return array('state-ok');
+ }
+ } catch (Exception $e) {
+ return null;
+ }
+ }
+
+ protected function lastDeployment()
+ {
+ if ($this->lastDeployment === null) {
+ $this->lastDeployment = DirectorDeploymentLog::loadLatest($this->db);
+ }
+
+ return $this->lastDeployment;
+ }
+
+ public function getSummary()
+ {
+ $msgs = array();
+ $cnt = $this->undeployedActivities();
+
+ try {
+ if ($this->lastDeploymentFailed()) {
+ $msgs[] = $this->translate('The last deployment did not succeed');
+ } elseif ($this->lastDeploymentPending()) {
+ $msgs[] = $this->translate('The last deployment is currently pending');
+ }
+ } catch (Exception $e) {
+ }
+
+ if ($cnt === 0) {
+ $msgs[] = $this->translate('There are no pending changes');
+ } else {
+ $msgs[] = sprintf(
+ $this->translate(
+ 'A total of %d config changes happened since your last'
+ . ' deployed config has been rendered'
+ ),
+ $cnt
+ );
+ }
+
+ return implode('. ', $msgs) . '.';
+ }
+
+ public function getUrl()
+ {
+ return 'director/config/deployments';
+ }
+
+ public function listRequiredPermissions()
+ {
+ return array('director/deploy');
+ }
+}