From b23a2437e663b6581afa6c9521bd72a6b22659b7 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 24 Oct 2016 21:43:52 +0000 Subject: [PATCH 01/10] IcingaHostTable: no more imports, show address... ...and related actions for templates --- application/tables/IcingaHostTable.php | 68 +++++----------- .../tables/IcingaHostTemplateTable.php | 80 +++++++++++++++++++ 2 files changed, 102 insertions(+), 46 deletions(-) diff --git a/application/tables/IcingaHostTable.php b/application/tables/IcingaHostTable.php index e010e89b..53c9ca72 100644 --- a/application/tables/IcingaHostTable.php +++ b/application/tables/IcingaHostTable.php @@ -2,34 +2,29 @@ namespace Icinga\Module\Director\Tables; -use Icinga\Data\Limitable; -use Icinga\Module\Director\Web\Table\IcingaObjectTable; +use Icinga\Module\Director\Web\Table\QuickTable; -class IcingaHostTable extends IcingaObjectTable +class IcingaHostTable extends QuickTable { protected $searchColumns = array( 'host', + 'address', + 'display_name' ); public function getColumns() { - if ($this->connection()->isPgsql()) { - $parents = "ARRAY_TO_STRING(ARRAY_AGG(ih.object_name ORDER BY hi.weight), ', ')"; - } else { - $parents = "GROUP_CONCAT(ih.object_name ORDER BY hi.weight SEPARATOR ', ')"; - } - return array( - 'id' => 'h.id', - 'host' => 'h.object_name', - 'object_type' => 'h.object_type', - 'address' => 'h.address', - 'zone' => 'z.object_name', - 'parents' => $parents, + 'id' => 'h.id', + 'host' => 'h.object_name', + 'object_type' => 'h.object_type', + 'address' => 'h.address', + 'disabled' => 'h.disabled', + 'display_name' => 'h.address', ); } - protected function getActionUrl($row) + protected function getActionUrl($row) { return $this->url('director/host', array('name' => $row->host)); } @@ -43,12 +38,21 @@ class IcingaHostTable extends IcingaObjectTable ); } + protected function getRowClasses($row) + { + if ($row->disabled === 'y') { + return 'disabled'; + } else { + return null; + } + } + public function getTitles() { $view = $this->view(); return array( 'host' => $view->translate('Hostname'), - 'parents' => $view->translate('Imports'), + 'address' => $view->translate('Address'), ); } @@ -57,35 +61,7 @@ class IcingaHostTable extends IcingaObjectTable return $this->db()->select()->from( array('h' => 'icinga_host'), array() - )->joinLeft( - array('z' => 'icinga_zone'), - 'h.zone_id = z.id', - array() - )->joinLeft( - array('hi' => 'icinga_host_inheritance'), - 'hi.host_id = h.id', - array() - )->joinLeft( - array('ih' => 'icinga_host'), - 'hi.parent_host_id = ih.id', - array() - )->group('h.id') - ->group('z.id') - ->order('h.object_name'); - } - - public function count() - { - $db = $this->db(); - $sub = clone($this->getBaseQuery()); - $sub->columns($this->getColumns()); - $this->applyFiltersToQuery($sub); - $query = $db->select()->from( - array('sub' => $sub), - 'COUNT(*)' - ); - - return $db->fetchOne($query); + )->order('h.object_name'); } public function getBaseQuery() diff --git a/application/tables/IcingaHostTemplateTable.php b/application/tables/IcingaHostTemplateTable.php index 191eda59..d35a126c 100644 --- a/application/tables/IcingaHostTemplateTable.php +++ b/application/tables/IcingaHostTemplateTable.php @@ -4,8 +4,88 @@ namespace Icinga\Module\Director\Tables; use Icinga\Module\Director\Tables\IcingaHostTable; +require_once __DIR__ . '/IcingaHostTable.php'; class IcingaHostTemplateTable extends IcingaHostTable { + protected $searchColumns = array( + 'host', + 'display_name' + ); + + public function getTitles() + { + $view = $this->view(); + return array( + 'host' => $view->translate('Template name'), + ); + } + + protected function renderAdditionalActions($row) + { + $htm = ''; + $view = $this->view(); + + if ($row->object_type === 'template') { + $htm .= $view->qlink( + '', + 'director/host/add?type=object', + array('imports' => $row->host), + array( + 'class' => 'icon-plus', + 'title' => $view->translate( + 'Create a new host based on this template' + ) + ) + ); + if ($cnt = $row->cnt_child_templates) { + if ((int) $cnt === 1) { + $title = $view->translate('Show one host template using this template'); + } else { + $title = sprintf( + $view->translate('Show %d host templates using this template'), + $cnt + ); + } + + $htm .= $view->qlink( + '', + 'director/hosts/bytemplate', + array('name' => $row->host), + array( + 'class' => 'icon-sitemap', + 'title' => $title + ) + ); + + } + + if ($cnt = $row->cnt_child_hosts) { + if ((int) $cnt === 1) { + $title = $view->translate('Show one host using this template'); + } else { + $title = sprintf( + $view->translate('Show %d hosts using this template'), + $cnt + ); + } + + $htm .= $view->qlink( + '', + 'director/hosts/bytemplate', + array('name' => $row->host), + array( + 'class' => 'icon-host', + 'title' => $title + ) + ); + + } + + } + + return $htm; + } + public function getBaseQuery() { return $this->getUnfilteredQuery()->where('h.object_type = ?', 'template'); From 484e14c445a6805bf4524a4d92e082bfa8dbed91 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 24 Oct 2016 21:46:18 +0000 Subject: [PATCH 02/10] ServiceController: prepare for an overview site... ...not much content here... yet --- application/controllers/ServiceController.php | 7 ++++++ application/views/scripts/service/index.phtml | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 application/views/scripts/service/index.phtml diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index c7ca924b..dfa2439e 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -99,6 +99,13 @@ class ServiceController extends ObjectController } } + public function indexAction() + { + $object = $this->loadObject(); + $title = $this->view->title = $object->object_name; + $this->singleTab($this->translate('Icinga Service Template')); + } + public function editAction() { $object = $this->object; diff --git a/application/views/scripts/service/index.phtml b/application/views/scripts/service/index.phtml new file mode 100644 index 00000000..e75ecc92 --- /dev/null +++ b/application/views/scripts/service/index.phtml @@ -0,0 +1,22 @@ +
+tabs ?> +

escape($this->title) ?>

+ +actionLinks ?> + +
+ +
+This is a service template. [As it has no command You might want to assign it: + +
    +
  • Assign it to one or more single hosts
  • +
  • Assign it to all hosts inheriting a specific template
  • +
  • Assign it base on rule/rule definitions + +Admin tasks: +
      +
    • Control which fields (custom vars) can be filled by your users +
    • Provide sets of services +
    +
From cf6f9d42e2a8cfa847f35094a47f72d233491ef8 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 24 Oct 2016 21:47:44 +0000 Subject: [PATCH 03/10] IcingaServiceTable: strip down the service table --- application/tables/IcingaServiceTable.php | 55 +---------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php index 433dc12a..222120d3 100644 --- a/application/tables/IcingaServiceTable.php +++ b/application/tables/IcingaServiceTable.php @@ -23,11 +23,6 @@ class IcingaServiceTable extends QuickTable ); } - protected function listTableClasses() - { - return array_merge(array('assignment-table'), parent::listTableClasses()); - } - protected function getActionUrl($row) { // TODO: Remove once we got a separate apply table @@ -38,55 +33,7 @@ class IcingaServiceTable extends QuickTable } - return $this->url('director/service', $params); - } - - protected function renderRow($row) - { - $v = $this->view(); - $extra = $this->appliedOnes($row->id); - $htm = " getRowClassesString($row) . ">\n"; - $htm .= '' . $v->qlink($row->service, $this->getActionUrl($row)); - if (empty($extra)) { - if ($row->check_command_id) { - $htm .= ' ' . $v->qlink( - 'Create apply-rule', - 'director/service/add', - array('apply' => $row->service), - array('class' => 'icon-plus') - ); - } - - } else { - $htm .= '. Related apply rules: '; - foreach ($extra as $service) { - $href = $v->url('director/service', array('id' => $service->id)); - $htm .= ""; - - try { - $prettyFilter = AssignRenderer::forFilter( - Filter::fromQueryString($service->assign_filter) - )->renderAssign(); - } - catch (IcingaException $e) { - // ignore errors in filter rendering - $prettyFilter = 'Error in Filter rendering: ' . $e->getMessage(); - } - - $htm .= "'; - $htm .= ''; - $htm .= ''; - } - $htm .= '
" . $service->object_name . '' . $prettyFilter . '
'; - $htm .= $v->qlink( - 'Add more', - 'director/service/add', - array('apply' => $row->service), - array('class' => 'icon-plus') - ); - } - $htm .= ''; - return $htm . " \n"; + return $this->url('director/service/edit', $params); } public function getTitles() From 5b58aad56bdbcc95dfdb8cf64ebf29e04923ae65 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 24 Oct 2016 21:48:11 +0000 Subject: [PATCH 04/10] IcingaHostServiceTable: directly link to the form ...at least for now --- application/tables/IcingaHostServiceTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/tables/IcingaHostServiceTable.php b/application/tables/IcingaHostServiceTable.php index e8520c0a..38e61eba 100644 --- a/application/tables/IcingaHostServiceTable.php +++ b/application/tables/IcingaHostServiceTable.php @@ -67,7 +67,7 @@ class IcingaHostServiceTable extends QuickTable } } - return $this->url('director/service', $params); + return $this->url('director/service/edit', $params); } public function getTitles() From 5407c4fe7c0c5c5735a4b8df369ba69e2623b463 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 26 Oct 2016 00:17:03 +0000 Subject: [PATCH 05/10] ObjectsController: template table for templates... ...but load the other one first to trick the autoloader --- application/tables/IcingaHostTemplateTable.php | 1 - library/Director/Web/Controller/ObjectsController.php | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/application/tables/IcingaHostTemplateTable.php b/application/tables/IcingaHostTemplateTable.php index d35a126c..0d01004a 100644 --- a/application/tables/IcingaHostTemplateTable.php +++ b/application/tables/IcingaHostTemplateTable.php @@ -4,7 +4,6 @@ namespace Icinga\Module\Director\Tables; use Icinga\Module\Director\Tables\IcingaHostTable; -require_once __DIR__ . '/IcingaHostTable.php'; class IcingaHostTemplateTable extends IcingaHostTable { protected $searchColumns = array( diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index 550f3185..9ea258b4 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -112,7 +112,10 @@ abstract class ObjectsController extends ActionController $table = 'icinga' . ucfirst($type); } elseif ($dummy->isTemplate()) { $this->getTabs()->activate('templates'); + // Trick the autoloader $table = 'icinga' . ucfirst($type); + $this->loadTable($table); + $table .= 'Template'; } else { $this->getTabs()->activate('objects'); $table = 'icinga' . ucfirst($type); From b39e7efce7e1f1d92a85217c1c453cb812dd4b55 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Nov 2016 16:02:28 +0100 Subject: [PATCH 06/10] ObjectForm: allow to preset imports --- .../Web/Controller/ObjectController.php | 3 +++ .../Director/Web/Form/DirectorObjectForm.php | 22 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index b43be537..779ec34f 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -9,6 +9,7 @@ use Icinga\Exception\NotFoundError; use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\Objects\IcingaObject; +use Icinga\Module\Director\Web\Form\DirectorObjectForm; use Icinga\Web\Url; abstract class ObjectController extends ActionController @@ -186,8 +187,10 @@ abstract class ObjectController extends ActionController $ltype = strtolower($type); $url = sprintf('director/%ss', $ltype); + /** @var DirectorObjectForm $form */ $form = $this->view->form = $this->loadForm('icinga' . ucfirst($type)) ->setDb($this->db()) + ->presetImports($this->params->shift('imports')) ->setApi($this->getApiIfAvailable()) ->setSuccessUrl($url); diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index b50dbe23..868d5679 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -45,12 +45,27 @@ abstract class DirectorObjectForm extends QuickForm /** @var CoreApi */ private $api; + private $presetImports; + public function setPreferredObjectType($type) { $this->preferredObjectType = $type; return $this; } + public function presetImports($imports) + { + if (! empty($imports)) { + if (is_array($imports)) { + $this->presetImports = $imports; + } else { + $this->presetImports = array($imports); + } + } + + return $this; + } + /** * @param array $values * @@ -248,7 +263,7 @@ abstract class DirectorObjectForm extends QuickForm unset($props['vars']); } - $this->setDefaults($this->removeNullProperties($props)); + $this->setDefaults($this->removeEmptyProperties($props)); if ($resolve) { $this->showInheritedProperties($object); @@ -270,11 +285,11 @@ abstract class DirectorObjectForm extends QuickForm } } - protected function removeNullProperties($props) + protected function removeEmptyProperties($props) { $result = array(); foreach ($props as $k => $v) { - if ($v !== null && $v !== '') { + if ($v !== null && $v !== '' && $v !== array()) { $result[$k] = $v; } } @@ -913,6 +928,7 @@ abstract class DirectorObjectForm extends QuickForm 'required' => ($required !== null ? $required : !$this->isTemplate()), 'multiOptions' => $this->optionallyAddFromEnum($enum), 'sorted' => true, + 'value' => $this->presetImports, 'class' => 'autosubmit' )); From 2372b40a96a04425e700e88b5d1c5e6ae426ff47 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Nov 2016 16:02:58 +0100 Subject: [PATCH 07/10] IcingaHostTemplateTable: do not show inheritance ...for now --- application/tables/IcingaHostTemplateTable.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/tables/IcingaHostTemplateTable.php b/application/tables/IcingaHostTemplateTable.php index 0d01004a..3c3d3bdf 100644 --- a/application/tables/IcingaHostTemplateTable.php +++ b/application/tables/IcingaHostTemplateTable.php @@ -36,6 +36,9 @@ class IcingaHostTemplateTable extends IcingaHostTable ) ) ); + + /* + // TODO: Not yet if ($cnt = $row->cnt_child_templates) { if ((int) $cnt === 1) { $title = $view->translate('Show one host template using this template'); @@ -79,7 +82,7 @@ class IcingaHostTemplateTable extends IcingaHostTable ); } - + */ } return $htm; From a3ecddcd9bbd2d8412b8c4e8a20b2584c2fede41 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Nov 2016 16:16:49 +0100 Subject: [PATCH 08/10] Revert "IcingaServiceTable: strip down the service table" Will be added later on This reverts commit cf6f9d42e2a8cfa847f35094a47f72d233491ef8. --- application/tables/IcingaServiceTable.php | 55 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php index 222120d3..433dc12a 100644 --- a/application/tables/IcingaServiceTable.php +++ b/application/tables/IcingaServiceTable.php @@ -23,6 +23,11 @@ class IcingaServiceTable extends QuickTable ); } + protected function listTableClasses() + { + return array_merge(array('assignment-table'), parent::listTableClasses()); + } + protected function getActionUrl($row) { // TODO: Remove once we got a separate apply table @@ -33,7 +38,55 @@ class IcingaServiceTable extends QuickTable } - return $this->url('director/service/edit', $params); + return $this->url('director/service', $params); + } + + protected function renderRow($row) + { + $v = $this->view(); + $extra = $this->appliedOnes($row->id); + $htm = " getRowClassesString($row) . ">\n"; + $htm .= '' . $v->qlink($row->service, $this->getActionUrl($row)); + if (empty($extra)) { + if ($row->check_command_id) { + $htm .= ' ' . $v->qlink( + 'Create apply-rule', + 'director/service/add', + array('apply' => $row->service), + array('class' => 'icon-plus') + ); + } + + } else { + $htm .= '. Related apply rules: '; + foreach ($extra as $service) { + $href = $v->url('director/service', array('id' => $service->id)); + $htm .= ""; + + try { + $prettyFilter = AssignRenderer::forFilter( + Filter::fromQueryString($service->assign_filter) + )->renderAssign(); + } + catch (IcingaException $e) { + // ignore errors in filter rendering + $prettyFilter = 'Error in Filter rendering: ' . $e->getMessage(); + } + + $htm .= "'; + $htm .= ''; + $htm .= ''; + } + $htm .= '
" . $service->object_name . '' . $prettyFilter . '
'; + $htm .= $v->qlink( + 'Add more', + 'director/service/add', + array('apply' => $row->service), + array('class' => 'icon-plus') + ); + } + $htm .= ''; + return $htm . " \n"; } public function getTitles() From 14908d11a4ef103e48c4130cf6259fd8ebcda4a9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Nov 2016 16:17:18 +0100 Subject: [PATCH 09/10] ServiceController: disable overview for now --- application/controllers/ServiceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index dfa2439e..c53ac8b7 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -99,7 +99,7 @@ class ServiceController extends ObjectController } } - public function indexAction() + public function futureoverviewIndexAction() { $object = $this->loadObject(); $title = $this->view->title = $object->object_name; From 5b1b733852051929156b7871be3f91fd1205c7ed Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 16 Nov 2016 16:18:22 +0100 Subject: [PATCH 10/10] css: highlight disabled objects fixes #11877 --- public/css/module.less | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/css/module.less b/public/css/module.less index a1c0ace2..7ac9c527 100644 --- a/public/css/module.less +++ b/public/css/module.less @@ -791,6 +791,11 @@ table th.actions, table td.actions { text-align: right; } +table tr.disabled td { + color: @gray-light; + font-style: italic; +} + /* Simple table, test */ table.syncstate { tr td:first-child {