Skip to content

Commit 2ddc75b

Browse files
committed
WIP: ipl form for custom properties
1 parent e1188fa commit 2ddc75b

8 files changed

Lines changed: 477 additions & 76 deletions

File tree

application/controllers/HostController.php

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use gipfl\Web\Widget\Hint;
66
use Icinga\Module\Director\Auth\Permission;
7+
use Icinga\Module\Director\CustomVariable\CustomVariables;
8+
use Icinga\Module\Director\Exception\NestingError;
9+
use Icinga\Module\Director\Forms\CustomPropertiesForm;
710
use Icinga\Module\Director\Integration\Icingadb\IcingadbBackend;
811
use Icinga\Module\Director\Integration\MonitoringModule\Monitoring;
912
use Icinga\Module\Director\Web\Table\ObjectsTableService;
@@ -25,7 +28,6 @@
2528
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
2629
use Icinga\Module\Director\Web\Controller\ObjectController;
2730
use Icinga\Module\Director\Web\SelfService;
28-
use Icinga\Module\Director\Web\Table\IcingaHostAppliedForServiceTable;
2931
use Icinga\Module\Director\Web\Table\IcingaHostAppliedServicesTable;
3032
use Icinga\Module\Director\Web\Table\IcingaServiceSetServiceTable;
3133

@@ -89,6 +91,36 @@ public function editAction()
8991
$this->addOptionalMonitoringLink();
9092
}
9193

94+
public function variablesAction()
95+
{
96+
$this->assertPermission('director/admin');
97+
$object = $this->requireObject();
98+
$type = $this->getType();
99+
100+
$this->addTitle(
101+
$this->translate('Custom Variables: %s'),
102+
$object->getObjectName()
103+
);
104+
105+
$vars = json_decode(json_encode($this->object->getVars()), true);
106+
107+
$form = (new CustomPropertiesForm($this->db(), $object))
108+
->populate($vars)
109+
->on(CustomPropertiesForm::ON_SUCCESS, function ($form) {
110+
$this->getResponse()->setHeader('X-Icinga-Container', 'col2');
111+
$this->redirectNow(Url::fromRequest());
112+
})
113+
->handleRequest($this->getServerRequest());
114+
115+
try {
116+
$this->content()->add($form);
117+
} catch (NestingError $e) {
118+
$this->content()->add(Hint::error($e->getMessage()));
119+
}
120+
121+
$this->tabs()->activate('variables');
122+
}
123+
92124
public function serviceAction()
93125
{
94126
$host = $this->getHostObject();
@@ -99,7 +131,7 @@ public function serviceAction()
99131
->setBranch($this->getBranch())
100132
->setHost($host)
101133
->setDb($this->db())
102-
->handleRequest()
134+
->handleRequest(),
103135
);
104136
}
105137

@@ -114,7 +146,7 @@ public function servicesetAction()
114146
->setBranch($this->getBranch())
115147
->setHost($host)
116148
->setDb($this->db())
117-
->handleRequest()
149+
->handleRequest(),
118150
);
119151
}
120152

@@ -128,12 +160,12 @@ protected function addServicesHeader()
128160
$this->translate('Add service'),
129161
'director/host/service',
130162
['name' => $hostname],
131-
['class' => 'icon-plus']
163+
['class' => 'icon-plus'],
132164
))->add(Link::create(
133165
$this->translate('Add service set'),
134166
'director/host/serviceset',
135167
['name' => $hostname],
136-
['class' => 'icon-plus']
168+
['class' => 'icon-plus'],
137169
));
138170
}
139171

@@ -159,7 +191,7 @@ public function findserviceAction()
159191
} elseif ($auth->hasPermission($this->getServicesReadOnlyPermission())) {
160192
$redirectUrl = Url::fromPath('director/host/servicesro', [
161193
'name' => $hostName,
162-
'service' => $serviceName
194+
'service' => $serviceName,
163195
]);
164196
} else {
165197
$redirectUrl = Url::fromPath('director/host/invalidservice', [
@@ -179,7 +211,7 @@ public function invalidserviceAction()
179211
if (! $this->showInfoForNonDirectorService()) {
180212
$this->content()->add(Hint::error(sprintf(
181213
$this->translate('No such service: %s'),
182-
$this->params->get('service')
214+
$this->params->get('service'),
183215
)));
184216
}
185217

@@ -199,7 +231,7 @@ protected function showInfoForNonDirectorService()
199231
'The configuration for this object has not been rendered by'
200232
. ' Icinga Director. You can find it on line %s in %s.',
201233
Html::tag('strong', null, $source->first_line),
202-
Html::tag('strong', null, $source->path)
234+
Html::tag('strong', null, $source->path),
203235
)));
204236
}
205237
}
@@ -245,8 +277,8 @@ public function servicesAction()
245277
$content->add(
246278
$table->setTitle(sprintf(
247279
$this->translate('Inherited from %s'),
248-
$parent->getObjectName()
249-
))
280+
$parent->getObjectName(),
281+
)),
250282
);
251283
}
252284
}
@@ -268,7 +300,7 @@ public function servicesAction()
268300
->setBranch($branch)
269301
->setAffectedHost($host)
270302
->setTitle($title)
271-
->removeQueryLimit()
303+
->removeQueryLimit(),
272304
);
273305
}
274306

@@ -326,8 +358,8 @@ public function servicesroAction()
326358
$content->add(
327359
$table->setTitle(sprintf(
328360
'Inherited from %s',
329-
$parent->getObjectName()
330-
))
361+
$parent->getObjectName(),
362+
)),
331363
);
332364
}
333365
}
@@ -348,7 +380,7 @@ public function servicesroAction()
348380
->setAffectedHost($host)
349381
->setReadonly()
350382
->highlightService($service)
351-
->setTitle($title)
383+
->setTitle($title),
352384
);
353385
}
354386

