MonitoredObject: obfuscate custom variables recursively

refs #10640
This commit is contained in:
Alexander A. Klimov 2016-01-22 18:37:27 +01:00
parent 5e51bb9c74
commit 7bc489ba4d
1 changed files with 25 additions and 8 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Monitoring\Object;
use stdClass;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Data\Filter\Filter;
@ -456,18 +457,34 @@ abstract class MonitoredObject implements Filterable
$customvars = $this->hostVariables;
}
$this->customvars = array();
foreach ($customvars as $name => $value) {
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$this->customvars[$name] = '***';
} else {
$this->customvars[$name] = $value;
}
}
$this->customvars = $this->obfuscateCustomVars($customvars, $blacklistPattern);
return $this;
}
/**
* Obfuscate custom variables recursively for $this->customvars.
*
* @param stdClass|array $customvars The custom variables to obfuscate
* @param string $blacklistPattern Which custom variables to obfuscate
*
* @return stdClass|array The obfuscated custom variables
*/
protected function obfuscateCustomVars($customvars, $blacklistPattern)
{
$obfuscatedCustomVars = array();
foreach ($customvars as $name => $value) {
if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$obfuscatedCustomVars[$name] = '***';
} else {
$obfuscatedCustomVars[$name] = $value instanceof stdClass || is_array($value)
? $this->obfuscateCustomVars($value, $blacklistPattern)
: $value;
}
}
return $customvars instanceof stdClass ? (object) $obfuscatedCustomVars : $obfuscatedCustomVars;
}
/**
* Fetch the host custom variables related to this object
*