From 7d993422740ff057aa77492b8ef6cab5a2e19690 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Wed, 3 Jun 2015 13:02:44 +0200 Subject: [PATCH] Timeperiod: Add form, table, object and actions --- application/controllers/ListController.php | 11 ++++ application/controllers/ObjectController.php | 16 ++++++ application/forms/IcingaTimeperiodForm.php | 54 +++++++++++++++++++ application/tables/IcingaTimeperiodTable.php | 48 +++++++++++++++++ configuration.php | 2 + library/Director/Objects/IcingaTimeperiod.php | 17 ++++++ 6 files changed, 148 insertions(+) create mode 100644 application/forms/IcingaTimeperiodForm.php create mode 100644 application/tables/IcingaTimeperiodTable.php create mode 100644 library/Director/Objects/IcingaTimeperiod.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index b228c0c5..fdf009a2 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -48,6 +48,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function timeperiodsAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Timeperiod'), + 'director/object/timeperiod' + ); + $this->view->title = $this->translate('Icinga Timeperiods'); + $this->view->table = $this->loadTable('icingaTimeperiod')->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 dfde3464..b1107e2e 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -175,6 +175,22 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function timeperiodAction() + { + $this->view->form = $this->loadForm('icingaTimeperiod') + ->setDb($this->db()) + ->setSuccessUrl('director/list/timeperiods'); + + if ($id = $this->params->get('id')) { + $this->view->form->loadObject($id); + $this->view->title = $this->translate('Modify Icinga Timeperiod'); + } else { + $this->view->title = $this->translate('Add new Icinga Timeperiod'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function zoneAction() { $this->view->form = $this->loadForm('icingaZone') diff --git a/application/forms/IcingaTimeperiodForm.php b/application/forms/IcingaTimeperiodForm.php new file mode 100644 index 00000000..4526ec0b --- /dev/null +++ b/application/forms/IcingaTimeperiodForm.php @@ -0,0 +1,54 @@ +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' => 'Timeperiod object', + 'template' => 'Timeperiod template', + ) + )); + + if ($isTemplate) { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Timeperiod template name'), + 'required' => true, + 'description' => $this->translate('Name for the Icinga timperiod template you are going to create') + )); + } else { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Timeperiod'), + 'required' => true, + 'description' => $this->translate('Name for the Icinga timeperiod you are going to create') + )); + } + + $this->addElement('text', 'display_name', array( + 'label' => $this->translate('Display Name'), + 'description' => $this->translate('the display name') + )); + + $this->addElement('text', 'update_method', array( + 'label' => $this->translate('Update Method'), + 'description' => $this->translate('the update method'), + )); + + $this->addElement('select', 'zone_id', array( + 'label' => $this->translate('Cluster Zone'), + 'description' => $this->translate('Check this host in this specific Icinga cluster zone'), + 'required' => true + )); + + $this->addElement('submit', $this->translate('Store')); + } +} diff --git a/application/tables/IcingaTimeperiodTable.php b/application/tables/IcingaTimeperiodTable.php new file mode 100644 index 00000000..4cf16f5d --- /dev/null +++ b/application/tables/IcingaTimeperiodTable.php @@ -0,0 +1,48 @@ + 't.id', + 'timeperiod' => 't.object_name', + 'display_name' => 't.display_name', + 'zone' => 'z.object_name', + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/timeperiod', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'timeperiod' => $view->translate('Timeperiod'), + 'display_name' => $view->translate('Display Name'), + 'zone' => $view->translate('Zone'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('t' => 'icinga_timeperiod'), + $this->getColumns() + )->joinLeft( + array('z' => 'icinga_zone'), + 't.zone_id = z.id', + array() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index 6c7fe5c0..db9c8c88 100644 --- a/configuration.php +++ b/configuration.php @@ -9,6 +9,8 @@ $section->add($this->translate('Commands')) ->setUrl('director/list/commands'); $section->add($this->translate('Command Arguments')) ->setUrl('director/list/commandarguments'); +$section->add($this->translate('Timeperiods')) + ->setUrl('director/list/timeperiods'); $section->add($this->translate('Hosts')) ->setUrl('director/list/hosts'); $section->add($this->translate('Hostgroups')) diff --git a/library/Director/Objects/IcingaTimeperiod.php b/library/Director/Objects/IcingaTimeperiod.php new file mode 100644 index 00000000..330d256d --- /dev/null +++ b/library/Director/Objects/IcingaTimeperiod.php @@ -0,0 +1,17 @@ + null, + 'zone_id' => null, + 'object_name' => null, + 'display_name' => null, + 'update_method' => null, + 'object_type' => null, + ); +}