HostgroupVars: Add form, table, object and actions

This commit is contained in:
Alexander Fuhr 2015-06-03 12:05:50 +02:00
parent a4a97db6c3
commit c61656c46c
6 changed files with 149 additions and 0 deletions

View File

@ -37,6 +37,17 @@ class Director_ListController extends ActionController
$this->render('table'); $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() public function servicegroupsAction()
{ {
$this->view->addLink = $this->view->qlink( $this->view->addLink = $this->view->qlink(

View File

@ -36,6 +36,26 @@ class Director_ObjectController extends ActionController
$this->render('form'); $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() public function hostgroupmemberAction()
{ {
$this->view->form = $this->loadForm('icingaHostgroupMember') $this->view->form = $this->loadForm('icingaHostgroupMember')

View File

@ -0,0 +1,35 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaHostVarForm extends DirectorObjectForm
{
public function setup()
{
$this->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'));
}
}

View File

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

View File

@ -15,6 +15,8 @@ $section->add($this->translate('Hostgroups'))
->setUrl('director/list/hostgroups'); ->setUrl('director/list/hostgroups');
$section->add($this->translate('Hostgroup Members')) $section->add($this->translate('Hostgroup Members'))
->setUrl('director/list/hostgroupmembers'); ->setUrl('director/list/hostgroupmembers');
$section->add($this->translate('Host Vars'))
->setUrl('director/list/hostvars');
$section->add($this->translate('Servicegroups')) $section->add($this->translate('Servicegroups'))
->setUrl('director/list/servicegroups'); ->setUrl('director/list/servicegroups');
$section->add($this->translate('Users')) $section->add($this->translate('Users'))

View File

@ -0,0 +1,29 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaHostVar extends IcingaObject
{
protected $keyName = array('host_id', 'varname');
protected $table = 'icinga_host_var';
protected $defaultProperties = array(
'host_id' => null,
'varname' => null,
'varvalue' => null,
'format' => null,
);
public function onInsert()
{
}
public function onUpdate()
{
}
public function onDelete()
{
}
}