mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 15:54:03 +02:00
parent
85ed54f932
commit
8046510b1f
39
application/controllers/ServiceapplyrulesController.php
Normal file
39
application/controllers/ServiceapplyrulesController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Module\Director\Objects\IcingaService;
|
||||
use Icinga\Module\Director\RestApi\IcingaObjectsHandler;
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Module\Director\Web\Table\ApplyRulesTable;
|
||||
|
||||
class ServiceapplyrulesController extends ActionController
|
||||
{
|
||||
protected $isApified = true;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
if (! $request->isApiRequest()) {
|
||||
throw new NotFoundError('Not found');
|
||||
}
|
||||
|
||||
$table = ApplyRulesTable::create('service', $this->db());
|
||||
/*
|
||||
$query = $this->db()->getDbAdapter()
|
||||
->select()
|
||||
->from('icinga_service')
|
||||
->where('object_type = ?', 'apply');
|
||||
$rules = IcingaService::loadAll($this->db(), $query);
|
||||
*/
|
||||
|
||||
$handler = (new IcingaObjectsHandler(
|
||||
$request,
|
||||
$this->getResponse(),
|
||||
$this->db()
|
||||
))->setTable($table);
|
||||
|
||||
$handler->dispatch();
|
||||
}
|
||||
}
|
@ -487,6 +487,15 @@ Content-Type: application/json
|
||||
}
|
||||
```
|
||||
|
||||
### Service Apply Rules
|
||||
|
||||
Please note that Service Apply Rule names are not unique in Icinga 2. They are
|
||||
not real objects, they are creating other objects in a loop. This makes it
|
||||
impossible to distinct them by name. Therefore, a dedicated REST API endpoint
|
||||
`director/serviceapplyrules` ships all Service Apply Rules combined with their
|
||||
internal ID. This ID can then be used to modify or delete a Rule via
|
||||
`director/service`.
|
||||
|
||||
### Agent Tickets
|
||||
|
||||
The Director is very helpful when it goes to manage your Icinga Agents. In
|
||||
|
@ -25,6 +25,7 @@ before switching to a new version.
|
||||
* FIX: Services from a Set assigned to a single Host can be blacklisted (#1616)
|
||||
* FEATURE: Add TimePeriod support to Configuration Baskets (#1735)
|
||||
* FEATURE: RO users could want to see where a configured service originated (#1785)
|
||||
* FEATURE: introduce director/serviceapplyrules REST API endpoint (#1755)
|
||||
|
||||
### REST API
|
||||
* FIX: Self Service API now ships optional Service User parameter (#1297)
|
||||
|
@ -2773,6 +2773,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
* @param bool $skipDefaults
|
||||
* @param array|null $chosenProperties
|
||||
* @param bool $resolveIds
|
||||
* @param bool $keepId
|
||||
* @return object
|
||||
* @throws NotFoundError
|
||||
*/
|
||||
@ -2780,7 +2781,8 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
$resolved = false,
|
||||
$skipDefaults = false,
|
||||
array $chosenProperties = null,
|
||||
$resolveIds = true
|
||||
$resolveIds = true,
|
||||
$keepId = false
|
||||
) {
|
||||
$props = array();
|
||||
|
||||
@ -2799,7 +2801,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
foreach ($p as $k => $v) {
|
||||
// Do not ship ids for IcingaObjects:
|
||||
if ($resolveIds) {
|
||||
if ($k === 'id' && $this->hasProperty('object_name')) {
|
||||
if ($k === 'id' && $keepId === false && $this->hasProperty('object_name')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ use Icinga\Application\Benchmark;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Module\Director\Db\Cache\PrefetchCache;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Web\Table\ApplyRulesTable;
|
||||
use Icinga\Module\Director\Web\Table\ObjectsTable;
|
||||
use Zend_Db_Select as ZfSelect;
|
||||
|
||||
@ -25,7 +26,11 @@ class IcingaObjectsHandler extends RequestHandler
|
||||
}
|
||||
}
|
||||
|
||||
public function setTable(ObjectsTable $table)
|
||||
/**
|
||||
* @param ObjectsTable|ApplyRulesTable $table
|
||||
* @return $this
|
||||
*/
|
||||
public function setTable($table)
|
||||
{
|
||||
$this->table = $table;
|
||||
return $this;
|
||||
@ -63,12 +68,13 @@ class IcingaObjectsHandler extends RequestHandler
|
||||
->columns('*')
|
||||
->reset(ZfSelect::LIMIT_COUNT)
|
||||
->reset(ZfSelect::LIMIT_OFFSET);
|
||||
|
||||
$type = $table->getType();
|
||||
$serviceApply = $type === 'service' && $table instanceof ApplyRulesTable;
|
||||
echo '{ "objects": [ ';
|
||||
$cnt = 0;
|
||||
$objects = [];
|
||||
|
||||
$dummy = IcingaObject::createByType($table->getType(), [], $connection);
|
||||
$dummy = IcingaObject::createByType($type, [], $connection);
|
||||
$dummy->prefetchAllRelatedTypes();
|
||||
|
||||
Benchmark::measure('Pre-fetching related objects');
|
||||
@ -100,7 +106,9 @@ class IcingaObjectsHandler extends RequestHandler
|
||||
$objects[] = json_encode($object->toPlainObject(
|
||||
$resolved,
|
||||
$withNull,
|
||||
$properties
|
||||
$properties,
|
||||
true,
|
||||
$serviceApply
|
||||
), JSON_PRETTY_PRINT);
|
||||
if ($first) {
|
||||
Benchmark::measure('Got first row');
|
||||
|
@ -38,6 +38,11 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return ['Name', 'assign where'/*, 'Actions'*/];
|
||||
|
Loading…
x
Reference in New Issue
Block a user