From 30ce3d8d4fe6d78e9ece80f0a4cf6e2a6c764673 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 15 Dec 2015 17:14:36 +0100 Subject: [PATCH] IcingaConfigFile: add object counter support --- .../IcingaConfig/IcingaConfigFile.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/library/Director/IcingaConfig/IcingaConfigFile.php b/library/Director/IcingaConfig/IcingaConfigFile.php index 0912e7dd..6e98f0a0 100644 --- a/library/Director/IcingaConfig/IcingaConfigFile.php +++ b/library/Director/IcingaConfig/IcingaConfigFile.php @@ -15,6 +15,10 @@ class IcingaConfigFile protected $checksum; + protected $cntObject = 0; + + protected $cntTemplate = 0; + public function prepend($content) { $this->content = $content . $this->content; @@ -34,6 +38,28 @@ class IcingaConfigFile return $this; } + public function getObjectCount() + { + return $this->cntObject; + } + + public function getTemplateCount() + { + return $this->cntTemplate; + } + + public function setObjectCount($cnt) + { + $this->cntObject = $cnt; + return $this; + } + + public function setTemplateCount($cnt) + { + $this->cntTemplate = $cnt; + return $this; + } + public function getHexChecksum() { return Util::binary2hex($this->getChecksum()); @@ -61,6 +87,20 @@ class IcingaConfigFile { $this->content .= $object->toConfigString(); $this->checksum = null; + + if ($object->hasProperty('object_type')) { + $type = $object->object_type; + + switch ($type) { + case 'object': + $this->cntObject++; + break; + case 'template': + $this->cntTemplate++; + break; + } + } + return $this; }