Ad Widget

Collapse

Discover Rule - Add Guest OS to Host Group based on Host

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zablab
    Junior Member
    • Jan 2022
    • 28

    #1

    Discover Rule - Add Guest OS to Host Group based on Host

    I've read around & have found *similar* issues but nothing regarding this particular issue.

    We've got a number of Hypervisor Hosts: 1,2,3,etc
    We have Zabbix Agent installed on each Guest VM as well.
    We have a Host Group set up for each Hypervisor Host. With naming like, "Host 1 VMs"
    We use this for maintenance, tagging and other reasons.
    We are currently adding each Guest VM to each Hypervisor Host Group manually, which is pretty time-consuming.
    I know through Actions you can dynamically add Hosts to Host Groups, but I am not currently able to identify a variable that would allow me to dynamically add each Guest VM to their respective Hypervisor Host Group. Since Guest VMs can't *see* which Hypervisor Host they are running on, typically.

    Edit: With HyperV on the Guest VM it does appear there's a Registry Key that shows which Host it's running on. Is it possible to create a Zabbix Action to read this Registry key?

    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Vir tual Machine\Guest\Parameters\Hostname

    Example:
    Install Zabbix agent on "Guest VM1", "Guest VM2". Each resides on a different Hypervisor Host.
    Guest VM1 & Guest VM2 show up in Zabbix as their own Hosts, but how do I set up an action to identify that this is a Guest VM, one of which is running on "Hypervisor Host 1" & "Hypervisor Host 2", and add it to the respective Host Groups?

    I hope that makes sense, and that someone may find this interesting or have some direction otherwise I'll keep at it!

    Thanks!
    Last edited by Zablab; 02-02-2022, 18:03.
  • Zablab
    Junior Member
    • Jan 2022
    • 28

    #2
    After upgrading to 6.x I am now using Autodiscover action rules along with the Metadata parameters in the config file. I use invoke on the Guest VM to pull the Host from Guest VM registry, then update the Zabbix Config file Metadata parameter using text replacement. Then auto-discover action takes care of the rest based on those parameters and moves the Guest VM to the correct Host.

    Comment


    • Zablab
      Zablab commented
      Editing a comment
      Just if anybody is interested I grab the Host FQDN from GuestVM during zabbix installation then use text replacement to update Metadata in the config file, then autoregistration in Zabbix assigns the Host to a particular group where the Hypervisor resides.

      Code:
      $VMHost = Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\' -Name HostName
      
          (Get-Content "C:\Program Files\Zabbix Agent\zabbix_agentd.conf") | 
              ForEach-Object { $_ -replace "###\s+Option: Include", "###  Option: Include`nInclude=C:\Program Files\Zabbix Agent\zabbix_agentd.d\*.conf" -replace "#\s+1\s-\sAllowKey", "AllowKey" -replace "#\s+LogRemoteCommands=0", "LogRemoteCommands=1" -replace "#\s+Timeout=30", "Timeout=30" -replace "#\s+UnsafeUserParameters=0", "UnsafeUserParameters=1" -replace "#\s+HostMetadata=", "# HostMetadata=`nHostMetadata=:Host=$($VMHost):ServerType=$($ZabbixServerType):"} | 
              Set-Content "C:\Program Files\Zabbix Agent\zabbix_agentd.conf"
Working...