@@ -379,15 +411,15 @@ protected function addHostServiceSetTables(IcingaHost $host, IcingaHost $affecte
379411
$query = $db->getDbAdapter()->select()
380412
->from(
381413
array('ss' => 'icinga_service_set'),
382-
'ss.*'
414+
'ss.*',
383415
)->join(
384416
array('hsi' => 'icinga_service_set_inheritance'),
385417
'hsi.parent_service_set_id = ss.id',
386-
array()
418+
array(),
387419
)->join(
388420
array('hs' => 'icinga_service_set'),
389421
'hs.id = hsi.service_set_id',
390-
array()
422+
array(),
391423
)->where('hs.host_id = ?', $host->get('id'));
392424

393425
$sets = IcingaServiceSet::loadAll($db, $query, 'object_name');
@@ -428,7 +460,7 @@ public function appliedserviceAction()
428460

429461
$this->addTitle(
430462
$this->translate('Applied service: %s'),
431-
$serviceName
463+
$serviceName,
432464
);
433465

434466
$this->content()->add(
@@ -438,7 +470,7 @@ public function appliedserviceAction()
438470
->setHost($host)
439471
->setApplyGenerated($parent)
440472
->setObject($service)
441-
->handleRequest()
473+
->handleRequest(),
442474
);
443475

444476
$this->commonForServices();
@@ -456,7 +488,7 @@ public function inheritedserviceAction()
456488

457489
$parent = IcingaService::load([
458490
'object_name' => $serviceName,
459-
'host_id' => $from->get('id')
491+
'host_id' => $from->get('id'),
460492
], $this->db());
461493

462494
// TODO: we want to eventually show the host template name, doesn't work
@@ -493,21 +525,21 @@ public function removesetAction()
493525
$db = $this->db()->getDbAdapter();
494526
$query = $db->select()->from(
495527
array('ss' => 'icinga_service_set'),
496-
array('id' => 'ss.id')
528+
array('id' => 'ss.id'),
497529
)->join(
498530
array('si' => 'icinga_service_set_inheritance'),
499531
'si.service_set_id = ss.id',
500-
array()
532+
array(),
501533
)->where(
502534
'si.parent_service_set_id = ?',
503-
$this->params->get('setId')
535+
$this->params->get('setId'),
504536
)->where('ss.host_id = ?', $this->object->get('id'));
505537

506538
IcingaServiceSet::loadWithAutoIncId($db->fetchOne($query), $this->db())->delete();
507539
$this->redirectNow(
508540
Url::fromPath('director/host/services', array(
509-
'name' => $this->object->getObjectName()
510-
))
541+
'name' => $this->object->getObjectName(),
542+
)),
511543
);
512544
}
513545

@@ -521,7 +553,7 @@ public function servicesetserviceAction()
521553
$serviceName = $this->params->get('service');
522554
$setParams = [
523555
'object_name' => $this->params->get('set'),
524-
'host_id' => $host->get('id')
556+
'host_id' => $host->get('id'),
525557
];
526558
$setTemplate = IcingaServiceSet::load($this->params->get('set'), $db);
527559
if (IcingaServiceSet::exists($setParams, $db)) {
@@ -532,7 +564,7 @@ public function servicesetserviceAction()
532564

533565
$service = IcingaService::load([
534566
'object_name' => $serviceName,
535-
'service_set_id' => $setTemplate->get('id')
567+
'service_set_id' => $setTemplate->get('id'),
536568
], $this->db());
537569
$service = IcingaService::create([
538570
'id' => $service->get('id'),
@@ -548,7 +580,7 @@ public function servicesetserviceAction()
548580
$this->translate('%s on %s (from set: %s)'),
549581
$serviceName,
550582
$host->getObjectName(),
551-
$set->getObjectName()
583+
$set->getObjectName(),
552584
);
553585

554586
$form = IcingaServiceForm::load()
@@ -570,7 +602,7 @@ protected function commonForServices()
570602
$this->translate('back'),
571603
'director/host/services',
572604
['name' => $host->getObjectName()],
573-
['class' => 'icon-left-big']
605+
['class' => 'icon-left-big'],
574606
));
575607
$this->tabs()->activate('services');
576608
}
@@ -605,8 +637,8 @@ protected function addOptionalMonitoringLink()
605637
$this->translate('Show'),
606638
$backend->getHostUrl($host->getObjectName()),
607639
null,
608-
['class' => 'icon-globe critical', 'data-base-target' => '_next']
609-
)
640+
['class' => 'icon-globe critical', 'data-base-target' => '_next'],
641+
),
610642
);
611643

612644
// Intentionally placed here, show it only for deployed Hosts
@@ -629,12 +661,12 @@ protected function addOptionalInspectLink()
629661
[
630662
'type' => 'host',
631663
'plural' => 'hosts',
632-
'name' => $this->object->getObjectName()
664+
'name' => $this->object->getObjectName(),
633665
],
634666
[
635667
'class' => 'icon-zoom-in',
636-
'data-base-target' => '_next'
637-
]
668+
'data-base-target' => '_next',
669+
],
638670
));
639671
}
640672

application/controllers/PropertyController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function indexAction()
4343

4444
$property = $db->fetchRow($query);
4545

46-
$hasFields = ($property->value_type === 'array' && $property->instantiable === 'y')
46+
$hasFields = ($property->value_type === 'array' && $property->instantiable !== 'y')
4747
|| $property->value_type === 'dict';
4848

4949
if ($hasFields) {

0 commit comments

Comments
 (0)