How to specify a regular expression to filter hosts for virt-who

Problem: I want to specify a regular expression for filtering hosts in the virt-who setting but don’t know how to specify the regular expression. I have esx(l|s)t*.contoso.com but I don’t see the ESXi hosts show up.

Expected outcome: Have some output to show whether the regular expression worked and a list of hosts that matched.

Foreman and Proxy versions: foreman-3.5.1.19-1.el8sat.noarch

Foreman and Proxy plugin versions: 3.5.1

Distribution and version: RHEL 8.8

Other relevant data:

journalctl for virt-who says:

/usr/bin/virt-who[192357]: 2023-08-15 22:40:59,683 [virtwho.destination_1390149217051072078 INFO] MainProcess(192357):Thread-7 @virt.py:_send_data:651 - Hosts-to-guests mapping for config "virt-who-config-1": 0 hypervisors and 0 guests found

I couldn’t find any docs or something in the forum to help me build a regex to match my hosts.

Even better would be something like esx(l|s)p\d{2}[k,s]{1}\.contoso\.com but yeah the primary question on how to specify this in here:

Now I saw this in the logs, but the UI does not show a toggle for what I am reading here:

Aug 15 22:59:13 foreman.contoso.com systemd[1]: Starting Daemon for reporting virtual guest IDs to subscription-manager...
Aug 15 22:59:13 foreman.contoso.com /usr/bin/virt-who[193822]: 2023-08-15 22:59:13,893 [virtwho.parser WARNING] MainProcess(193822):MainThread @parser.py:read_config_env_variables:237 - The use of environment variables and the use of the sysconfig file to configure virt-who are deprecated. Their use will be ignored in the next major release.
Aug 15 22:59:13 foreman.contoso.com /usr/bin/virt-who[193822]: 2023-08-15 22:59:13,932 [virtwho.rhsm_log WARNING] MainProcess(193822):MainThread @config.py:init_config:1594 - [global]: Ignoring unknown configuration option "no_proxy"
Aug 15 22:59:13 foreman.contoso.com /usr/bin/virt-who[193822]: 2023-08-15 22:59:13,933 [virtwho.rhsm_log WARNING] MainProcess(193822):MainThread @config.py:init_config:1594 - [virt-who-config-3]: "filter_hosts" is set, but filter_type is not set. Possible values of filter_type: "regex, wildcards". Using default: "wildcards".
Aug 15 22:59:13 foreman.contoso.com /usr/bin/virt-who[193822]: 2023-08-15 22:59:13,933 [virtwho.rhsm_log WARNING] MainProcess(193822):MainThread @config.py:init_config:1594 - [virt-who-config-2]: "filter_hosts" is set, but filter_type is not set. Possible values of filter_type: "regex, wildcards". Using default: "wildcards".
Aug 15 22:59:13 foreman.contoso.com /usr/bin/virt-who[193822]: 2023-08-15 22:59:13,933 [virtwho.rhsm_log WARNING] MainProcess(193822):MainThread @config.py:init_config:1594 - [virt-who-config-1]: "filter_hosts" is set, but filter_type is not set. Possible values of filter_type: "regex, wildcards". Using default: "wildcards".
Aug 15 22:59:13 foreman.contoso.com /usr/bin/virt-who[193822]: 2023-08-15 22:59:13,933 [virtwho.rhsm_log WARNING] MainProcess(193822):MainThread @config.py:init_config:1594 - [virt-who-config-4]: "filter_hosts" is set, but filter_type is not set. Possible values of filter_type: "regex, wildcards". Using default: "wildcards".

continued by a line which says 0 hypervisors and 0 guests found for the virt-who instance in question.

Sadly, the virt-who-config plugin has historically not been very good at exposing advanced config options.
From the looks of it, the filter_type option is one of those cases.
Personally, I would recommend switching to writing your config files yourself if you have the need for options the plugin does not expose. You can have a look at man virt-who and man virt-who-config to get you startet. The current configs should be in /etc/virt-who.d.
Of course, you can always submit a feature request and/or, depending on your coding skills, submit a PR yourself to add that feature.

Hope this helps

2 Likes

Gotcha! This solution totally works for me. Thanks for the information and hints to the man page :point_up: