Vsphere Import Source with Modifiers on custom_values

Hello,

I am struggeling trying to filter some systems out, that have a specific custom_value set.

Then I get this error in the preview:

Oops, an error occurred!
preg_match() expects parameter 2 to be string, object given (FilterExpression.php:209)
#0 [internal function]: Icinga\Application\ApplicationBootstrap->Icinga\Application\{closure}(2, 'preg_match() ex...', '/usr/share/php/...', 209, Array)
#1 /usr/share/php/Icinga/Data/Filter/FilterExpression.php(209): preg_match('/^.*NO_MONITORI...', Object(stdClass))
#2 /usr/share/icingaweb2/modules/director/library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php(101): Icinga\Data\Filter\FilterExpression->matches(Object(stdClass))
#3 /usr/share/icingaweb2/modules/director/library/Director/PropertyModifier/PropertyModifierRejectOrSelect.php(135): Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect->matchesWildcard(Object(stdClass), '*NO_MONITORING*')
#4 /usr/share/icingaweb2/modules/director/library/Director/Objects/ImportSource.php(389): Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect->transform(Object(stdClass))
#5 /usr/share/icingaweb2/modules/director/library/Director/Objects/ImportSource.php(316): Icinga\Module\Director\Objects\ImportSource->applyPropertyModifierToRow(Object(Icinga\Module\Director\PropertyModifier\PropertyModifierRejectOrSelect), 'custom_values', Object(stdClass))
#6 /usr/share/icingaweb2/modules/director/library/Director/Web/Table/ImportsourceHookTable.php(102): Icinga\Module\Director\Objects\ImportSource->applyModifiers(Array)
#7 /usr/share/icingaweb2/modules/incubator/vendor/gipfl/icingaweb2/src/Table/SimpleQueryBasedTable.php(29): Icinga\Module\Director\Web\Table\ImportsourceHookTable->prepareQuery()
#8 /usr/share/icingaweb2/modules/incubator/vendor/gipfl/icingaweb2/src/Table/SimpleQueryBasedTable.php(15): gipfl\IcingaWeb2\Table\SimpleQueryBasedTable->getQuery()
#9 /usr/share/icingaweb2/modules/incubator/vendor/gipfl/icingaweb2/src/Table/QueryBasedTable.php(59): gipfl\IcingaWeb2\Table\SimpleQueryBasedTable->getPaginationAdapter()
#10 /usr/share/icingaweb2/modules/incubator/vendor/gipfl/icingaweb2/src/Table/QueryBasedTable.php(258): gipfl\IcingaWeb2\Table\QueryBasedTable->getPaginator(Object(gipfl\IcingaWeb2\Url))
#11 /usr/share/icingaweb2/modules/director/application/controllers/ImportsourceController.php(186): gipfl\IcingaWeb2\Table\QueryBasedTable->renderTo(Object(Icinga\Module\Director\Controllers\ImportsourceController))
#12 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(507): Icinga\Module\Director\Controllers\ImportsourceController->previewAction()
#13 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch('previewAction')
#14 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#15 /usr/share/php/Icinga/Application/Web.php(304): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))
#16 /usr/share/php/Icinga/Application/webrouter.php(107): Icinga\Application\Web->dispatch()
#17 /usr/share/icingaweb2/public/index.php(4): require_once('/usr/share/php/...')
#18 {main}

The error,
→ preg_match() expects parameter 2 to be string, object given (FilterExpression.php:209)
in my understandment means that the filter does expect an string, but the custom_value field is an dict:

grafik

Did anyone was able to do this with the modifiers?


  • Director version (System - About): 1.9.1
  • Icinga Web 2 version and modules (System - About): 2.9.5
  • Icinga 2 version (icinga2 --version): 2.13.2-1
  • Operating System and version: Rocky8.4
  • Webserver, PHP versions: 7.4.19

I think you need to use custom_values.NO_MONITORING to set a property first and then in a following modifier discard the row depending on the new property.

I have tried this already

but then Director fails do compile the field, in cases it is empty!

Oops, an error occurred!
Data is not nested, cannot access custom_values.Monitoring_Service: (object) array(
   'object_name' => 'SYSTEM',
   'vcenter_name' => 'system.domain.com',
   'guest_ip_address' => '123.123.252.158',
   'hardware_numcpu' => '4',
   'hardware_memorymb' => '16384',
   'guest_id' => 'centos7_64Guest',
   'guest_full_name' => 'CentOS 7 (64-bit)',
   'guest_host_name' => 'system',
   'custom_values' => NULL,
   'host' => 'system.domain.com',
   'name' => 'system',
   'address' => '123.123.252.158',
) (SyncUtils.php:96)

So I need to fill up all 400 VM with some value to be able to use this field.

I use:


But in your case you flip the logic to accept if NULL.

Edit: yes I had to ignore all with custom_values => NULL, in a earlier filter or I would get the same error.
It wasn’t a problem for me as I only want hosts that have a team defined as only then I can alert somebody :wink: