mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 01:04:12 +02:00
Merge branch 'feature/service-sets-12891'
This commit is contained in:
commit
93a4cd7dd9
@ -160,14 +160,16 @@ class SyncPropertyForm extends DirectorObjectForm
|
||||
|
||||
if ($destination === 'import') {
|
||||
$funcTemplates = 'enum' . ucfirst($this->rule->get('object_type')) . 'Templates';
|
||||
$templates = $this->db->$funcTemplates();
|
||||
if (! empty($templates)) {
|
||||
$templates = array_combine($templates, $templates);
|
||||
}
|
||||
if (method_exists($this->db, $funcTemplates)) {
|
||||
$templates = $this->db->$funcTemplates();
|
||||
if (! empty($templates)) {
|
||||
$templates = array_combine($templates, $templates);
|
||||
}
|
||||
|
||||
$importTitle = $this->translate('Existing templates');
|
||||
$columns[$importTitle] = $templates;
|
||||
natsort($columns[$importTitle]);
|
||||
$importTitle = $this->translate('Existing templates');
|
||||
$columns[$importTitle] = $templates;
|
||||
natsort($columns[$importTitle]);
|
||||
}
|
||||
}
|
||||
|
||||
$xpTitle = $this->translate('Expert mode');
|
||||
|
@ -6,35 +6,50 @@ use Icinga\Module\Director\Web\Table\IcingaObjectTable;
|
||||
|
||||
class IcingaServiceSetTable extends IcingaObjectTable
|
||||
{
|
||||
protected $searchColumns = array(
|
||||
'name',
|
||||
);
|
||||
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'id' => 'sset.id',
|
||||
'name' => 'sset.object_name',
|
||||
'object_type' => 'sset.object_type',
|
||||
'assign_filter' => 'sset.assign_filter',
|
||||
'description' => 'sset.description',
|
||||
'host_name' => 'h.object_name',
|
||||
'count_hosts' => 'count(ssetobj.id)',
|
||||
'count_services' => 'count(s.id)',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getRowClasses($row)
|
||||
{
|
||||
$class = parent::getRowClasses($row);
|
||||
|
||||
if ($row->object_type === 'template' && $row->assign_filter !== null) {
|
||||
$class = 'icinga-apply';
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
public function getTitles()
|
||||
{
|
||||
$view = $this->view();
|
||||
return array(
|
||||
'name' => $view->translate('Service set'),
|
||||
'name' => $view->translate('Service set'),
|
||||
'count_services' => $view->translate('# Services'),
|
||||
'count_hosts' => $view->translate('# Hosts'),
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
@ -46,10 +61,33 @@ class IcingaServiceSetTable extends IcingaObjectTable
|
||||
array('sset' => 'icinga_service_set'),
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('h' => 'icinga_host'),
|
||||
'h.id = sset.host_id',
|
||||
array('ssih' => 'icinga_service_set_inheritance'),
|
||||
'ssih.parent_service_set_id = sset.id',
|
||||
array()
|
||||
)->where('sset.object_type = ?', 'template')->order('sset.object_name');
|
||||
)->joinLeft(
|
||||
array('ssetobj' => 'icinga_service_set'),
|
||||
'ssetobj.id = ssih.service_set_id',
|
||||
array()
|
||||
)->joinLeft(
|
||||
array('s' => 'icinga_service'),
|
||||
's.service_set_id = sset.id',
|
||||
array()
|
||||
)->group('sset.id')
|
||||
->where('sset.object_type = ?', 'template')->order('sset.object_name');
|
||||
}
|
||||
|
||||
public function count()
|
||||
{
|
||||
$db = $this->db();
|
||||
$sub = clone($this->getBaseQuery());
|
||||
$sub->columns($this->getColumns());
|
||||
$this->applyFiltersToQuery($sub);
|
||||
$query = $db->select()->from(
|
||||
array('sub' => $sub),
|
||||
'COUNT(*)'
|
||||
);
|
||||
|
||||
return $db->fetchOne($query);
|
||||
}
|
||||
|
||||
public function getBaseQuery()
|
||||
|
@ -122,7 +122,8 @@ class IcingaServiceTable extends QuickTable
|
||||
'i.service_id = s.id',
|
||||
array()
|
||||
)->where('i.parent_service_id = ?', $id)
|
||||
->where('s.object_type = ?', 'apply');
|
||||
->where('s.object_type = ?', 'apply')
|
||||
->where('s.service_set_id IS NULL');
|
||||
|
||||
return $db->fetchAll($query);
|
||||
}
|
||||
|
@ -349,7 +349,10 @@ class Sync
|
||||
) as $object) {
|
||||
|
||||
if ($object instanceof IcingaService) {
|
||||
if (! $object->host_id) {
|
||||
if (strstr($destinationKeyPattern, '${host}') && $object->host_id === null) {
|
||||
continue;
|
||||
}
|
||||
elseif (strstr($destinationKeyPattern, '${service_set}') && $object->service_set_id === null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||
|
||||
|
||||
@ -43,6 +44,26 @@ class IcingaServiceSet extends IcingaObject
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function setKey($key)
|
||||
{
|
||||
if (is_int($key)) {
|
||||
$this->id = $key;
|
||||
} elseif (is_string($key)) {
|
||||
$keyComponents = preg_split('~!~', $key);
|
||||
if (count($keyComponents) === 1) {
|
||||
$this->set('object_name', $keyComponents[0]);
|
||||
$this->set('object_type', 'template');
|
||||
}
|
||||
else {
|
||||
throw new IcingaException('Can not parse key: %s', $key);
|
||||
}
|
||||
} else {
|
||||
return parent::setKey($key);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IcingaService[]
|
||||
*/
|
||||
|
@ -263,6 +263,42 @@ class SyncRule extends DbObject
|
||||
$hasHost = false;
|
||||
$hasObjectName = false;
|
||||
|
||||
foreach ($this->getSyncProperties() as $key => $property) {
|
||||
if ($property->destination_field === 'host') {
|
||||
$hasHost = $property->source_expression;
|
||||
}
|
||||
if ($property->destination_field === 'service_set') {
|
||||
$hasServiceSet = $property->source_expression;
|
||||
}
|
||||
if ($property->destination_field === 'object_name') {
|
||||
$hasObjectName = $property->source_expression;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasHost !== false && $hasObjectName !== false) {
|
||||
$this->hasCombinedKey = true;
|
||||
$this->sourceKeyPattern = sprintf(
|
||||
'%s!%s',
|
||||
$hasHost,
|
||||
$hasObjectName
|
||||
);
|
||||
|
||||
$this->destinationKeyPattern = '${host}!${object_name}';
|
||||
}
|
||||
elseif ($hasServiceSet !== false && $hasObjectName !== false) {
|
||||
$this->hasCombinedKey = true;
|
||||
$this->sourceKeyPattern = sprintf(
|
||||
'%s!%s',
|
||||
$hasServiceSet,
|
||||
$hasObjectName
|
||||
);
|
||||
|
||||
$this->destinationKeyPattern = '${service_set}!${object_name}';
|
||||
}
|
||||
} elseif ($this->get('object_type') === 'serviceSet') {
|
||||
$hasHost = false;
|
||||
$hasObjectName = false;
|
||||
|
||||
foreach ($this->getSyncProperties() as $key => $property) {
|
||||
if ($property->destination_field === 'host') {
|
||||
$hasHost = $property->source_expression;
|
||||
|
@ -8,6 +8,8 @@ use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
|
||||
use Icinga\Module\Director\Web\Table\QuickTable;
|
||||
use Icinga\Web\Widget\FilterEditor;
|
||||
|
||||
abstract class ObjectsController extends ActionController
|
||||
{
|
||||
@ -51,6 +53,12 @@ abstract class ObjectsController extends ActionController
|
||||
$object = $this->dummyObject();
|
||||
if ($object->isGroup()) {
|
||||
$type = substr($type, 0, -5);
|
||||
/** @var IcingaObject $baseType */
|
||||
$baseType = $this->getObjectClassname($type);
|
||||
$baseObject = $baseType::create(array());
|
||||
}
|
||||
else {
|
||||
$baseObject = $object;
|
||||
}
|
||||
|
||||
$tabs->add('objects', array(
|
||||
@ -66,14 +74,14 @@ abstract class ObjectsController extends ActionController
|
||||
));
|
||||
}
|
||||
|
||||
if ($object->supportsGroups() || $object->isGroup()) {
|
||||
if ($baseObject->supportsGroups()) {
|
||||
$tabs->add('objectgroups', array(
|
||||
'url' => sprintf('director/%sgroups', $type),
|
||||
'label' => $this->translate('Groups')
|
||||
));
|
||||
}
|
||||
|
||||
if ($object->supportsSets() || $object->isGroup() /** Bullshit, need base object, wrong on users */) {
|
||||
if ($baseObject->supportsSets()) {
|
||||
$tabs->add('sets', array(
|
||||
'url' => sprintf('director/%ss/sets', $type),
|
||||
'label' => $this->translate('Sets')
|
||||
@ -202,14 +210,21 @@ abstract class ObjectsController extends ActionController
|
||||
public function setsAction()
|
||||
{
|
||||
$this->assertPermission('director/admin');
|
||||
$this->view->title = $this->translate('Service sets');
|
||||
$this->view->table = $this
|
||||
->loadTable('IcingaServiceSet')
|
||||
->setConnection($this->db());
|
||||
|
||||
$dummy = $this->dummyObject();
|
||||
$type = $this->getType();
|
||||
$Type = ucfirst($type);
|
||||
|
||||
if ($dummy->supportsSets() !== true) {
|
||||
throw new NotFoundError('Sets are not available for %s', $type);
|
||||
}
|
||||
|
||||
$this->view->title = $this->translate('Icinga ' . $Type . ' Sets');
|
||||
$table = $this->loadTable('Icinga' . $Type . 'Set')->setConnection($this->db());
|
||||
|
||||
$this->view->addLink = $this->view->qlink(
|
||||
$this->translate('Add'),
|
||||
'director/serviceset/add',
|
||||
'director/' . $type . 'set/add',
|
||||
null,
|
||||
array(
|
||||
'class' => 'icon-plus',
|
||||
@ -217,6 +232,7 @@ abstract class ObjectsController extends ActionController
|
||||
)
|
||||
);
|
||||
|
||||
$this->provideFilterEditorForTable($table);
|
||||
$this->getTabs()->activate('sets');
|
||||
$this->setViewScript('objects/table');
|
||||
}
|
||||
@ -227,6 +243,7 @@ abstract class ObjectsController extends ActionController
|
||||
protected function dummyObject()
|
||||
{
|
||||
if ($this->dummy === null) {
|
||||
/** @var IcingaObject $class */
|
||||
$class = $this->getObjectClassname();
|
||||
$this->dummy = $class::create(array());
|
||||
if ($this->dummy->hasProperty('object_type')) {
|
||||
@ -257,9 +274,12 @@ abstract class ObjectsController extends ActionController
|
||||
);
|
||||
}
|
||||
|
||||
protected function getObjectClassname()
|
||||
protected function getObjectClassname($type = null)
|
||||
{
|
||||
if ($type === null) {
|
||||
$type = $this->getType();
|
||||
}
|
||||
return 'Icinga\\Module\\Director\\Objects\\Icinga'
|
||||
. ucfirst($this->getType());
|
||||
. ucfirst($type);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user