From 0459ec95f9816f456c12ebef8a8835cbd55b7e82 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 2 Jun 2015 10:49:31 +0200 Subject: [PATCH] Hostgroup: Add form, table, object and actions --- application/controllers/ListController.php | 11 +++++ application/controllers/ObjectController.php | 16 ++++++++ application/forms/IcingaHostgroupForm.php | 43 ++++++++++++++++++++ application/tables/IcingaHostgroupTable.php | 42 +++++++++++++++++++ configuration.php | 2 + library/Director/Objects/IcingaHostgroup.php | 15 +++++++ 6 files changed, 129 insertions(+) create mode 100644 application/forms/IcingaHostgroupForm.php create mode 100644 application/tables/IcingaHostgroupTable.php create mode 100644 library/Director/Objects/IcingaHostgroup.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index ea3e6fe4..4753ff5e 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -15,6 +15,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function hostgroupsAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Hostgroup'), + 'director/object/hostgroup' + ); + $this->view->title = $this->translate('Icinga Hostgroups'); + $this->view->table = $this->loadTable('icingaHostgroup')->setConnection($this->db()); + $this->render('table'); + } + public function commandsAction() { $this->view->addLink = $this->view->qlink( diff --git a/application/controllers/ObjectController.php b/application/controllers/ObjectController.php index b70d352c..0b072def 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -20,6 +20,22 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function hostgroupAction() + { + $this->view->form = $this->loadForm('icingaHostgroup') + ->setDb($this->db()) + ->setSuccessUrl('director/list/hostgroups'); + + if ($id = $this->params->get('id')) { + $this->view->form->loadObject($id); + $this->view->title = $this->translate('Modify Icinga Hostgroup'); + } else { + $this->view->title = $this->translate('Add new Icinga Hostgroup'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function commandAction() { $this->view->form = $this->loadForm('icingaCommand') diff --git a/application/forms/IcingaHostgroupForm.php b/application/forms/IcingaHostgroupForm.php new file mode 100644 index 00000000..e3c612ac --- /dev/null +++ b/application/forms/IcingaHostgroupForm.php @@ -0,0 +1,43 @@ +addElement('select', 'object_type', array( + 'label' => $this->translate('Object type'), + 'description' => $this->translate('Whether this should be a template'), + 'multiOptions' => array( + null => '- please choose -', + 'object' => 'Hostgroup object', + 'template' => 'Hostgroup template', + ) + )); + + if ($isTemplate) { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Hostgroup template name'), + 'required' => true, + 'description' => $this->translate('Hostgroup for the Icinga hostgroup template you are going to create') + )); + } else { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Hostgroup'), + 'required' => true, + 'description' => $this->translate('Hostgroup for the Icinga hostgroup you are going to create') + )); + } + + $this->addElement('text', 'display_name', array( + 'label' => $this->translate('Display Name'), + 'description' => $this->translate('The name which should displayed.') + )); + + $this->addElement('submit', $this->translate('Store')); + } +} diff --git a/application/tables/IcingaHostgroupTable.php b/application/tables/IcingaHostgroupTable.php new file mode 100644 index 00000000..a1e705a9 --- /dev/null +++ b/application/tables/IcingaHostgroupTable.php @@ -0,0 +1,42 @@ + 'hg.id', + 'hostgroup' => 'hg.object_name', + 'display_name' => 'hg.display_name' + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/hostgroup', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'hostgroup' => $view->translate('Hostgroup'), + 'display_name' => $view->translate('Display Name'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('hg' => 'icinga_hostgroup'), + $this->getColumns() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index b8913848..894a948f 100644 --- a/configuration.php +++ b/configuration.php @@ -11,6 +11,8 @@ $section->add($this->translate('Command Arguments')) ->setUrl('director/list/commandarguments'); $section->add($this->translate('Hosts')) ->setUrl('director/list/hosts'); +$section->add($this->translate('Hostgroups')) + ->setUrl('director/list/hostgroups'); $section->add($this->translate('Users')) ->setUrl('director/list/users'); $section->add($this->translate('Endpoints')) diff --git a/library/Director/Objects/IcingaHostgroup.php b/library/Director/Objects/IcingaHostgroup.php new file mode 100644 index 00000000..b09e4fcf --- /dev/null +++ b/library/Director/Objects/IcingaHostgroup.php @@ -0,0 +1,15 @@ + null, + 'object_name' => null, + 'display_name' => null, + 'object_type' => null, + ); +}