diff options
Diffstat (limited to 'library/Director/Dashboard/Dashlet/JobDashlet.php')
-rw-r--r-- | library/Director/Dashboard/Dashlet/JobDashlet.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/library/Director/Dashboard/Dashlet/JobDashlet.php b/library/Director/Dashboard/Dashlet/JobDashlet.php new file mode 100644 index 0000000..d7452e0 --- /dev/null +++ b/library/Director/Dashboard/Dashlet/JobDashlet.php @@ -0,0 +1,65 @@ +<?php + +namespace Icinga\Module\Director\Dashboard\Dashlet; + +use Exception; +use Icinga\Module\Director\Objects\DirectorJob; + +class JobDashlet extends Dashlet +{ + protected $icon = 'clock'; + + public function getTitle() + { + return $this->translate('Jobs'); + } + + public function listCssClasses() + { + try { + return $this->fetchStateClass(); + } catch (Exception $e) { + return 'state-critical'; + } + } + + public function getSummary() + { + return $this->translate( + 'Schedule and automate Import, Syncronization, Config Deployment,' + . ' Housekeeping and more' + ); + } + + protected function fetchStateClass() + { + /** @var DirectorJob[] $jobs */ + $jobs = DirectorJob::loadAll($this->db); + if (count($jobs) > 0) { + $state = 'state-ok'; + } else { + $state = null; + } + + foreach ($jobs as $job) { + if ($job->isPending()) { + $state = 'state-pending'; + } elseif (! $job->lastAttemptSucceeded()) { + $state = 'state-critical'; + break; + } + } + + return $state; + } + + public function getUrl() + { + return 'director/jobs'; + } + + public function listRequiredPermissions() + { + return array('director/admin'); + } +} |