mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
Automation: move and refactor related tables
This commit is contained in:
parent
408ff7639c
commit
e5f7633d1e
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use Icinga\Module\Director\Import\Import;
|
||||
use Icinga\Module\Director\Objects\ImportSource;
|
||||
use Exception;
|
||||
|
||||
class ImportsourceTable extends QuickTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'source_name',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 's.id',
|
||||
'source_name' => 's.source_name',
|
||||
'provider_class' => 's.provider_class',
|
||||
'import_state' => 's.import_state',
|
||||
'last_error_message' => 's.last_error_message',
|
||||
'description' => 'CASE WHEN s.description IS NULL THEN s.source_name'
|
||||
. " ELSE s.source_name || ': ' || s.description END",
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url('director/importsource', array('id' => $row->id));
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'description' => $view->translate('Source name'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function listTableClasses()
|
||||
{
|
||||
return array_merge(array('syncstate'), parent::listTableClasses());
|
||||
}
|
||||
|
||||
protected function getRowClasses($row)
|
||||
{
|
||||
if ($row->import_state === 'failing' && $row->last_error_message) {
|
||||
$row->source_name .= ' (' . $row->last_error_message . ')';
|
||||
}
|
||||
|
||||
return $row->import_state;
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('s' => 'import_source'),
|
||||
array()
|
||||
)->order('source_name ASC');
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?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->last_attempt_succeeded === 'n' && $row->last_error_message) {
|
||||
$row->job_name .= ' (' . $row->last_error_message . ')';
|
||||
}
|
||||
|
||||
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'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('j' => 'director_job'),
|
||||
array()
|
||||
)->order('job_name');
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Tables;
|
||||
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use Icinga\Module\Director\Import\Sync;
|
||||
use Icinga\Module\Director\Objects\SyncRule;
|
||||
use Exception;
|
||||
|
||||
class SyncruleTable extends QuickTable
|
||||
{
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 's.id',
|
||||
'rule_name' => 's.rule_name',
|
||||
'sync_state' => 's.sync_state',
|
||||
'object_type' => 's.object_type',
|
||||
'update_policy' => 's.update_policy',
|
||||
'purge_existing' => 's.purge_existing',
|
||||
'filter_expression' => 's.filter_expression',
|
||||
'last_error_message' => 's.last_error_message',
|
||||
'description' => 'CASE WHEN s.description IS NULL THEN s.rule_name'
|
||||
. " ELSE s.rule_name || ': ' || s.description END",
|
||||
);
|
||||
}
|
||||
|
||||
protected function getActionUrl($row)
|
||||
{
|
||||
return $this->url('director/syncrule', array('id' => $row->id));
|
||||
}
|
||||
|
||||
protected function listTableClasses()
|
||||
{
|
||||
return array_merge(array('syncstate'), parent::listTableClasses());
|
||||
}
|
||||
|
||||
protected function getRowClasses($row)
|
||||
{
|
||||
if ($row->sync_state === 'failing' && $row->last_error_message) {
|
||||
$row->rule_name .= ' (' . $row->last_error_message . ')';
|
||||
}
|
||||
|
||||
return $row->sync_state;
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'description' => $view->translate('Rule name'),
|
||||
'object_type' => $view->translate('Object type'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
array('s' => 'sync_rule'),
|
||||
array()
|
||||
)->order('rule_name');
|
||||
}
|
||||
}
|
63
library/Director/Web/Table/ImportsourceTable.php
Normal file
63
library/Director/Web/Table/ImportsourceTable.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class ImportsourceTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = [
|
||||
'source_name',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Source name'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$this->attributes()->add('class', 'syncstate');
|
||||
parent::assemble();
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$caption = [Link::create(
|
||||
$row->source_name,
|
||||
'director/importsource',
|
||||
['id' => $row->id]
|
||||
)];
|
||||
if ($row->description !== null) {
|
||||
$caption[] = ': ' . $row->description;
|
||||
}
|
||||
|
||||
if ($row->import_state === 'failing' && $row->last_error_message) {
|
||||
$caption[] = ' (' . $row->last_error_message . ')';
|
||||
}
|
||||
|
||||
$tr = $this::row([$caption]);
|
||||
$tr->attributes()->add('class', $row->import_state);
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['s' => 'import_source'],
|
||||
[
|
||||
'id' => 's.id',
|
||||
'source_name' => 's.source_name',
|
||||
'provider_class' => 's.provider_class',
|
||||
'import_state' => 's.import_state',
|
||||
'last_error_message' => 's.last_error_message',
|
||||
'description' => 's.description',
|
||||
]
|
||||
)->order('source_name ASC');
|
||||
}
|
||||
}
|
82
library/Director/Web/Table/JobTable.php
Normal file
82
library/Director/Web/Table/JobTable.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class JobTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = [
|
||||
'job_name',
|
||||
];
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$this->attributes()->add('class', 'jobs');
|
||||
parent::assemble();
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$caption = [Link::create(
|
||||
$row->job_name,
|
||||
'director/job',
|
||||
['id' => $row->id]
|
||||
)];
|
||||
|
||||
if ($row->last_attempt_succeeded === 'n' && $row->last_error_message) {
|
||||
$caption[] = ' (' . $row->last_error_message . ')';
|
||||
}
|
||||
|
||||
$tr = $this::row([$caption]);
|
||||
$tr->attributes()->add('class', $this->getJobClasses($row));
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
protected function getJobClasses($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 getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Job name'),
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['j' => 'director_job'],
|
||||
[
|
||||
'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',
|
||||
]
|
||||
)->order('job_name');
|
||||
}
|
||||
}
|
67
library/Director/Web/Table/SyncruleTable.php
Normal file
67
library/Director/Web/Table/SyncruleTable.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
|
||||
class SyncruleTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = [
|
||||
'rule_name',
|
||||
'description',
|
||||
];
|
||||
|
||||
protected function assemble()
|
||||
{
|
||||
$this->attributes()->add('class', 'syncstate');
|
||||
parent::assemble();
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$caption = [Link::create(
|
||||
$row->rule_name,
|
||||
'director/syncrule',
|
||||
['id' => $row->id]
|
||||
)];
|
||||
if ($row->description !== null) {
|
||||
$caption[] = ': ' . $row->description;
|
||||
}
|
||||
|
||||
if ($row->sync_state === 'failing' && $row->last_error_message) {
|
||||
$caption[] = ' (' . $row->last_error_message . ')';
|
||||
}
|
||||
|
||||
$tr = $this::row([$caption, $row->object_type]);
|
||||
$tr->attributes()->add('class', $row->sync_state);
|
||||
|
||||
return $tr;
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return [
|
||||
$this->translate('Rule name'),
|
||||
$this->translate('Object type'),
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
return $this->db()->select()->from(
|
||||
['s' => 'sync_rule'],
|
||||
[
|
||||
'id' => 's.id',
|
||||
'rule_name' => 's.rule_name',
|
||||
'sync_state' => 's.sync_state',
|
||||
'object_type' => 's.object_type',
|
||||
'update_policy' => 's.update_policy',
|
||||
'purge_existing' => 's.purge_existing',
|
||||
'filter_expression' => 's.filter_expression',
|
||||
'last_error_message' => 's.last_error_message',
|
||||
'description' => 's.description',
|
||||
]
|
||||
)->order('rule_name');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user