Merge branch 'feature/service-set-12891'

This commit is contained in:
Thomas Gelf 2016-10-25 23:44:13 +00:00
commit 94ce4112c7
23 changed files with 740 additions and 125 deletions

View File

@ -69,6 +69,11 @@ class HostController extends ObjectController
'director/service/add', 'director/service/add',
array('host' => $host->object_name), array('host' => $host->object_name),
array('class' => 'icon-plus') array('class' => 'icon-plus')
) . ' ' . $this->view->qlink(
$this->translate('Add service set'),
'director/serviceset/add',
array('host' => $host->object_name),
array('class' => 'icon-plus')
); );
$this->getTabs()->activate('services'); $this->getTabs()->activate('services');
@ -120,6 +125,14 @@ class HostController extends ObjectController
$tables[$title] = $table->setTitle($title); $tables[$title] = $table->setTitle($title);
} }
$title = $this->translate('Service sets');
$table = $this->loadTable('IcingaHostServiceSet')
->setHost($host)
->setTitle($title)
->setConnection($db);
$tables[$title] = $table;
$this->view->tables = $tables; $this->view->tables = $tables;
} }

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\Web\Controller\ObjectController; use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Module\Director\Objects\IcingaServiceSet;
use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaHost;
@ -11,6 +12,8 @@ class ServiceController extends ObjectController
{ {
protected $host; protected $host;
protected $set;
protected $apply; protected $apply;
protected function beforeTabs() protected function beforeTabs()
@ -28,9 +31,9 @@ class ServiceController extends ObjectController
{ {
if ($host = $this->params->get('host')) { if ($host = $this->params->get('host')) {
$this->host = IcingaHost::load($host, $this->db()); $this->host = IcingaHost::load($host, $this->db());
} } elseif ($set = $this->params->get('set')) {
$this->set = IcingaServiceSet::load(array('object_name' => $set), $this->db());
if ($apply = $this->params->get('apply')) { } elseif ($apply = $this->params->get('apply')) {
$this->apply = IcingaService::load( $this->apply = IcingaService::load(
array('object_name' => $apply, 'object_type' => 'template'), array('object_name' => $apply, 'object_type' => 'template'),
$this->db() $this->db()
@ -45,6 +48,10 @@ class ServiceController extends ObjectController
$tab->getUrl()->setParam('host', $this->host->object_name); $tab->getUrl()->setParam('host', $this->host->object_name);
} }
} }
if (! $this->set && $this->object->service_set_id) {
$this->set = $this->object->getRelated('service_set');
}
} }
if ($this->host) { if ($this->host) {
@ -53,6 +60,12 @@ class ServiceController extends ObjectController
'urlParams' => array('name' => $this->host->object_name), 'urlParams' => array('name' => $this->host->object_name),
'label' => $this->translate('Services'), 'label' => $this->translate('Services'),
)); ));
} elseif ($this->host) {
$this->getTabs()->add('services', array(
'url' => 'director/serviceset/services',
'urlParams' => array('name' => $this->set->object_name),
'label' => $this->translate('Services'),
));
} }
} }
@ -61,9 +74,12 @@ class ServiceController extends ObjectController
parent::addAction(); parent::addAction();
if ($this->host) { if ($this->host) {
$this->view->title = $this->host->object_name . ': ' . $this->view->title; $this->view->title = $this->host->object_name . ': ' . $this->view->title;
} } elseif ($this->set) {
$this->view->title = sprintf(
if ($this->apply) { $this->translate('Add a service to "%s"'),
$this->set->object_name
);
} elseif ($this->apply) {
$this->view->title = sprintf( $this->view->title = sprintf(
$this->translate('Apply "%s"'), $this->translate('Apply "%s"'),
$this->apply->object_name $this->apply->object_name
@ -147,8 +163,15 @@ class ServiceController extends ObjectController
public function loadForm($name) public function loadForm($name)
{ {
$form = parent::loadForm($name); $form = parent::loadForm($name);
if ($name === 'icingaService' && $this->host) { if ($name === 'icingaService') {
if ($this->host) {
$form->setHost($this->host); $form->setHost($this->host);
} elseif ($this->set) {
$form->setServiceSet($this->set)->setSuccessUrl(
'director/serviceset/services',
array('name' => $this->set->object_name)
);
}
} }
return $form; return $form;
@ -166,6 +189,10 @@ class ServiceController extends ObjectController
$params['host_id'] = $this->host->id; $params['host_id'] = $this->host->id;
} }
if ($this->set) {
$this->view->set = $this->set;
$params['service_set_id'] = $this->set->id;
}
$this->object = IcingaService::load($params, $db); $this->object = IcingaService::load($params, $db);
} else { } else {
parent::loadObject(); parent::loadObject();

View File

@ -0,0 +1,97 @@
<?php
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaServiceSet;
use Icinga\Module\Director\Web\Controller\ObjectController;
class ServicesetController extends ObjectController
{
protected $host;
public function init()
{
if ($host = $this->params->get('host')) {
$this->host = IcingaHost::load($host, $this->db());
}
parent::init();
if ($this->object) {
$tabs = $this->getTabs();
$tabs->add('services', array(
'url' => 'director/serviceset/services',
'urlParams' => array('name' => $this->object->object_name),
'label' => 'Services'
));
}
}
public function loadForm($name)
{
$form = parent::loadForm($name);
if ($name === 'icingaServiceSet' && $this->host) {
$form->setHost($this->host);
}
return $form;
}
public function addAction()
{
parent::addAction();
if ($this->host) {
$this->view->title = sprintf(
$this->translate('Add a service set to "%s"'),
$this->host->object_name
);
}
}
public function servicesAction()
{
$db = $this->db();
$set = $this->object;
$this->view->addLink = $this->view->qlink(
$this->translate('Add service'),
'director/service/add',
array('set' => $set->object_name),
array('class' => 'icon-plus')
);
$this->view->stayHere = true;
$this->getTabs()->activate('services');
$this->view->title = sprintf(
$this->translate('Services in this set: %s'),
$set->object_name
);
$this->view->table = $this->loadTable('IcingaServiceSetService')
->setServiceSet($set)
->setConnection($db);
$this->setViewScript('objects/table');
}
protected function loadObject()
{
if ($this->object === null) {
if ($name = $this->params->get('name')) {
$params = array('object_name' => $name);
$db = $this->db();
if ($this->host) {
$this->view->host = $this->host;
$params['host_id'] = $this->host->id;
}
$this->object = IcingaServiceSet::load($params, $db);
} else {
parent::loadObject();
}
}
return $this->object;
}
}

View File

@ -17,7 +17,7 @@ class ShowController extends ActionController
protected function objectKey($entry) protected function objectKey($entry)
{ {
if ($entry->object_type === 'icinga_service') { if ($entry->object_type === 'icinga_service' || $entry->object_type === 'icinga_service_set') {
// TODO: this is not correct. Activity needs to get (multi) key support // TODO: this is not correct. Activity needs to get (multi) key support
return array('name' => $entry->object_name); return array('name' => $entry->object_name);
} }

View File

@ -7,11 +7,14 @@ use Icinga\Module\Director\Exception\NestingError;
use Icinga\Module\Director\Web\Form\DirectorObjectForm; use Icinga\Module\Director\Web\Form\DirectorObjectForm;
use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Objects\IcingaServiceSet;
class IcingaServiceForm extends DirectorObjectForm class IcingaServiceForm extends DirectorObjectForm
{ {
private $host; private $host;
private $set;
private $apply; private $apply;
private $hostGenerated = false; private $hostGenerated = false;
@ -52,7 +55,9 @@ class IcingaServiceForm extends DirectorObjectForm
// ignore for the form to load // ignore for the form to load
} }
if ($this->host === null) { if ($this->set !== null) {
$this->setupSetRelatedElements();
} elseif ($this->host === null) {
$this->setupServiceElements(); $this->setupServiceElements();
} else { } else {
$this->setupHostRelatedElements(); $this->setupHostRelatedElements();
@ -206,6 +211,44 @@ class IcingaServiceForm extends DirectorObjectForm
return $this; return $this;
} }
protected function setupSetRelatedElements()
{
$this->addHidden('service_set_id', $this->set->id);
$this->addHidden('object_type', 'apply');
$this->addImportsElement();
$imports = $this->getSentOrObjectValue('imports');
if ($this->hasBeenSent()) {
$imports = $this->getElement('imports')->setValue($imports)->getValue();
}
if ($this->isNew() && empty($imports)) {
return $this->groupMainProperties();
}
$this->addNameElement()
->addDisabledElement()
->groupMainProperties()
->addCheckCommandElements(true)
->addCheckExecutionElements(true)
->addExtraInfoElements()
->setButtons();
if ($this->hasBeenSent()) {
$name = $this->getSentOrObjectValue('object_name');
if (!strlen($name)) {
$this->setElementValue('object_name', end($imports));
$this->object->object_name = end($imports);
}
}
}
public function setServiceSet(IcingaServiceSet $set)
{
$this->set = $set;
return $this;
}
protected function addNameElement() protected function addNameElement()
{ {
$this->addElement('text', 'object_name', array( $this->addElement('text', 'object_name', array(

View File

@ -0,0 +1,132 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Objects\IcingaService;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaServiceSetForm extends DirectorObjectForm
{
protected $host;
public function setup()
{
if ($this->host === null) {
$this->setupTemplate();
} else {
$this->setupHost();
}
$this->setupFields()
->setButtons();
}
protected function setupFields()
{
$object = $this->object();
$this->assertResolvedImports();
if ($this->hasBeenSent() && $services = $this->getSentValue('service')) {
$object->service = $services;
}
if ($this->assertResolvedImports()) {
$this->fieldLoader($object)
->loadFieldsForMultipleObjects($object->getServiceObjects());
}
return $this;
}
protected function setupTemplate()
{
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Service set name'),
'description' => $this->translate(
'A short name identifying this set of services'
),
'required' => true,
));
$this->addHidden('object_type', 'template');
$this->addDescriptionElement()
->addAssignmentElements();
}
protected function setupHost()
{
$object = $this->object();
if ($this->hasBeenSent()) {
$object->object_name = $object->imports = $this->getSentValue('imports');
}
if (! $object->hasBeenLoadedFromDb()) {
$this->addSingleImportsElement();
}
if (count($object->imports)) {
$this->addHtmlHint(
$this->getView()->escape(
$object->getResolvedProperty('description')
)
);
}
$this->addHidden('object_type', 'object');
$this->addHidden('host_id', $this->host->id);
}
public function setHost(IcingaHost $host)
{
$this->host = $host;
return $this;
}
protected function addSingleImportsElement()
{
$enum = $this->enumAllowedTemplates();
$this->addElement('select', 'imports', array(
'label' => $this->translate('Service set'),
'description' => $this->translate(
'The service set that should be assigned to this host'
),
'required' => true,
'multiOptions' => $this->optionallyAddFromEnum($enum),
'class' => 'autosubmit'
));
return $this;
}
protected function addDescriptionElement()
{
$this->addElement('textarea', 'description', array(
'label' => $this->translate('Description'),
'description' => $this->translate(
'A meaningful description explaining your users what to expect'
. ' when assigning this set of services'
),
'rows' => '3',
'required' => ! $this->isTemplate(),
));
return $this;
}
protected function addAssignmentElements()
{
$this->addAssignFilter(array(
'columns' => IcingaHost::enumProperties($this->db, 'host.'),
'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want. You'
. ' might also want to skip this, define it later and/or just'
. ' add this set of services to single hosts'
)
));
return $this;
}
}

View File

@ -0,0 +1,79 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaHostServiceSetTable extends IcingaObjectTable
{
protected $title;
protected $host;
public function getColumns()
{
return array(
'id' => 'sset.id',
'name' => 'sset.object_name',
'object_type' => 'sset.object_type',
'description' => 'sset.description',
'host_name' => 'h.object_name',
);
}
public function getTitles()
{
$view = $this->view();
return array(
'name' => $view->translate('Service set'),
);
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function setHost(IcingaHost $host)
{
$this->host = $host;
return $this;
}
protected function getActionUrl($row)
{
// TODO: Remove once we got a separate apply table
if ($row->object_type === 'apply') {
$params['id'] = $row->id;
} else {
$params = array('name' => $row->name);
if ($row->host_name) {
$params['host'] = $row->host_name;
}
}
return $this->url('director/serviceset', $params);
}
protected function getUnfilteredQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('sset' => 'icinga_service_set'),
array()
)->joinLeft(
array('h' => 'icinga_host'),
'h.id = sset.host_id',
array()
)->where('sset.host_id = ?', $this->host->id)->order('sset.object_name');
return $query;
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery();
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Objects\IcingaServiceSet;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaServiceSetServiceTable extends QuickTable
{
protected $set;
protected $searchColumns = array(
'service',
);
public function getColumns()
{
return array(
'id' => 's.id',
'service_set_id' => 's.service_set_id',
'service_set' => 'ss.object_name',
'service' => 's.object_name',
'object_type' => 's.object_type',
);
}
public function setServiceSet(IcingaServiceSet $set)
{
$this->set = $set;
return $this;
}
protected function getActionUrl($row)
{
$params = array(
'name' => $row->service,
'set' => $row->service_set
);
return $this->url('director/service', $params);
}
public function getTitles()
{
$view = $this->view();
return array(
'service' => $view->translate('Servicename'),
);
}
public function getUnfilteredQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('s' => 'icinga_service'),
array()
)->joinLeft(
array('ss' => 'icinga_service_set'),
'ss.id = s.service_set_id',
array()
)->order('s.object_name');
return $query;
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery()->where(
's.service_set_id = ?',
$this->set->id
);
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
class IcingaServiceSetTable extends IcingaObjectTable
{
public function getColumns()
{
return array(
'id' => 'sset.id',
'name' => 'sset.object_name',
'object_type' => 'sset.object_type',
'description' => 'sset.description',
'host_name' => 'h.object_name',
);
}
public function getTitles()
{
$view = $this->view();
return array(
'name' => $view->translate('Service set'),
);
}
protected function getActionUrl($row)
{
// TODO: Remove once we got a separate apply table
if ($row->object_type === 'apply') {
$params['id'] = $row->id;
} else {
$params = array('name' => $row->name);
if ($row->host_name) {
$params['host'] = $row->host_name;
}
}
return $this->url('director/serviceset', $params);
}
protected function getUnfilteredQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('sset' => 'icinga_service_set'),
array()
)->joinLeft(
array('h' => 'icinga_host'),
'h.id = sset.host_id',
array()
)->where('sset.object_type = ?', 'template')->order('sset.object_name');
return $query;
}
public function getBaseQuery()
{
return $this->getUnfilteredQuery();
}
}

View File

@ -25,6 +25,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
'icinga_command_var', 'icinga_command_var',
'icinga_host_var', 'icinga_host_var',
'icinga_notification_var', 'icinga_notification_var',
'icinga_service_set_var',
'icinga_service_var', 'icinga_service_var',
'icinga_user_var', 'icinga_user_var',
); );

View File

@ -274,6 +274,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->relations[$property]; return $this->relations[$property];
} }
public function getRelated($property)
{
return $this->getRelatedObject($property, $this->{$property . '_id'});
}
protected function getRelatedObjectName($property, $id) protected function getRelatedObjectName($property, $id)
{ {
return $this->getRelatedObject($property, $id)->object_name; return $this->getRelatedObject($property, $id)->object_name;
@ -2071,6 +2076,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$type = 'timePeriod'; $type = 'timePeriod';
} elseif ($type === 'servicegroup') { } elseif ($type === 'servicegroup') {
$type = 'serviceGroup'; $type = 'serviceGroup';
} elseif ($type === 'service_set') {
$type = 'serviceSet';
} elseif ($type === 'apiuser') { } elseif ($type === 'apiuser') {
$type = 'apiUser'; $type = 'apiUser';
} }
@ -2335,6 +2342,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
if ($this->hasProperty('service_id') && $this->service_id) { if ($this->hasProperty('service_id') && $this->service_id) {
$params['service'] = $this->service; $params['service'] = $this->service;
} }
if ($this->hasProperty('service_set_id') && $this->service_set_id) {
$params['set'] = $this->service_set;
}
} }
return $params; return $params;

View File

@ -40,6 +40,11 @@ class IcingaObjectMultiRelations implements Iterator, Countable, IcingaConfigRen
$this->relatedObjectClass = $relatedObjectClass; $this->relatedObjectClass = $relatedObjectClass;
} }
public function getObjects()
{
return $this->relations;
}
public function count() public function count()
{ {
return count($this->relations); return count($this->relations);

View File

@ -18,6 +18,7 @@ class IcingaService extends IcingaObject
'disabled' => 'n', 'disabled' => 'n',
'display_name' => null, 'display_name' => null,
'host_id' => null, 'host_id' => null,
'service_set_id' => null,
'check_command_id' => null, 'check_command_id' => null,
'max_check_attempts' => null, 'max_check_attempts' => null,
'check_period_id' => null, 'check_period_id' => null,
@ -47,6 +48,7 @@ class IcingaService extends IcingaObject
protected $relations = array( protected $relations = array(
'host' => 'IcingaHost', 'host' => 'IcingaHost',
'service_set' => 'IcingaServiceSet',
'check_command' => 'IcingaCommand', 'check_command' => 'IcingaCommand',
'event_command' => 'IcingaCommand', 'event_command' => 'IcingaCommand',
'check_period' => 'IcingaTimePeriod', 'check_period' => 'IcingaTimePeriod',
@ -83,7 +85,7 @@ class IcingaService extends IcingaObject
protected $supportsSets = true; protected $supportsSets = true;
protected $keyName = array('host_id', 'object_name'); protected $keyName = array('host_id', 'service_set_id', 'object_name');
protected $prioritizedProperties = array('host_id'); protected $prioritizedProperties = array('host_id');
@ -123,7 +125,7 @@ class IcingaService extends IcingaObject
if (is_int($key)) { if (is_int($key)) {
$this->id = $key; $this->id = $key;
} elseif (is_array($key)) { } elseif (is_array($key)) {
foreach (array('id', 'host_id', 'object_name') as $k) { foreach (array('id', 'host_id', 'service_set_id', 'object_name') as $k) {
if (array_key_exists($k, $key)) { if (array_key_exists($k, $key)) {
$this->set($k, $key[$k]); $this->set($k, $key[$k]);
} }

View File

@ -17,6 +17,7 @@ class IcingaServiceSet extends IcingaObject
'object_name' => null, 'object_name' => null,
'object_type' => null, 'object_type' => null,
'description' => null, 'description' => null,
'assign_filter' => null,
); );
protected $keyName = array('host_id', 'object_name'); protected $keyName = array('host_id', 'object_name');
@ -31,10 +32,6 @@ class IcingaServiceSet extends IcingaObject
'host' => 'IcingaHost', 'host' => 'IcingaHost',
); );
protected $multiRelations = array(
'service' => 'IcingaService',
);
public function isDisabled() public function isDisabled()
{ {
return false; return false;
@ -50,34 +47,46 @@ class IcingaServiceSet extends IcingaObject
*/ */
public function getServiceObjects() public function getServiceObjects()
{ {
if (! $this->hasBeenLoadedFromDb()) { if ($this->host_id) {
$imports = $this->imports()->getObjects();
if (empty($imports)) {
return array();
}
return $this->getServiceObjectsForSet(array_shift($imports));
} else {
return $this->getServiceObjectsForSet($this);
}
}
protected function getServiceObjectsForSet(IcingaServiceSet $set)
{
if ($set->id === null) {
return array(); return array();
} }
$conn = $this->getConnection(); $connection = $this->getConnection();
$db = $conn->getDbAdapter(); $db = $this->getDb();
$ids = $db->fetchCol(
$db->select()->from('icinga_service', 'id')
->where('service_set_id = ?', $set->id)
);
$query = $db->select()->from( $services = array();
array('s' => 'icinga_service'), foreach ($ids as $id) {
'*' $service = IcingaService::load(array(
)->join( 'id' => $id,
array('sset' => 'icinga_service_set_service'), 'object_type' => 'template'
'sset.service_id = s.id', ), $connection);
array()
)->where(
$db->quoteInto(
'sset.service_set_id = ?',
(int) $this->id
)
)->order('s.object_name');
// TODO: This cannot be prefetched $services[$service->object_name] = $service;
return IcingaService::loadAll($conn, $query, 'object_name'); }
return $services;
} }
public function renderToConfig(IcingaConfig $config) public function renderToConfig(IcingaConfig $config)
{ {
if ($this->isTemplate()) { if ($this->assign_filter === null && $this->isTemplate()) {
return; return;
} }
@ -85,25 +94,38 @@ class IcingaServiceSet extends IcingaObject
return $this->renderToLegacyConfig($config); return $this->renderToLegacyConfig($config);
} }
$file = $this->getConfigFileWithHeader($config);
// Loop over all services belonging to this set // Loop over all services belonging to this set
// add our assign rules and then add the service to the config // add our assign rules and then add the service to the config
// eventually clone them beforehand to not get into trouble with caches // eventually clone them beforehand to not get into trouble with caches
// figure out whether we might need a zone property // figure out whether we might need a zone property
foreach ($this->getServiceObjects() as $service) {
// TODO: make them REAL applies
if ($this->assign_filter) {
$service->object_type = 'apply';
$service->assign_filter = $this->assign_filter;
} else {
$service->object_type = $this->object_type;
if ($this->isApplyRule()) {
$service->assign_filter = $this->assign_filter;
}
}
$service->vars = $this->vars;
$service->host_id = $this->host_id;
$file->addObject($service);
}
}
protected function getConfigFileWithHeader(IcingaConfig $config)
{
$file = $config->configFile( $file = $config->configFile(
'zones.d/' . $this->getRenderingZone($config) . '/servicesets' 'zones.d/' . $this->getRenderingZone($config) . '/servicesets'
); );
$file->prepend($this->getConfigHeaderComment($config)); $file->prepend($this->getConfigHeaderComment($config));
return $file;
foreach ($this->getServiceObjects() as $service) {
$service->object_type = $this->object_type;
if ($this->isApplyRule()) {
$service->setAssignments($this->getAssignments());
}
$service->host_id = $this->host_id;
$file->addObject($service);
}
} }
protected function getConfigHeaderComment(IcingaConfig $config) protected function getConfigHeaderComment(IcingaConfig $config)
@ -142,32 +164,19 @@ class IcingaServiceSet extends IcingaObject
foreach ($this->getServiceObjects() as $service) { foreach ($this->getServiceObjects() as $service) {
$service->object_type = 'object'; $service->object_type = 'object';
$service->host_id = $this->host_id; $service->host_id = $this->host_id;
$service->vars = $this->vars;
$file->addLegacyObject($service); $file->addLegacyObject($service);
} }
} }
protected function resolve($what)
{
return array();
}
protected function getResolved($what)
{
return array();
}
protected function getInherited($what)
{
return array();
}
protected function getOrigins($what)
{
return array();
}
public function getRenderingZone(IcingaConfig $config = null) public function getRenderingZone(IcingaConfig $config = null)
{ {
if ($this->host_id === null) {
return $this->connection->getDefaultGlobalZoneName(); return $this->connection->getDefaultGlobalZoneName();
} else {
$host = $this->getRelatedObject('host', $this->host_id);
return $host->getRenderingZone($config);
}
return $zone;
} }
} }

