Service: Add form, table, object and actions

This commit is contained in:
Alexander Fuhr 2015-06-03 14:34:54 +02:00
parent 7d99342274
commit 0c66f23430
6 changed files with 212 additions and 2 deletions

View File

@ -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(

View File

@ -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')

View File

@ -0,0 +1,85 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaServiceForm extends DirectorObjectForm
{
public function setup()
{
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
$this->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'));
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaServiceTable extends QuickTable
{
public function getColumns()
{
return array(
'id' => '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);
}
}

View File

@ -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);

View File

@ -0,0 +1,36 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaService extends IcingaObject
{
protected $table = 'icinga_service';
protected $defaultProperties = array(
'id' => 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,
);
}