diff options
Diffstat (limited to 'library/Director/Objects/Extension')
-rw-r--r-- | library/Director/Objects/Extension/Arguments.php | 61 | ||||
-rw-r--r-- | library/Director/Objects/Extension/FlappingSupport.php | 54 | ||||
-rw-r--r-- | library/Director/Objects/Extension/PriorityColumn.php | 40 |
3 files changed, 155 insertions, 0 deletions
diff --git a/library/Director/Objects/Extension/Arguments.php b/library/Director/Objects/Extension/Arguments.php new file mode 100644 index 0000000..3acbdd3 --- /dev/null +++ b/library/Director/Objects/Extension/Arguments.php @@ -0,0 +1,61 @@ +<?php + +namespace Icinga\Module\Director\Objects\Extension; + +use Icinga\Module\Director\Objects\IcingaArguments; +use Icinga\Module\Director\Objects\IcingaObject; + +trait Arguments +{ + private $arguments; + + public function arguments() + { + /** @var IcingaObject $this */ + if ($this->arguments === null) { + if ($this->hasBeenLoadedFromDb()) { + $this->arguments = IcingaArguments::loadForStoredObject($this); + } else { + $this->arguments = new IcingaArguments($this); + } + } + + return $this->arguments; + } + + public function gotArguments() + { + return null !== $this->arguments; + } + + public function unsetArguments() + { + unset($this->arguments); + } + + /** + * @return string + */ + protected function renderArguments() + { + return $this->arguments()->toConfigString(); + } + + /** + * @param $value + * @return $this + */ + protected function setArguments($value) + { + $this->arguments()->setArguments($value); + return $this; + } + + /** + * @return array + */ + protected function getArguments() + { + return $this->arguments()->toPlainObject(); + } +} diff --git a/library/Director/Objects/Extension/FlappingSupport.php b/library/Director/Objects/Extension/FlappingSupport.php new file mode 100644 index 0000000..a86f10d --- /dev/null +++ b/library/Director/Objects/Extension/FlappingSupport.php @@ -0,0 +1,54 @@ +<?php + +namespace Icinga\Module\Director\Objects\Extension; + +use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; +use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; + +trait FlappingSupport +{ + /** + * @param $value + * @return string + * @codingStandardsIgnoreStart + */ + protected function renderFlapping_threshold_high($value) + { + return $this->renderFlappingThreshold('flapping_threshold_high', $value); + } + + /** + * @param $value + * @return string + */ + protected function renderFlapping_threshold_low($value) + { + return $this->renderFlappingThreshold('flapping_threshold_low', $value); + } + + protected function renderFlappingThreshold($key, $value) + { + return sprintf( + " try { // This setting is only available in Icinga >= 2.8.0\n" + . " %s" + . " } except { globals.directorWarnOnceForThresholds() }\n", + c::renderKeyValue($key, c::renderFloat($value)) + ); + } + + protected function renderLegacyEnable_flapping($value) + { + return c1::renderKeyValue('flap_detection_enabled', c1::renderBoolean($value)); + } + + protected function renderLegacyFlapping_threshold_high($value) + { + return c1::renderKeyValue('high_flap_threshold', $value); + } + + protected function renderLegacyFlapping_threshold_low($value) + { + // @codingStandardsIgnoreEnd + return c1::renderKeyValue('low_flap_threshold', $value); + } +} diff --git a/library/Director/Objects/Extension/PriorityColumn.php b/library/Director/Objects/Extension/PriorityColumn.php new file mode 100644 index 0000000..638bdc6 --- /dev/null +++ b/library/Director/Objects/Extension/PriorityColumn.php @@ -0,0 +1,40 @@ +<?php + +namespace Icinga\Module\Director\Objects\Extension; + +use Zend_Db_Expr as Expr; + +trait PriorityColumn +{ + public function setNextPriority($prioSetColumn = null, $prioColumn = 'priority') + { + /** @var \Zend_Db_Adapter_Abstract $db */ + $db = $this->getDb(); + $prioValue = '(CASE WHEN MAX(priosub.priority) IS NULL THEN 1' + . ' ELSE MAX(priosub.priority) + 1 END)'; + $query = $db->select() + ->from( + ['priosub' => $this->getTableName()], + "$prioValue" + ); + + if ($prioSetColumn !== null) { + $query->where("priosub.$prioSetColumn = ?", $this->get($prioSetColumn)); + } + + $this->set($prioColumn, new Expr('(' . $query . ')')); + + return $this; + } + + protected function refreshPriortyProperty($prioColumn = 'priority') + { + /** @var \Zend_Db_Adapter_Abstract $db */ + $db = $this->getDb(); + $idCol = $this->getAutoincKeyName(); + $query = $db->select() + ->from($this->getTableName(), $prioColumn) + ->where("$idCol = ?", $this->get($idCol)); + $this->reallySet($prioColumn, $db->fetchOne($query)); + } +} |