From 792ff03a6d69f2f76a80de64110a2b9a1b760a93 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 5 Oct 2021 18:19:01 +0200 Subject: [PATCH] Objects: add uuid column --- library/Director/Objects/IcingaApiUser.php | 7 +++++-- library/Director/Objects/IcingaCommand.php | 3 +++ library/Director/Objects/IcingaDependency.php | 3 +++ library/Director/Objects/IcingaEndpoint.php | 3 +++ library/Director/Objects/IcingaHost.php | 3 +++ library/Director/Objects/IcingaNotification.php | 3 +++ library/Director/Objects/IcingaObject.php | 14 ++++++++++++++ library/Director/Objects/IcingaObjectGroup.php | 3 +++ .../Director/Objects/IcingaScheduledDowntime.php | 3 +++ library/Director/Objects/IcingaService.php | 3 +++ library/Director/Objects/IcingaTimePeriod.php | 7 +++++-- library/Director/Objects/IcingaUser.php | 3 +++ library/Director/Objects/IcingaUserGroup.php | 3 +++ library/Director/Objects/IcingaZone.php | 3 +++ 14 files changed, 57 insertions(+), 4 deletions(-) diff --git a/library/Director/Objects/IcingaApiUser.php b/library/Director/Objects/IcingaApiUser.php index 84407156..bb4f9f8a 100644 --- a/library/Director/Objects/IcingaApiUser.php +++ b/library/Director/Objects/IcingaApiUser.php @@ -8,18 +8,21 @@ class IcingaApiUser extends IcingaObject { protected $table = 'icinga_apiuser'; + protected $uuidColumn = 'uuid'; + // TODO: Enable (and add table) if required protected $supportsImports = false; - protected $defaultProperties = array( + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', 'password' => null, 'client_dn' => null, 'permissions' => null, - ); + ]; protected function renderPassword() { diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index e77b0e8b..2567e3e7 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -18,8 +18,11 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI protected $type = 'CheckCommand'; + protected $uuidColumn = 'uuid'; + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', diff --git a/library/Director/Objects/IcingaDependency.php b/library/Director/Objects/IcingaDependency.php index 5b55bbf2..77e5e31a 100644 --- a/library/Director/Objects/IcingaDependency.php +++ b/library/Director/Objects/IcingaDependency.php @@ -16,6 +16,7 @@ class IcingaDependency extends IcingaObject implements ExportInterface protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', @@ -34,6 +35,8 @@ class IcingaDependency extends IcingaObject implements ExportInterface 'parent_service_by_name' => null, ]; + protected $uuidColumn = 'uuid'; + protected $supportsCustomVars = false; protected $supportsImports = true; diff --git a/library/Director/Objects/IcingaEndpoint.php b/library/Director/Objects/IcingaEndpoint.php index bb0e080b..5cb17953 100644 --- a/library/Director/Objects/IcingaEndpoint.php +++ b/library/Director/Objects/IcingaEndpoint.php @@ -15,8 +15,11 @@ class IcingaEndpoint extends IcingaObject protected $supportsImports = true; + protected $uuidColumn = 'uuid'; + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'zone_id' => null, 'object_name' => null, 'object_type' => null, diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php index d9a17945..d42ab6a1 100644 --- a/library/Director/Objects/IcingaHost.php +++ b/library/Director/Objects/IcingaHost.php @@ -22,6 +22,7 @@ class IcingaHost extends IcingaObject implements ExportInterface protected $defaultProperties = array( 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', @@ -101,6 +102,8 @@ class IcingaHost extends IcingaObject implements ExportInterface /** @var HostGroupMembershipResolver */ protected $hostgroupMembershipResolver; + protected $uuidColumn = 'uuid'; + public static function enumProperties( DbConnection $connection = null, $prefix = '', diff --git a/library/Director/Objects/IcingaNotification.php b/library/Director/Objects/IcingaNotification.php index d64fde7d..ec88b57e 100644 --- a/library/Director/Objects/IcingaNotification.php +++ b/library/Director/Objects/IcingaNotification.php @@ -14,6 +14,7 @@ class IcingaNotification extends IcingaObject implements ExportInterface protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', @@ -31,6 +32,8 @@ class IcingaNotification extends IcingaObject implements ExportInterface 'assign_filter' => null, ]; + protected $uuidColumn = 'uuid'; + protected $supportsCustomVars = true; protected $supportsFields = true; diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 02e56ca1..b62ac9a7 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -2159,6 +2159,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return ''; } + public function renderUuid() + { + return ''; + } + /** * @return string */ @@ -2785,6 +2790,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer foreach ($p as $k => $v) { // Do not ship ids for IcingaObjects: + if ($k === $this->getUuidColumn()) { + continue; + } if ($resolveIds) { if ($k === 'id' && $keepId === false && $this->hasProperty('object_name')) { continue; @@ -3003,6 +3011,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer public function getUrlParams() { $params = []; + if ($column = $this->getUuidColumn()) { + return [$column => $this->getUniqueId()->toString()]; + } if ($this->isApplyRule() && ! $this instanceof IcingaScheduledDowntime) { $params['id'] = $this->get('id'); @@ -3056,6 +3067,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer if ($k === 'id' && $this->hasProperty('object_name')) { continue; } + if ($k === $this->getUuidColumn()) { + continue; + } if ('_id' === substr($k, -3)) { $relKey = substr($k, 0, -3); diff --git a/library/Director/Objects/IcingaObjectGroup.php b/library/Director/Objects/IcingaObjectGroup.php index af18c12b..bfa71246 100644 --- a/library/Director/Objects/IcingaObjectGroup.php +++ b/library/Director/Objects/IcingaObjectGroup.php @@ -12,8 +12,11 @@ abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface protected $supportedInLegacy = true; + protected $uuidColumn = 'uuid'; + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', diff --git a/library/Director/Objects/IcingaScheduledDowntime.php b/library/Director/Objects/IcingaScheduledDowntime.php index 45cf1e3f..7fc3f78a 100644 --- a/library/Director/Objects/IcingaScheduledDowntime.php +++ b/library/Director/Objects/IcingaScheduledDowntime.php @@ -11,6 +11,7 @@ class IcingaScheduledDowntime extends IcingaObject protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'zone_id' => null, 'object_name' => null, 'object_type' => null, @@ -24,6 +25,8 @@ class IcingaScheduledDowntime extends IcingaObject 'with_services' => null, ]; + protected $uuidColumn = 'uuid'; + protected $supportsImports = true; protected $supportsRanges = true; diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index e2ad831e..18ac5b0f 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -23,8 +23,11 @@ class IcingaService extends IcingaObject implements ExportInterface protected $table = 'icinga_service'; + protected $uuidColumn = 'uuid'; + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', diff --git a/library/Director/Objects/IcingaTimePeriod.php b/library/Director/Objects/IcingaTimePeriod.php index 1a9e6911..a3c65c41 100644 --- a/library/Director/Objects/IcingaTimePeriod.php +++ b/library/Director/Objects/IcingaTimePeriod.php @@ -10,8 +10,11 @@ class IcingaTimePeriod extends IcingaObject implements ExportInterface { protected $table = 'icinga_timeperiod'; - protected $defaultProperties = array( + protected $uuidColumn = 'uuid'; + + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'zone_id' => null, 'object_name' => null, 'object_type' => null, @@ -19,7 +22,7 @@ class IcingaTimePeriod extends IcingaObject implements ExportInterface 'prefer_includes' => null, 'display_name' => null, 'update_method' => null, - ); + ]; protected $booleans = [ 'prefer_includes' => 'prefer_includes', diff --git a/library/Director/Objects/IcingaUser.php b/library/Director/Objects/IcingaUser.php index 51baae46..394e8498 100644 --- a/library/Director/Objects/IcingaUser.php +++ b/library/Director/Objects/IcingaUser.php @@ -12,6 +12,7 @@ class IcingaUser extends IcingaObject implements ExportInterface protected $defaultProperties = array( 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', @@ -23,6 +24,8 @@ class IcingaUser extends IcingaObject implements ExportInterface 'zone_id' => null, ); + protected $uuidColumn = 'uuid'; + protected $supportsGroups = true; protected $supportsCustomVars = true; diff --git a/library/Director/Objects/IcingaUserGroup.php b/library/Director/Objects/IcingaUserGroup.php index 09d21397..656235a2 100644 --- a/library/Director/Objects/IcingaUserGroup.php +++ b/library/Director/Objects/IcingaUserGroup.php @@ -6,8 +6,11 @@ class IcingaUserGroup extends IcingaObjectGroup { protected $table = 'icinga_usergroup'; + protected $uuidColumn = 'uuid'; + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n', diff --git a/library/Director/Objects/IcingaZone.php b/library/Director/Objects/IcingaZone.php index 54929eb8..8d77e478 100644 --- a/library/Director/Objects/IcingaZone.php +++ b/library/Director/Objects/IcingaZone.php @@ -10,8 +10,11 @@ class IcingaZone extends IcingaObject { protected $table = 'icinga_zone'; + protected $uuidColumn = 'uuid'; + protected $defaultProperties = [ 'id' => null, + 'uuid' => null, 'object_name' => null, 'object_type' => null, 'disabled' => 'n',