From 8d25b84f208228f6eed2bf699ae28f3650188a52 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 2 Jun 2015 11:56:42 +0200 Subject: [PATCH] Servicegroup: Add form, table, object and actions --- application/controllers/ListController.php | 11 +++++ application/controllers/ObjectController.php | 16 +++++++ application/forms/IcingaServicegroupForm.php | 43 +++++++++++++++++++ .../tables/IcingaServicegroupTable.php | 42 ++++++++++++++++++ configuration.php | 2 + .../Director/Objects/IcingaServicegroup.php | 15 +++++++ 6 files changed, 129 insertions(+) create mode 100644 application/forms/IcingaServicegroupForm.php create mode 100644 application/tables/IcingaServicegroupTable.php create mode 100644 library/Director/Objects/IcingaServicegroup.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 4753ff5e..32f6bb7b 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 servicegroupsAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Servicegroup'), + 'director/object/servicegroup' + ); + $this->view->title = $this->translate('Icinga Servicegroups'); + $this->view->table = $this->loadTable('icingaServicegroup')->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 0b072def..14be5a1e 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -36,6 +36,22 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function servicegroupAction() + { + $this->view->form = $this->loadForm('icingaServicegroup') + ->setDb($this->db()) + ->setSuccessUrl('director/list/servicegroups'); + + if ($id = $this->params->get('id')) { + $this->view->form->loadObject($id); + $this->view->title = $this->translate('Modify Icinga Servicegroup'); + } else { + $this->view->title = $this->translate('Add new Icinga Servicegroup'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function commandAction() { $this->view->form = $this->loadForm('icingaCommand') diff --git a/application/forms/IcingaServicegroupForm.php b/application/forms/IcingaServicegroupForm.php new file mode 100644 index 00000000..8b2967fe --- /dev/null +++ b/application/forms/IcingaServicegroupForm.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' => 'Servicegroup object', + 'template' => 'Servicegroup template', + ) + )); + + if ($isTemplate) { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Servicegroup template name'), + 'required' => true, + 'description' => $this->translate('Servicegroup for the Icinga servicegroup template you are going to create') + )); + } else { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Servicegroup'), + 'required' => true, + 'description' => $this->translate('Servicegroup for the Icinga servicegroup 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/IcingaServicegroupTable.php b/application/tables/IcingaServicegroupTable.php new file mode 100644 index 00000000..9c376a79 --- /dev/null +++ b/application/tables/IcingaServicegroupTable.php @@ -0,0 +1,42 @@ + 'sg.id', + 'servicegroup' => 'sg.object_name', + 'display_name' => 'sg.display_name' + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/servicegroup', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'servicegroup' => $view->translate('Servicegroup'), + 'display_name' => $view->translate('Display Name'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('sg' => 'icinga_servicegroup'), + $this->getColumns() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index 894a948f..2cb9cfd9 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('Servicegroups')) + ->setUrl('director/list/servicegroups'); $section->add($this->translate('Users')) ->setUrl('director/list/users'); $section->add($this->translate('Endpoints')) diff --git a/library/Director/Objects/IcingaServicegroup.php b/library/Director/Objects/IcingaServicegroup.php new file mode 100644 index 00000000..0f66592d --- /dev/null +++ b/library/Director/Objects/IcingaServicegroup.php @@ -0,0 +1,15 @@ + null, + 'object_name' => null, + 'display_name' => null, + 'object_type' => null, + ); +}