diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index 4251a260..214de131 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; +use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\IcingaConfig\IcingaConfig; @@ -249,4 +250,17 @@ class IcingaServiceSet extends IcingaObject return $host->getRenderingZone($config); } } + + protected function beforeStore() + { + parent::beforeStore(); + + $name = $this->getObjectName(); + + // checking if template object_name is unique + // TODO: Move to IcingaObject + if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) { + throw new DuplicateKeyException('%s template "%s" already existing in database!', $this->getType(), $name); + } + } }