diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index c1b0cbac..42dd6bb8 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -234,6 +234,19 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface return $object; } + public function beforeDelete() + { + // check if this is a template, or directly assigned to a host + if ($this->get('host_id') === null) { + // find all host sets and delete them + foreach ($this->fetchHostSets() as $set) { + $set->delete(); + } + } + + parent::beforeDelete(); + } + /** * @throws \Icinga\Exception\NotFoundError */