View File

@ -26,7 +26,7 @@ abstract class ObjectController extends ActionController
{ {
parent::init(); parent::init();
$type = $this->getType(); $type = strtolower($this->getType());
if ($object = $this->loadObject()) { if ($object = $this->loadObject()) {
$this->beforeTabs(); $this->beforeTabs();
@ -61,7 +61,6 @@ abstract class ObjectController extends ActionController
'label' => $this->translate('Fields') 'label' => $this->translate('Fields')
)); ));
} }
} else { } else {
$this->beforeTabs(); $this->beforeTabs();
$this->getTabs()->add('add', array( $this->getTabs()->add('add', array(
@ -301,8 +300,8 @@ abstract class ObjectController extends ActionController
{ {
// Strip final 's' and upcase an eventual 'group' // Strip final 's' and upcase an eventual 'group'
return preg_replace( return preg_replace(
array('/group$/', '/period$/', '/argument$/', '/apiuser$/'), array('/group$/', '/period$/', '/argument$/', '/apiuser$/', '/set$/'),
array('Group', 'Period', 'Argument', 'ApiUser'), array('Group', 'Period', 'Argument', 'ApiUser', 'Set'),
$this->getRequest()->getControllerName() $this->getRequest()->getControllerName()
); );
} }

View File

@ -67,6 +67,13 @@ abstract class ObjectsController extends ActionController
)); ));
} }
if ($object->supportsSets() || $object->isGroup() /** Bullshit, need base object, wrong on users */) {
$tabs->add('sets', array(
'url' => sprintf('director/%ss/sets', $type),
'label' => $this->translate('Sets')
));
}
$tabs->add('tree', array( $tabs->add('tree', array(
'url' => sprintf('director/%ss/templatetree', $type), 'url' => sprintf('director/%ss/templatetree', $type),
'label' => $this->translate('Tree'), 'label' => $this->translate('Tree'),
@ -246,6 +253,27 @@ abstract class ObjectsController extends ActionController
$this->setViewScript('objects/tree'); $this->setViewScript('objects/tree');
} }
public function setsAction()
{
$this->view->title = $this->translate('Service sets');
$this->view->table = $this
->loadTable('IcingaServiceSet')
->setConnection($this->db());
$this->view->addLink = $this->view->qlink(
$this->translate('Add'),
'director/serviceset/add',
null,
array(
'class' => 'icon-plus',
'data-base-target' => '_next'
)
);
$this->getTabs()->activate('sets');
$this->setViewScript('objects/table');
}
protected function dummyObject() protected function dummyObject()
{ {
if ($this->dummy === null) { if ($this->dummy === null) {

View File

@ -33,6 +33,8 @@ abstract class DirectorObjectForm extends QuickForm
protected $preferredObjectType; protected $preferredObjectType;
protected $fieldLoader;
private $allowsExperimental; private $allowsExperimental;
private $api; private $api;
@ -234,40 +236,60 @@ abstract class DirectorObjectForm extends QuickForm
unset($props['vars']); unset($props['vars']);
} }
$this->setDefaults($props); $this->setDefaults($this->removeNullProperties($props));
if (! $object instanceof IcingaObject) {
return $this;
}
if ($resolve) { if ($resolve) {
$inherited = $object->getInheritedProperties(); $this->showInheritedProperties($object);
$origins = $object->getOriginsProperties(); }
} else {
$inherited = (object) array();
$origins = (object) array();
} }
foreach ($props as $k => $v) { protected function showInheritedProperties($object)
$this->setElementValue($k, $v); {
if ($k !== 'object_name' && property_exists($inherited, $k)) { $inherited = $object->getInheritedProperties();
$origins = $object->getOriginsProperties();
foreach ($inherited as $k => $v) {
if ($v !== null && $k !== 'object_name') {
$el = $this->getElement($k); $el = $this->getElement($k);
if ($el && $resolve) { if ($el) {
$this->setInheritedValue($el, $inherited->$k, $origins->$k); $this->setInheritedValue($el, $inherited->$k, $origins->$k);
} }
} }
} }
} }
protected function removeNullProperties($props)
{
$result = array();
foreach ($props as $k => $v) {
if ($v !== null && $v !== '') {
$result[$k] = $v;
}
}
return $result;
}
protected function handleCustomVars($object, & $values) protected function handleCustomVars($object, & $values)
{ {
if ($this->assertResolvedImports()) { if ($this->assertResolvedImports()) {
$loader = new IcingaObjectFieldLoader($object); $loader = $this->fieldLoader($object);
$loader->addFieldsToForm($this); $loader->addFieldsToForm($this);
if ($values) { if ($values) {
$loader->setValues($values, 'var_'); $loader->setValues($values, 'var_');
} }
} }
return $this;
}
protected function fieldLoader($object)
{
if ($this->fieldLoader === null) {
$this->fieldLoader = new IcingaObjectFieldLoader($object);
}
return $this->fieldLoader;
} }
protected function isNew() protected function isNew()
@ -907,9 +929,9 @@ abstract class DirectorObjectForm extends QuickForm
return $this; return $this;
} }
protected function addCheckCommandElements() protected function addCheckCommandElements($force = false)
{ {
if (! $this->isTemplate()) { if (! $force && ! $this->isTemplate()) {
return $this; return $this;
} }
@ -936,9 +958,9 @@ abstract class DirectorObjectForm extends QuickForm
return $this; return $this;
} }
protected function addCheckExecutionElements() protected function addCheckExecutionElements($force = false)
{ {
if (! $this->isTemplate()) { if (! $force && ! $this->isTemplate()) {
return $this; return $this;
} }

View File

@ -25,13 +25,36 @@ class IcingaObjectFieldLoader
public function addFieldsToForm(QuickForm $form) public function addFieldsToForm(QuickForm $form)
{ {
if ($this->object->supportsCustomVars()) { if ($this->fields || $this->object->supportsFields()) {
$this->attachFieldsToForm($form); $this->attachFieldsToForm($form);
} }
return $this; return $this;
} }
public function loadFieldsForMultipleObjects($objects)
{
$fields = array();
foreach ($objects as $object) {
foreach ($this->prepareObjectFields($object) as $varname => $field) {
$varname = $field->varname;
if (array_key_exists($varname, $fields)) {
if ($field->datatype !== $fields[$varname]->datatype) {
unset($fields[$varname]);
}
continue;
}
$fields[$field->varname] = $field;
}
}
$this->fields = $fields;
return $this;
}
/** /**
* Set a list of values * Set a list of values
* *

View File

@ -224,6 +224,10 @@ input[type=text], input[type=password], textarea, select {
} }
} }
select[multiple] {
height: auto;
}
select option { select option {
height: 2em; height: 2em;
padding-top: 0.3em; padding-top: 0.3em;

View File

@ -0,0 +1,8 @@
ALTER TABLE icinga_service
ADD COLUMN service_set_id INT(10) UNSIGNED DEFAULT NULL AFTER host_id;
DROP TABLE icinga_service_set_service;
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (121, NOW());

View File

@ -535,6 +535,7 @@ CREATE TABLE icinga_service (
disabled ENUM('y', 'n') NOT NULL DEFAULT 'n', disabled ENUM('y', 'n') NOT NULL DEFAULT 'n',
display_name VARCHAR(255) DEFAULT NULL, display_name VARCHAR(255) DEFAULT NULL,
host_id INT(10) UNSIGNED DEFAULT NULL, host_id INT(10) UNSIGNED DEFAULT NULL,
service_set_id INT(10) UNSIGNED DEFAULT NULL,
check_command_id INT(10) UNSIGNED DEFAULT NULL, check_command_id INT(10) UNSIGNED DEFAULT NULL,
max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL, max_check_attempts MEDIUMINT UNSIGNED DEFAULT NULL,
check_period_id INT(10) UNSIGNED DEFAULT NULL, check_period_id INT(10) UNSIGNED DEFAULT NULL,
@ -670,22 +671,6 @@ CREATE TABLE icinga_service_set (
UNIQUE KEY object_key (object_name, host_id) UNIQUE KEY object_key (object_name, host_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE icinga_service_set_service (
service_set_id INT(10) UNSIGNED NOT NULL,
service_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (service_set_id, service_id),
CONSTRAINT service_set_set
FOREIGN KEY service_set (service_set_id)
REFERENCES icinga_service_set (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT service_set_service
FOREIGN KEY service (service_id)
REFERENCES icinga_service (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE icinga_service_set_inheritance ( CREATE TABLE icinga_service_set_inheritance (
service_set_id INT(10) UNSIGNED NOT NULL, service_set_id INT(10) UNSIGNED NOT NULL,
parent_service_set_id INT(10) UNSIGNED NOT NULL, parent_service_set_id INT(10) UNSIGNED NOT NULL,
@ -1369,4 +1354,4 @@ CREATE TABLE sync_run (
INSERT INTO director_schema_migration INSERT INTO director_schema_migration
(schema_version, migration_time) (schema_version, migration_time)
VALUES (120, NOW()); VALUES (121, NOW());

View File

@ -0,0 +1,8 @@
ALTER TABLE icinga_service
ADD COLUMN service_set_id integer DEFAULT NULL;
DROP TABLE icinga_service_set_service;
INSERT INTO director_schema_migration
(schema_version, migration_time)
VALUES (121, NOW());

View File

@ -677,6 +677,7 @@ CREATE TABLE icinga_service (
disabled enum_boolean DEFAULT 'n', disabled enum_boolean DEFAULT 'n',
display_name character varying(255) DEFAULT NULL, display_name character varying(255) DEFAULT NULL,
host_id INTEGER DEFAULT NULL, host_id INTEGER DEFAULT NULL,
service_set_id integer DEFAULT NULL,
check_command_id integer DEFAULT NULL, check_command_id integer DEFAULT NULL,
max_check_attempts integer DEFAULT NULL, max_check_attempts integer DEFAULT NULL,
check_period_id integer DEFAULT NULL, check_period_id integer DEFAULT NULL,
@ -838,23 +839,6 @@ CREATE TABLE icinga_service_set (
CREATE UNIQUE INDEX service_set_name ON icinga_service_set (object_name, host_id); CREATE UNIQUE INDEX service_set_name ON icinga_service_set (object_name, host_id);
CREATE TABLE icinga_service_set_service (
service_set_id serial,
service_id serial,
PRIMARY KEY (service_set_id, service_id),
CONSTRAINT icinga_service_set_set
FOREIGN KEY (service_set_id)
REFERENCES icinga_service_set (id)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT icinga_service_set_service
FOREIGN KEY (service_id)
REFERENCES icinga_service (id)
ON DELETE RESTRICT
ON UPDATE CASCADE
);
CREATE TABLE icinga_service_set_inheritance ( CREATE TABLE icinga_service_set_inheritance (
service_set_id integer NOT NULL, service_set_id integer NOT NULL,
parent_service_set_id integer NOT NULL, parent_service_set_id integer NOT NULL,
@ -1597,4 +1581,4 @@ CREATE UNIQUE INDEX notification_inheritance ON icinga_notification_inheritance
INSERT INTO director_schema_migration INSERT INTO director_schema_migration
(schema_version, migration_time) (schema_version, migration_time)
VALUES (120, NOW()); VALUES (121, NOW());