From a4a97db6c3d25335cc452d8d9bd09895a863beb7 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 2 Jun 2015 17:37:54 +0200 Subject: [PATCH] HostgroupMember: Add form, table, object and actions --- application/controllers/ListController.php | 11 ++++ application/controllers/ObjectController.php | 23 ++++++++ .../forms/IcingaHostgroupMemberForm.php | 23 ++++++++ .../tables/IcingaCommandArgumentTable.php | 6 +-- application/tables/IcingaCommandTable.php | 6 +-- .../tables/IcingaHostgroupMemberTable.php | 54 +++++++++++++++++++ configuration.php | 2 + .../Objects/IcingaHostgroupMember.php | 27 ++++++++++ 8 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 application/forms/IcingaHostgroupMemberForm.php create mode 100644 application/tables/IcingaHostgroupMemberTable.php create mode 100644 library/Director/Objects/IcingaHostgroupMember.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 67a42d6a..fcf66316 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -26,6 +26,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function hostgroupmembersAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Hostgroup Member'), + 'director/object/hostgroupmember' + ); + $this->view->title = $this->translate('Icinga Hostgroup Members'); + $this->view->table = $this->loadTable('icingaHostgroupMember')->setConnection($this->db()); + $this->render('table'); + } + public function servicegroupsAction() { $this->view->addLink = $this->view->qlink( diff --git a/application/controllers/ObjectController.php b/application/controllers/ObjectController.php index 95577c0e..0b62fde8 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -36,6 +36,29 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function hostgroupmemberAction() + { + $this->view->form = $this->loadForm('icingaHostgroupMember') + ->setDb($this->db()) + ->setSuccessUrl('director/list/hostgroupmembers'); + + if (($host_id = $this->params->get('host_id')) + && ($hostgroup_id = $this->params->get('hostgroup_id'))) { + + $this->view->form->loadObject( + array( + 'host_id' => $host_id, + 'hostgroup_id' => $hostgroup_id, + ) + ); + $this->view->title = $this->translate('Modify Icinga Hostgroup Member'); + } else { + $this->view->title = $this->translate('Add new Icinga Hostgroup Member'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function servicegroupAction() { $this->view->form = $this->loadForm('icingaServicegroup') diff --git a/application/forms/IcingaHostgroupMemberForm.php b/application/forms/IcingaHostgroupMemberForm.php new file mode 100644 index 00000000..db9ce1fd --- /dev/null +++ b/application/forms/IcingaHostgroupMemberForm.php @@ -0,0 +1,23 @@ +addElement('select', 'hostgroup_id', array( + 'label' => $this->translate('Hostgroup'), + 'description' => $this->translate('The name of the hostgroup') + )); + + $this->addElement('select', 'host_id', array( + 'label' => $this->translate('Host'), + 'description' => $this->translate('The name of the host') + )); + + $this->addElement('submit', $this->translate('Store')); + } +} diff --git a/application/tables/IcingaCommandArgumentTable.php b/application/tables/IcingaCommandArgumentTable.php index aea06568..b41953b0 100644 --- a/application/tables/IcingaCommandArgumentTable.php +++ b/application/tables/IcingaCommandArgumentTable.php @@ -26,9 +26,9 @@ class IcingaCommandArgumentTable extends QuickTable { $view = $this->view(); return array( - $view->translate('Command'), - $view->translate('Argument'), - $view->translate('Value'), + 'command' => $view->translate('Command'), + 'argument_name' => $view->translate('Argument'), + 'argument_value' => $view->translate('Value'), ); } diff --git a/application/tables/IcingaCommandTable.php b/application/tables/IcingaCommandTable.php index 9cea2ba9..176ef6fa 100644 --- a/application/tables/IcingaCommandTable.php +++ b/application/tables/IcingaCommandTable.php @@ -25,9 +25,9 @@ class IcingaCommandTable extends QuickTable { $view = $this->view(); return array( - $view->translate('Command'), - $view->translate('Command line'), - $view->translate('Zone'), + 'command' => $view->translate('Command'), + 'command_line' => $view->translate('Command line'), + 'zone' => $view->translate('Zone'), ); } diff --git a/application/tables/IcingaHostgroupMemberTable.php b/application/tables/IcingaHostgroupMemberTable.php new file mode 100644 index 00000000..2f73ffa2 --- /dev/null +++ b/application/tables/IcingaHostgroupMemberTable.php @@ -0,0 +1,54 @@ + 'hg.id', + 'host_id' => 'h.id', + 'hostgroup' => 'hg.object_name', + 'host' => 'h.object_name' + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/hostgroupmember', array( + 'hostgroup_id' => $row->hostgroup_id, + 'host_id' => $row->host_id, + )); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'hostgroup' => $view->translate('Hostgroup'), + 'host' => $view->translate('Member'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('hg' => 'icinga_hostgroup'), + $this->getColumns() + )->join( + array('hgh' => 'icinga_hostgroup_host'), + 'hgh.hostgroup_id = hg.id', + array() + )->join( + array('h' => 'icinga_host'), + 'hgh.host_id = h.id', + array() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index 4d1e2d1c..a2f65fc7 100644 --- a/configuration.php +++ b/configuration.php @@ -13,6 +13,8 @@ $section->add($this->translate('Hosts')) ->setUrl('director/list/hosts'); $section->add($this->translate('Hostgroups')) ->setUrl('director/list/hostgroups'); +$section->add($this->translate('Hostgroup Members')) + ->setUrl('director/list/hostgroupmembers'); $section->add($this->translate('Servicegroups')) ->setUrl('director/list/servicegroups'); $section->add($this->translate('Users')) diff --git a/library/Director/Objects/IcingaHostgroupMember.php b/library/Director/Objects/IcingaHostgroupMember.php new file mode 100644 index 00000000..3c4eb9f6 --- /dev/null +++ b/library/Director/Objects/IcingaHostgroupMember.php @@ -0,0 +1,27 @@ + null, + 'host_id' => null, + ); + + public function onInsert() + { + } + + public function onUpdate() + { + } + + public function onDelete() + { + } +} \ No newline at end of file