PropertyModifierXlsNumericIp: new implementation

fixes #1296
This commit is contained in:
Thomas Gelf 2017-11-17 01:31:43 +01:00
parent efc36fdbb8
commit 0c4e18533b
3 changed files with 28 additions and 0 deletions

View File

@ -26,6 +26,7 @@ before switching to a new version.
* FIX: Sync is very powerful and allows for actions not available in the GUI. It
however allowed to store invalid single Service Objects with no Host. This is
now illegal, as it never makes any sense
* FEATURE: new Property Modifier for IPs formatted as number in Excel files (#1296)
1.4.2
-----

View File

@ -0,0 +1,26 @@
<?php
namespace Icinga\Module\Director\PropertyModifier;
use Icinga\Module\Director\Hook\PropertyModifierHook;
class PropertyModifierXlsNumericIp extends PropertyModifierHook
{
public function getName()
{
return 'Fix IP formatted as a number in MS Excel';
}
public function transform($value)
{
if (ctype_digit($value) && strlen($value) > 9 && strlen($value) <= 12) {
return preg_replace(
'/^(\d{1,3})(\d{3})(\d{3})(\d{3})/',
'\1.\2.\3.\4',
$value
);
} else {
return $value;
}
}
}

View File

@ -48,6 +48,7 @@ $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\Pro
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierLConfCustomVar');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierArrayFilter');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierCombine');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierXlsNumericIp');
$this->provideHook('director/Job', $prefix . 'Job\\HousekeepingJob');
$this->provideHook('director/Job', $prefix . 'Job\\ConfigJob');