Search in sources :

Example 11 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareImporter method iterateHostSystems.

/**
     * Iterates through the host systems and adds them to the requisition object.
     *
     * @param vmwareViJavaAccess the access/connection to use
     * @throws RemoteException
     */
private void iterateHostSystems(VmwareViJavaAccess vmwareViJavaAccess, int apiVersion) throws RemoteException {
    ManagedEntity[] hostSystems;
    // search for host systems (esx hosts)
    logger.debug("Starting to iterate host systems on VMware host {} ...", request.getHostname());
    hostSystems = vmwareViJavaAccess.searchManagedEntities("HostSystem");
    if (hostSystems != null) {
        for (ManagedEntity managedEntity : hostSystems) {
            HostSystem hostSystem = (HostSystem) managedEntity;
            logger.debug("Iterating host systems on VMware management server {} : {} (ID: {})", request.getHostname(), hostSystem.getName(), hostSystem.getMOR().getVal());
            m_hostSystemMap.put(hostSystem.getMOR().getVal(), hostSystem.getName());
            // check for correct key/value-pair
            if (checkHostPowerState(hostSystem) && checkForAttribute(hostSystem)) {
                logger.debug("Adding Host System '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
                // iterate over all service console networks and add interface Ip addresses
                TreeSet<String> ipAddresses = vmwareViJavaAccess.getHostSystemIpAddresses(hostSystem);
                // create the new node...
                RequisitionNode node = createRequisitionNode(ipAddresses, hostSystem, apiVersion, vmwareViJavaAccess);
                // add cpu
                try {
                    node.putAsset(new RequisitionAsset("cpu", hostSystem.getHardware().getCpuInfo().getNumCpuCores() + " cores"));
                } catch (Exception e) {
                    logger.debug("Can't find CPU information for {} (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
                }
                // add memory
                try {
                    node.putAsset(new RequisitionAsset("ram", Math.round(hostSystem.getHardware().getMemorySize() / 1000000f) + " MB"));
                } catch (Exception e) {
                    logger.debug("Can't find Memory information for {} (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
                }
                // add vendor
                /*
                    try {
                        node.putAsset(new RequisitionAsset("vendor", hostSystem.getHardware().getSystemInfo().getVendor()));
                    } catch (Exception e) {
                        logger.debug("Can't find vendor information for {}", hostSystem.getName());
                    }
                    */
                // set the location
                node.setLocation(request.getLocation());
                // ...and add it to the requisition
                if (node != null && request.isPersistHosts()) {
                    m_requisition.insertNode(node);
                }
            }
        }
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) HostSystem(com.vmware.vim25.mo.HostSystem) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) CIMException(org.sblim.wbem.cim.CIMException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 12 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareViJavaAccess method getManagedEntityByManagedObjectId.

/**
     * Returns a managed entitiy for a given managed object Id.
     *
     * @param managedObjectId the managed object Id
     * @return the managed entity
     */
public ManagedEntity getManagedEntityByManagedObjectId(String managedObjectId) {
    ManagedObjectReference managedObjectReference = new ManagedObjectReference();
    managedObjectReference.setType("ManagedEntity");
    managedObjectReference.setVal(managedObjectId);
    ManagedEntity managedEntity = MorUtil.createExactManagedEntity(m_serviceInstance.getServerConnection(), managedObjectReference);
    return managedEntity;
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 13 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareViJavaAccess method queryPerformanceValues.

/**
     * This method queries performance values for a given managed entity.
     *
     * @param managedEntity the managed entity to query
     * @return the perfomance values
     * @throws RemoteException
     */
public VmwarePerformanceValues queryPerformanceValues(ManagedEntity managedEntity) throws RemoteException {
    VmwarePerformanceValues vmwarePerformanceValues = new VmwarePerformanceValues();
    int refreshRate = getPerformanceManager().queryPerfProviderSummary(managedEntity).getRefreshRate();
    PerfQuerySpec perfQuerySpec = new PerfQuerySpec();
    perfQuerySpec.setEntity(managedEntity.getMOR());
    perfQuerySpec.setMaxSample(Integer.valueOf(1));
    perfQuerySpec.setIntervalId(refreshRate);
    PerfEntityMetricBase[] perfEntityMetricBases = getPerformanceManager().queryPerf(new PerfQuerySpec[] { perfQuerySpec });
    if (perfEntityMetricBases != null) {
        for (int i = 0; i < perfEntityMetricBases.length; i++) {
            PerfMetricSeries[] perfMetricSeries = ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();
            for (int j = 0; perfMetricSeries != null && j < perfMetricSeries.length; j++) {
                if (perfMetricSeries[j] instanceof PerfMetricIntSeries) {
                    long[] longs = ((PerfMetricIntSeries) perfMetricSeries[j]).getValue();
                    if (longs.length == 1) {
                        PerfCounterInfo perfCounterInfo = getPerfCounterInfoMap().get(perfMetricSeries[j].getId().getCounterId());
                        String instance = perfMetricSeries[j].getId().getInstance();
                        String name = getHumanReadableName(perfCounterInfo);
                        if (instance != null && !"".equals(instance)) {
                            vmwarePerformanceValues.addValue(name, instance, longs[0]);
                        } else {
                            vmwarePerformanceValues.addValue(name, longs[0]);
                        }
                    }
                }
            }
        }
    }
    return vmwarePerformanceValues;
}
Also used : PerfMetricIntSeries(com.vmware.vim25.PerfMetricIntSeries) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) PerfMetricSeries(com.vmware.vim25.PerfMetricSeries) VmwarePerformanceValues(org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues) PerfQuerySpec(com.vmware.vim25.PerfQuerySpec) PerfEntityMetricBase(com.vmware.vim25.PerfEntityMetricBase) PerfEntityMetric(com.vmware.vim25.PerfEntityMetric)

Example 14 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareCimQuery method cimQuery.

private static void cimQuery(String hostname, String username, String password) {
    System.out.print("Trying to connect to " + hostname + "... ");
    VmwareViJavaAccess vmwareViJavaAccess = new VmwareViJavaAccess(hostname, username, password);
    try {
        vmwareViJavaAccess.connect();
    } catch (MalformedURLException e) {
        System.out.println("Exception:");
        e.printStackTrace();
        return;
    } catch (RemoteException e) {
        System.out.println("Exception:");
        e.printStackTrace();
        return;
    }
    System.out.println("Success!");
    ManagedEntity[] hostSystems;
    System.out.print(" Querying " + hostname + " for host systems... ");
    try {
        hostSystems = vmwareViJavaAccess.searchManagedEntities("HostSystem");
    } catch (RemoteException remoteException) {
        remoteException.printStackTrace();
        vmwareViJavaAccess.disconnect();
        return;
    }
    if (hostSystems != null) {
        System.out.println(hostSystems.length + " host system(s) found!");
        for (ManagedEntity managedEntity : hostSystems) {
            HostSystem hostSystem = (HostSystem) managedEntity;
            if (hostSystem.getSummary() != null) {
                if (hostSystem.getRuntime() != null) {
                    String powerState = hostSystem.getRuntime().getPowerState().toString();
                    if (!"poweredOn".equals(powerState)) {
                        System.out.println("  Ignoring host system " + hostSystem.getName() + " (powerState=" + powerState + ")... ");
                        continue;
                    } else {
                        System.out.print("  Determining primary Ip address of host system " + hostSystem.getName() + " (powerState=" + powerState + ")... ");
                    }
                } else {
                    System.out.println("  Ignoring host system " + hostSystem.getName() + " (powerState=unknown)... ");
                    continue;
                }
            } else {
                System.out.println("  Ignoring host system " + hostSystem.getName() + " (powerState=unknown)... ");
                continue;
            }
            String ipAddress;
            try {
                ipAddress = vmwareViJavaAccess.getPrimaryHostSystemIpAddress(hostSystem);
            } catch (RemoteException remoteException) {
                System.out.println("Exception:");
                remoteException.printStackTrace();
                continue;
            }
            if (ipAddress != null) {
                System.out.print(ipAddress + "\n  Querying host system " + hostSystem.getName() + " for numeric sensors... ");
                List<CIMObject> cimObjects;
                try {
                    cimObjects = vmwareViJavaAccess.queryCimObjects(hostSystem, "CIM_NumericSensor");
                } catch (Exception e) {
                    System.out.println("Exception:");
                    e.printStackTrace();
                    continue;
                }
                if (cimObjects != null) {
                    // FIXME queryCimObjects returns an empty list or a filled list, but never null
                    System.out.println(cimObjects.size() + " sensor(s) found!");
                    for (CIMObject cimObject : cimObjects) {
                        String healthState = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, "HealthState");
                        String cimObjectName = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, "Name");
                        System.out.print("   " + cimObjectName);
                        if (healthState != null) {
                            System.out.println(" " + m_healthStates.get(Integer.valueOf(healthState)));
                        } else {
                            System.out.println();
                        }
                    }
                } else {
                    System.out.println("NULL - aborting...");
                    continue;
                }
            } else {
                System.out.println("NULL - aborting...");
                continue;
            }
        }
    } else {
        System.out.println("NULL - aborting...");
    }
    System.out.println("Cleaning up...");
    vmwareViJavaAccess.disconnect();
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) MalformedURLException(java.net.MalformedURLException) CIMObject(org.sblim.wbem.cim.CIMObject) HostSystem(com.vmware.vim25.mo.HostSystem) RemoteException(java.rmi.RemoteException) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException)

Example 15 with ManagedEntity

use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.

the class VmwareConfigBuilder method generateData.

private void generateData(String rrdRepository) throws Exception {
    serviceInstance = new ServiceInstance(new URL("https://" + hostname + "/sdk"), username, password);
    performanceManager = serviceInstance.getPerformanceManager();
    PerfCounterInfo[] perfCounterInfos = performanceManager.getPerfCounter();
    for (PerfCounterInfo perfCounterInfo : perfCounterInfos) {
        perfCounterInfoMap.put(perfCounterInfo.getKey(), perfCounterInfo);
    }
    System.out.println("Generating configuration files for '" + serviceInstance.getAboutInfo().getFullName() + "' using rrdRepository '" + rrdRepository + "'...");
    StringBuffer buffer = new StringBuffer();
    buffer.append("Configuration file generated for:\n\n");
    buffer.append("Full name.......: " + serviceInstance.getAboutInfo().getFullName() + "\n");
    buffer.append("API type........: " + serviceInstance.getAboutInfo().getApiType() + "\n");
    buffer.append("API version.....: " + serviceInstance.getAboutInfo().getApiVersion() + "\n");
    buffer.append("Product name....: " + serviceInstance.getAboutInfo().getLicenseProductName() + "\n");
    buffer.append("Product version.: " + serviceInstance.getAboutInfo().getLicenseProductVersion() + "\n");
    buffer.append("OS type.........: " + serviceInstance.getAboutInfo().getOsType() + "\n");
    versionInformation = buffer.toString();
    String[] arr = serviceInstance.getAboutInfo().getApiVersion().split("\\.");
    if (arr.length > 1) {
        apiVersion = arr[0];
        if (Integer.valueOf(apiVersion) < 4) {
            apiVersion = "3";
        }
    }
    ManagedEntity[] hostSystems, virtualMachines;
    virtualMachines = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("VirtualMachine");
    if (virtualMachines != null) {
        if (virtualMachines.length > 0) {
            for (ManagedEntity managedEntity : virtualMachines) {
                if ("poweredOn".equals(((VirtualMachine) managedEntity).getRuntime().getPowerState().toString())) {
                    lookupMetrics("default-VirtualMachine" + apiVersion, managedEntity.getMOR().getVal());
                    break;
                }
            }
        } else {
            System.err.println("No virtual machines found");
        }
    }
    hostSystems = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("HostSystem");
    if (hostSystems != null) {
        if (hostSystems.length > 0) {
            for (ManagedEntity managedEntity : hostSystems) {
                if ("poweredOn".equals(((HostSystem) managedEntity).getRuntime().getPowerState().toString())) {
                    lookupMetrics("default-HostSystem" + apiVersion, managedEntity.getMOR().getVal());
                    break;
                }
            }
        } else {
            System.err.println("No host systems found!");
        }
    }
    saveVMwareDatacollectionConfig(rrdRepository);
    saveVMwareDatacollectionInclude();
    saveVMwareGraphProperties();
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) ServiceInstance(com.vmware.vim25.mo.ServiceInstance) URL(java.net.URL) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator)

Aggregations

ManagedEntity (com.vmware.vim25.mo.ManagedEntity)12 RemoteException (java.rmi.RemoteException)8 MalformedURLException (java.net.MalformedURLException)6 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)5 PerfCounterInfo (com.vmware.vim25.PerfCounterInfo)5 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)5 ObjectContent (com.vmware.vim25.ObjectContent)4 ObjectSpec (com.vmware.vim25.ObjectSpec)4 PerfEntityMetric (com.vmware.vim25.PerfEntityMetric)4 PerfMetricIntSeries (com.vmware.vim25.PerfMetricIntSeries)4 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)4 PropertySpec (com.vmware.vim25.PropertySpec)4 TraversalSpec (com.vmware.vim25.TraversalSpec)4 HostSystem (com.vmware.vim25.mo.HostSystem)4 PerfQuerySpec (com.vmware.vim25.PerfQuerySpec)3 SelectionSpec (com.vmware.vim25.SelectionSpec)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 UnknownHostException (java.net.UnknownHostException)3 ArrayList (java.util.ArrayList)3 VmwarePerformanceValues (org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues)3