From 37d3c5aa045c86c7827322f29484d41c4a55316c Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 22 Apr 2016 14:31:41 +0200 Subject: [PATCH] index: show and link jobs on dashboard --- application/controllers/IndexController.php | 29 ++++++++++++++++++++- application/views/scripts/index/index.phtml | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index 6a7c5770..7ee6f963 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Director\Controllers; use Exception; +use Icinga\Module\Director\Objects\DirectorJob; use Icinga\Module\Director\Objects\SyncRule; use Icinga\Module\Director\Web\Controller\ActionController; @@ -31,7 +32,8 @@ class IndexController extends ActionController 'label' => $this->translate('Overview') ))->activate('overview'); - $this->fetchSyncState(); + $this->fetchSyncState() + ->fetchJobState(); } } @@ -56,6 +58,31 @@ class IndexController extends ActionController } $this->view->syncState = $state; + + return $this; + } + + protected function fetchJobState() + { + $jobs = DirectorJob::loadAll($this->db()); + if (count($jobs) > 0) { + $state = 'ok'; + } else { + $state = null; + } + + foreach ($jobs as $job) { + if ($job->isPending()) { + $state = 'pending'; + } elseif (! $job->lastAttemptSucceeded()) { + $state = 'critical'; + break; + } + } + + $this->view->jobState = $state; + + return $this; } protected function hasDeploymentEndpoint() diff --git a/application/views/scripts/index/index.phtml b/application/views/scripts/index/index.phtml index afec2dd1..86d3892c 100644 --- a/application/views/scripts/index/index.phtml +++ b/application/views/scripts/index/index.phtml @@ -103,6 +103,7 @@ $all = array( $this->translate('Do more with your data') => array( array('database', $this->translate('Import data sources'), 'director/list/importsource', $this->translate('Define and manage imports from various data sources')), array('flapping', $this->translate('Synchronize'), 'director/list/syncrule', $this->translate('Define how imported data should be synchronized with Icinga'), $this->syncState), + array('clock', $this->translate('Jobs'), 'director/jobs', $this->translate('Schedule and automate Import, Syncronization, Config Deployment, Housekeeping and more'), $this->jobState), array('sort-name-up', $this->translate('Provide data lists'), 'director/data/lists', $this->translate('Provide data lists to make life easier for your users')), array('edit', $this->translate('Define data fields'), 'director/data/fields', $this->translate('Data fields make sure that configuration fits your rules')), )