diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index fdf009a2..16e92c07 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -59,6 +59,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function servicesAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Service'), + 'director/object/service' + ); + $this->view->title = $this->translate('Icinga Services'); + $this->view->table = $this->loadTable('icingaService')->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 b1107e2e..1eddb677 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -79,6 +79,22 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function serviceAction() + { + $this->view->form = $this->loadForm('icingaService') + ->setDb($this->db()) + ->setSuccessUrl('director/list/services'); + + if ($id = $this->params->get('id')) { + $this->view->form->loadObject($id); + $this->view->title = $this->translate('Modify Icinga Service'); + } else { + $this->view->title = $this->translate('Add new Icinga Service'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function servicegroupAction() { $this->view->form = $this->loadForm('icingaServicegroup') diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php new file mode 100644 index 00000000..6c2af94e --- /dev/null +++ b/application/forms/IcingaServiceForm.php @@ -0,0 +1,85 @@ +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' => 'Service object', + 'template' => 'Service template', + ), + 'class' => 'autosubmit' + )); + + if ($isTemplate) { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Service template name'), + 'required' => true, + 'description' => $this->translate('Name for the Icinga service template you are going to create') + )); + } else { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Servicename'), + 'required' => true, + 'description' => $this->translate('Servicename for the Icinga service you are going to create') + )); + } + + $this->addElement('select', 'check_command_id', array( + 'label' => $this->translate('Check command'), + 'description' => $this->translate('Check command definition') + )); + + $this->optionalBoolean( + 'enable_notifications', + $this->translate('Send notifications'), + $this->translate('Whether to send notifications for this service') + ); + + $this->optionalBoolean( + 'enable_active_checks', + $this->translate('Execute active checks'), + $this->translate('Whether to actively check this service') + ); + + $this->optionalBoolean( + 'enable_passive_checks', + $this->translate('Accept passive checks'), + $this->translate('Whether to accept passive check results for this service') + ); + + $this->optionalBoolean( + 'enable_event_handler', + $this->translate('Enable event handler'), + $this->translate('Whether to enable event handlers this service') + ); + + $this->optionalBoolean( + 'enable_perfdata', + $this->translate('Process performance data'), + $this->translate('Whether to process performance data provided by this service') + ); + + $this->optionalBoolean( + 'volatile', + $this->translate('Volatile'), + $this->translate('Whether this check is volatile.') + ); + + $this->addElement('select', 'zone_id', array( + 'label' => $this->translate('Cluster Zone'), + 'description' => $this->translate('Check this host in this specific Icinga cluster zone') + )); + + $this->addElement('submit', $this->translate('Store')); + } +} diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php new file mode 100644 index 00000000..242ca9b4 --- /dev/null +++ b/application/tables/IcingaServiceTable.php @@ -0,0 +1,46 @@ + 's.id', + 'service' => 's.object_name', + 'zone' => 'z.object_name', + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/service', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'service' => $view->translate('Servicename'), + 'zone' => $view->translate('Zone'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('s' => 'icinga_service'), + $this->getColumns() + )->joinLeft( + array('z' => 'icinga_zone'), + 's.zone_id = z.id', + array() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index db9c8c88..191c9cda 100644 --- a/configuration.php +++ b/configuration.php @@ -3,14 +3,18 @@ $section = $this->menuSection($this->translate('Icinga Director')); $section->setIcon('cubes'); -$section->add($this->translate('Zones')) - ->setUrl('director/list/zones'); + +// COMMAND $section->add($this->translate('Commands')) ->setUrl('director/list/commands'); $section->add($this->translate('Command Arguments')) ->setUrl('director/list/commandarguments'); + +// KA $section->add($this->translate('Timeperiods')) ->setUrl('director/list/timeperiods'); + +// HOST $section->add($this->translate('Hosts')) ->setUrl('director/list/hosts'); $section->add($this->translate('Hostgroups')) @@ -19,14 +23,26 @@ $section->add($this->translate('Hostgroup Members')) ->setUrl('director/list/hostgroupmembers'); $section->add($this->translate('Host Vars')) ->setUrl('director/list/hostvars'); + +// SERVICE +$section->add($this->translate('Services')) + ->setUrl('director/list/services'); $section->add($this->translate('Servicegroups')) ->setUrl('director/list/servicegroups'); + +// USER $section->add($this->translate('Users')) ->setUrl('director/list/users'); $section->add($this->translate('Usergroups')) ->setUrl('director/list/usergroups'); + +// HA +$section->add($this->translate('Zones')) + ->setUrl('director/list/zones'); $section->add($this->translate('Endpoints')) ->setUrl('director/list/endpoints'); + +// INTERNAL $section->add($this->translate('Activity Log')) ->setUrl('director/list/activitylog') ->setPriority(900); diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php new file mode 100644 index 00000000..11a9e4ee --- /dev/null +++ b/library/Director/Objects/IcingaService.php @@ -0,0 +1,36 @@ + null, + 'object_name' => null, + 'display_name' => null, + 'check_command_id' => null, + 'max_check_attempts' => null, + 'check_period_id' => null, + 'check_interval' => null, + 'retry_interval' => null, + 'enable_notifications' => null, + 'enable_active_checks' => null, + 'enable_passive_checks' => null, + 'enable_event_handler' => null, + 'enable_flapping' => null, + 'enable_perfdata' => null, + 'event_command_id' => null, + 'flapping_threshold' => null, + 'volatile' => null, + 'zone_id' => null, + 'command_endpoint_id' => null, + 'notes' => null, + 'notes_url' => null, + 'action_url' => null, + 'icon_image' => null, + 'icon_image_alt' => null, + 'object_type' => null, + ); +}