Jobs: controller and table
This commit is contained in:
parent
35c592ffba
commit
d05d58cc48
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
|
||||
class JobsController extends ActionController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->title = $this->translate('Jobs');
|
||||
|
||||
$this->getTabs()->add('jobs', array(
|
||||
'url' => 'director/jobs',
|
||||
'label' => $this->translate('Jobs'),
|
||||
))->activate('jobs');
|
||||
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->translate('Add'),
|
||||
'director/job',
|
||||
null,
|
||||
array('class' => 'icon-plus')
|
||||
);
|
||||
|
||||
$this->view->table = $this->applyPaginationLimits(
|
||||
$this->loadTable('job')
|
||||
->setConnection($this->db())
|
||||
);
|
||||
$this->setViewScript('list/table');
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use Icinga\Module\Director\Objects\Job;
|
||||
use Exception;
|
||||
|
||||
class JobTable extends QuickTable
|
||||
{
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'j.id',
|
||||
'job_name' => 'j.job_name',
|
||||
'job_class' => 'j.job_class',
|
||||
'disabled' => 'j.disabled',
|
||||
'run_interval' => 'j.run_interval',
|
||||
'last_attempt_succeeded' => 'j.last_attempt_succeeded',
|
||||
'ts_last_attempt' => 'j.ts_last_attempt',
|
||||
'unixts_last_attempt' => 'UNIX_TIMESTAMP(j.ts_last_attempt)',
|
||||
'ts_last_error' => 'j.ts_last_error',
|
||||
'last_error_message' => 'j.last_error_message',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url('director/job', array('id' => $row->id));
|
||||
}
|
||||
|
||||
protected function listTableClasses()
|
||||
{
|
||||
return array_merge(array('jobs'), parent::listTableClasses());
|
||||
}
|
||||
|
||||
protected function getRowClasses($row)
|
||||
{
|
||||
if ($row->unixts_last_attempt === null) {
|
||||
return 'pending';
|
||||
}
|
||||
if ($row->unixts_last_attempt + $row->run_interval < time()) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
if ($row->last_attempt_succeeded === 'y') {
|
||||
return 'ok';
|
||||
} elseif ($row->last_attempt_succeeded === 'n') {
|
||||
return 'critical';
|
||||
} else {
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'job_name' => $view->translate('Job name'),
|
||||
'object_type' => $view->translate('Object type'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
$db = $this->connection()->getConnection();
|
||||
|
||||
$query = $db->select()->from(
|
||||
array('j' => 'director_job'),
|
||||
array()
|
||||
)->order('job_name');
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue