From c61656c46c92db33fc22eaefcdecd064017b67ec Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Wed, 3 Jun 2015 12:05:50 +0200 Subject: [PATCH] HostgroupVars: Add form, table, object and actions --- application/controllers/ListController.php | 11 +++++ application/controllers/ObjectController.php | 20 ++++++++ application/forms/IcingaHostVarForm.php | 35 +++++++++++++ application/tables/IcingaHostVarTable.php | 52 ++++++++++++++++++++ configuration.php | 2 + library/Director/Objects/IcingaHostVar.php | 29 +++++++++++ 6 files changed, 149 insertions(+) create mode 100644 application/forms/IcingaHostVarForm.php create mode 100644 application/tables/IcingaHostVarTable.php create mode 100644 library/Director/Objects/IcingaHostVar.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index fcf66316..b228c0c5 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -37,6 +37,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function hostvarsAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Host Variable'), + 'director/object/hostvar' + ); + $this->view->title = $this->translate('Icinga Host Variables'); + $this->view->table = $this->loadTable('icingaHostVar')->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 0b62fde8..dfde3464 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -36,6 +36,26 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function hostvarAction() + { + $this->view->form = $this->loadForm('icingaHostVar') + ->setDb($this->db()) + ->setSuccessUrl('director/list/hostvars'); + + if (($host_id = $this->params->get('host_id')) + && ($varname = $this->params->get('varname'))) { + $this->view->form->loadObject(array( + 'host_id' => $host_id, + 'varname' => $varname, + )); + $this->view->title = $this->translate('Modify Icinga Host Variable'); + } else { + $this->view->title = $this->translate('Add new Icinga Host Variable'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function hostgroupmemberAction() { $this->view->form = $this->loadForm('icingaHostgroupMember') diff --git a/application/forms/IcingaHostVarForm.php b/application/forms/IcingaHostVarForm.php new file mode 100644 index 00000000..151c46d6 --- /dev/null +++ b/application/forms/IcingaHostVarForm.php @@ -0,0 +1,35 @@ +addElement('select', 'host_id', array( + 'label' => $this->translate('Host'), + 'description' => $this->translate('The name of the host'), + 'required' => true + )); + + $this->addElement('text', 'varname', array( + 'label' => $this->translate('Name'), + 'description' => $this->translate('host var name') + )); + + $this->addElement('textarea', 'varvalue', array( + 'label' => $this->translate('Value'), + 'description' => $this->translate('host var value') + )); + + $this->addElement('text', 'format', array( + 'label' => $this->translate('Format'), + 'description' => $this->translate('value format') + )); + + $this->addElement('submit', $this->translate('Store')); + } +} diff --git a/application/tables/IcingaHostVarTable.php b/application/tables/IcingaHostVarTable.php new file mode 100644 index 00000000..0771cb77 --- /dev/null +++ b/application/tables/IcingaHostVarTable.php @@ -0,0 +1,52 @@ + 'hv.host_id', + 'host' => 'h.object_name', + 'varname' => 'hv.varname', + 'varvalue' => 'hv.varvalue', + 'format' => 'hv.format', + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/hostvar', array( + 'host_id' => $row->host_id, + 'varname' => $row->varname, + )); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'host' => $view->translate('Host'), + 'varname' => $view->translate('Name'), + 'varvalue' => $view->translate('Value'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('hv' => 'icinga_host_var'), + $this->getColumns() + )->join( + array('h' => 'icinga_host'), + 'hv.host_id = h.id', + array() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index a2f65fc7..6c7fe5c0 100644 --- a/configuration.php +++ b/configuration.php @@ -15,6 +15,8 @@ $section->add($this->translate('Hostgroups')) ->setUrl('director/list/hostgroups'); $section->add($this->translate('Hostgroup Members')) ->setUrl('director/list/hostgroupmembers'); +$section->add($this->translate('Host Vars')) + ->setUrl('director/list/hostvars'); $section->add($this->translate('Servicegroups')) ->setUrl('director/list/servicegroups'); $section->add($this->translate('Users')) diff --git a/library/Director/Objects/IcingaHostVar.php b/library/Director/Objects/IcingaHostVar.php new file mode 100644 index 00000000..45656d5e --- /dev/null +++ b/library/Director/Objects/IcingaHostVar.php @@ -0,0 +1,29 @@ + null, + 'varname' => null, + 'varvalue' => null, + 'format' => null, + ); + + public function onInsert() + { + } + + public function onUpdate() + { + } + + public function onDelete() + { + } +}