From db8059c4b79446510e8cdfadc510e20f9426cb15 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 9 Jun 2015 11:55:48 +0200 Subject: [PATCH] ServiceVars: Add form, table, object and actions --- application/controllers/ListController.php | 11 ++++ application/controllers/ObjectController.php | 20 +++++++ application/forms/IcingaServiceVarForm.php | 34 ++++++++++++ application/tables/IcingaServiceVarTable.php | 52 +++++++++++++++++++ configuration.php | 2 + library/Director/Objects/IcingaServiceVar.php | 29 +++++++++++ 6 files changed, 148 insertions(+) create mode 100644 application/forms/IcingaServiceVarForm.php create mode 100644 application/tables/IcingaServiceVarTable.php create mode 100644 library/Director/Objects/IcingaServiceVar.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index efa585d5..ba513fa0 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -92,6 +92,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function servicevarsAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Service Variable'), + 'director/object/servicevar' + ); + $this->view->title = $this->translate('Icinga Service Variables'); + $this->view->table = $this->loadTable('icingaServiceVar')->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 3d21a08d..d9123aa9 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -134,6 +134,26 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function servicevarAction() + { + $this->view->form = $this->loadForm('icingaServiceVar') + ->setDb($this->db()) + ->setSuccessUrl('director/list/servicevars'); + + if (($host_id = $this->params->get('service_id')) + && ($varname = $this->params->get('varname'))) { + $this->view->form->loadObject(array( + 'service_id' => $host_id, + 'varname' => $varname, + )); + $this->view->title = $this->translate('Modify Icinga Service Variable'); + } else { + $this->view->title = $this->translate('Add new Icinga Service Variable'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function commandAction() { $this->view->form = $this->loadForm('icingaCommand') diff --git a/application/forms/IcingaServiceVarForm.php b/application/forms/IcingaServiceVarForm.php new file mode 100644 index 00000000..57936925 --- /dev/null +++ b/application/forms/IcingaServiceVarForm.php @@ -0,0 +1,34 @@ +addElement('select', 'service_id', array( + 'label' => $this->translate('Service'), + 'description' => $this->translate('The name of the service'), + 'required' => true + )); + + $this->addElement('text', 'varname', array( + 'label' => $this->translate('Name'), + 'description' => $this->translate('service var name') + )); + + $this->addElement('textarea', 'varvalue', array( + 'label' => $this->translate('Value'), + 'description' => $this->translate('service 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/IcingaServiceVarTable.php b/application/tables/IcingaServiceVarTable.php new file mode 100644 index 00000000..c15d1331 --- /dev/null +++ b/application/tables/IcingaServiceVarTable.php @@ -0,0 +1,52 @@ + 'sv.service_id', + 'service' => 'h.object_name', + 'varname' => 'sv.varname', + 'varvalue' => 'sv.varvalue', + 'format' => 'sv.format', + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/servicevar', array( + 'service_id' => $row->service_id, + 'varname' => $row->varname, + )); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'service' => $view->translate('Service'), + 'varname' => $view->translate('Name'), + 'varvalue' => $view->translate('Value'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('sv' => 'icinga_service_var'), + $this->getColumns() + )->join( + array('h' => 'icinga_service'), + 'sv.service_id = h.id', + array() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index cf935254..f32e1b3c 100644 --- a/configuration.php +++ b/configuration.php @@ -31,6 +31,8 @@ $section->add($this->translate('Servicegroups')) ->setUrl('director/list/servicegroups'); $section->add($this->translate('Serviceroup Members')) ->setUrl('director/list/servicegroupmembers'); +$section->add($this->translate('Service Vars')) + ->setUrl('director/list/servicevars'); // USER $section->add($this->translate('Users')) diff --git a/library/Director/Objects/IcingaServiceVar.php b/library/Director/Objects/IcingaServiceVar.php new file mode 100644 index 00000000..0b855b28 --- /dev/null +++ b/library/Director/Objects/IcingaServiceVar.php @@ -0,0 +1,29 @@ + null, + 'varname' => null, + 'varvalue' => null, + 'format' => null, + ); + + public function onInsert() + { + } + + public function onUpdate() + { + } + + public function onDelete() + { + } +}