summaryrefslogtreecommitdiffstats
path: root/library/Director/IcingaConfig
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/IcingaConfig')
-rw-r--r--library/Director/IcingaConfig/AgentWizard.php39
-rw-r--r--library/Director/IcingaConfig/AssignRenderer.php11
-rw-r--r--library/Director/IcingaConfig/ExtensibleSet.php2
-rw-r--r--library/Director/IcingaConfig/IcingaConfig.php31
-rw-r--r--library/Director/IcingaConfig/IcingaConfigHelper.php2
5 files changed, 70 insertions, 15 deletions
diff --git a/library/Director/IcingaConfig/AgentWizard.php b/library/Director/IcingaConfig/AgentWizard.php
index aceddb1..93527f5 100644
--- a/library/Director/IcingaConfig/AgentWizard.php
+++ b/library/Director/IcingaConfig/AgentWizard.php
@@ -148,15 +148,34 @@ class AgentWizard
public function renderIcinga4WindowsWizardCommand($token)
{
- $script = "Use-Icinga;\n"
- . 'Start-IcingaAgentInstallWizard `' . "\n "
+ $ifwParams = [
+ "IfW-DirectorSelfServiceKey" => [
+ "Values" => [$token],
+ ],
+ "IfW-DirectorUrl" => [
+ "Values" => [$this->getDirectorUrl()],
+ ],
+ "IfW-StableRepository" => [
+ "Values" => ["https://packages.icinga.com/IcingaForWindows/stable"],
+ ]
+ ];
+
+ $script = "[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11';\n"
+ . "\$ProgressPreference = 'SilentlyContinue';" . "\n"
+ . "[string]\$ScriptFile = 'C:\Users\Public\IcingaForWindows.ps1';\n"
+ . "\n"
+ . "Invoke-WebRequest `\n "
. $this->renderPowershellParameters([
- 'DirectorUrl' => $this->getDirectorUrl(),
- 'SelfServiceAPIKey' => $token,
- 'UseDirectorSelfService' => 1,
- 'OverrideDirectorVars' => 0,
- 'Reconfigure',
- 'RunInstaller'
+ 'UseBasicParsing',
+ 'Uri' => "https://packages.icinga.com/IcingaForWindows/IcingaForWindows.ps1",
+ 'OutFile' => '$ScriptFile;',
+ ]) . "\n"
+ . "\n"
+ . "& \$ScriptFile `\n "
+ . $this->renderPowershellParameters([
+ 'ModuleDirectory' => "C:\Program Files\WindowsPowerShell\Modules\\",
+ 'InstallCommand' => json_encode($ifwParams, JSON_UNESCAPED_SLASHES),
+ 'IcingaRepository' => "https://packages.icinga.com/IcingaForWindows/stable/ifw.repo.json"
]);
return $script;
@@ -235,6 +254,8 @@ class AgentWizard
$ret .= implode(', ', $vals);
} elseif (is_int($value)) {
$ret .= $value;
+ } elseif (is_string($value) && $value[0] === '$') {
+ $ret .= $value;
} else {
$ret .= $this->renderPowershellString($value);
}
@@ -297,7 +318,7 @@ class AgentWizard
} else {
$value = escapeshellarg($value);
}
- $script = preg_replace("~^#?$quotedKey='@$quotedKey@'$~m", "${key}=${value}", $script);
+ $script = preg_replace("~^#?$quotedKey='@$quotedKey@'$~m", "{$key}={$value}", $script);
}
return $script;
diff --git a/library/Director/IcingaConfig/AssignRenderer.php b/library/Director/IcingaConfig/AssignRenderer.php
index 6acbfee..495ad1e 100644
--- a/library/Director/IcingaConfig/AssignRenderer.php
+++ b/library/Director/IcingaConfig/AssignRenderer.php
@@ -2,6 +2,7 @@
namespace Icinga\Module\Director\IcingaConfig;
+use gipfl\Json\JsonDecodeException;
use gipfl\Json\JsonString;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterAnd;
@@ -128,8 +129,14 @@ class AssignRenderer
}
$column = $filter->getColumn();
- $rawExpression = Json::decode($filter->getExpression());
- $expression = $this->renderExpressionValue($rawExpression);
+ try {
+ $rawExpression = JsonString::decode($filter->getExpression());
+ $expression = $this->renderExpressionValue($rawExpression);
+ } catch (JsonDecodeException $e) {
+ throw new InvalidArgumentException(
+ "Got invalid JSON in filter string: $column" . $filter->getSign() . $filter->getExpression()
+ );
+ }
if (is_array($rawExpression) && $filter instanceof FilterMatch) {
return $this->renderInArray($column, $expression);
diff --git a/library/Director/IcingaConfig/ExtensibleSet.php b/library/Director/IcingaConfig/ExtensibleSet.php
index 9120816..d52a30e 100644
--- a/library/Director/IcingaConfig/ExtensibleSet.php
+++ b/library/Director/IcingaConfig/ExtensibleSet.php
@@ -50,7 +50,7 @@ class ExtensibleSet
$set->object = $object;
$set->propertyName = $propertyName;
- if ($object->hasBeenLoadedFromDb()) {
+ if ($object->hasBeenLoadedFromDb() && $id = $object->get('id')) {
$set->loadFromDb();
}
diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index 72edd7e..a79bf3c 100644
--- a/library/Director/IcingaConfig/IcingaConfig.php
+++ b/library/Director/IcingaConfig/IcingaConfig.php
@@ -25,6 +25,9 @@ class IcingaConfig
protected $zoneMap = array();
+ /** @var ?array Exists for caching reasons at rendering time */
+ protected $nonGlobalZones = null;
+
protected $lastActivityChecksum;
/** @var \Zend_Db_Adapter_Abstract */
@@ -349,6 +352,15 @@ class IcingaConfig
return $this->zoneMap[$id];
}
+ public function listNonGlobalZones(): array
+ {
+ if ($this->nonGlobalZones === null) {
+ $this->nonGlobalZones = array_values($this->connection->enumNonglobalZones());
+ }
+
+ return $this->nonGlobalZones;
+ }
+
/**
* @return self
*/
@@ -436,9 +448,9 @@ class IcingaConfig
$start = microtime(true);
MemoryLimit::raiseTo('1024M');
- ini_set('max_execution_time', 0);
+ ini_set('max_execution_time', '0');
// Workaround for https://bugs.php.net/bug.php?id=68606 or similar
- ini_set('zend.enable_gc', 0);
+ ini_set('zend.enable_gc', '0');
if (! $this->connection->isPgsql() && $this->db->quote("1\0") !== '\'1\\0\'') {
throw new RuntimeException(
@@ -501,6 +513,7 @@ class IcingaConfig
"\nconst DirectorStageDir = dirname(dirname(current_filename))\n"
. $this->renderFlappingLogHelper()
. $this->renderHostOverridableVars()
+ . $this->renderIfwFallbackTemplate()
);
return $this;
@@ -566,6 +579,20 @@ if (! globals.contains(DirectorOverrideTemplate)) {
);
}
+
+ protected function renderIfwFallbackTemplate(): string
+ {
+ return '
+// Make sure config validates for Icinga < 2.14 with IfW 1.11 configuration. This might look weird,
+// but is intentional. get_object() does\'t work as expected at parse time.
+if (! globals.System || ! System.get_template || ! get_template(CheckCommand, "ifw-api-check-command")) {
+ object CheckCommand "ifw-api" {
+ import "plugin-check-command"
+ }
+}
+';
+ }
+
/**
* @param string $checksum
*
diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php
index 03c017e..634337f 100644
--- a/library/Director/IcingaConfig/IcingaConfigHelper.php
+++ b/library/Director/IcingaConfig/IcingaConfigHelper.php
@@ -177,7 +177,7 @@ class IcingaConfigHelper
throw new InvalidArgumentException(sprintf(
'Unexpected type %s',
- var_export($value, 1)
+ var_export($value, true)
));
}