dmeyers-berkley

updated

14 years ago

0

140478

August 17th, 2012 13:00

Determine if host is virtual in groovy script

Hi,

I am writing a groovy script to pull some data from our SQL Server instances being monitored.  I would like to be able to differentiate b/w physical hosts and virtual hosts.  I know this must be possible since the database dashboard shows a different icon for the two.  However, I can find what data item or property I would look at to determine this.

db_hosts.png

I am using the following code:

dataSrv = server.DataService

querySvc = server.QueryService

topologyQuery = "!DBSS_Instance"

objects = querySvc.queryTopologyObjects(topologyQuery)

// Need a way to determine if each object is on a physical or virtual host

//...........

Thanks.

  • 591

    1

    Posted August 17th, 2012 18:00

    Thanks.  That pointed me in the right direction.  For anyone looking for code, I am using:

    ...

    topologyQuery = "!DBSS_Instance"

    objects = querySvc.queryTopologyObjects(topologyQuery)

    objects.each { object->

        instance_name = object.name

        instance_host_name = object.real_mon_instance_name

        vm = 'Physical'

        vmQuery = "!VMWVirtualMachine where host.name = '"+instance_host_name+"'"

        vms = querySvc.queryTopologyObjects(vmQuery)

        if (vms.size() > 0) {

            vm = 'VM'

        }

    ...

  • john_s_main

    132 Posts

    591

    1

    Posted August 17th, 2012 14:00

    Get the host object, check to see if it has a counterpart of type Monitoring:VMware Virtual Machine, using a query something like this:

    Using the following required input parameters:

        {host} : of type foglight-5:Host

    Select objects of type VMware Virtual Machine from the "(Default)" datasource (of type foglight-5)

        from Root of (foglight-5:default)/VMWModel/virtualCenters/virtualMachineCollection/virtualMachines

        where:

            {host}/name equals /name

    You could also check {host}/name equals /host/name, or {host}/uniqueId equals /host/uniqueId might be a bit more accurate, I haven't tested this extensively.