Search in sources :

Example 6 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareCimCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final OnmsNode onmsNode = m_nodeDao.get(agent.getNodeId());
    if (onmsNode == null) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No node found with id: %d", agent.getNodeId()));
    }
    // retrieve the assets
    final String vmwareManagementServer = onmsNode.getAssetRecord().getVmwareManagementServer();
    if (Strings.isNullOrEmpty(vmwareManagementServer)) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No management server is set on node with id %d.", onmsNode.getId()));
    }
    runtimeAttributes.put(VMWARE_MGMT_SERVER_KEY, vmwareManagementServer);
    final String vmwareManagedObjectId = onmsNode.getForeignId();
    if (Strings.isNullOrEmpty(vmwareManagedObjectId)) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No foreign id is set on node with id %d.", onmsNode.getId()));
    }
    runtimeAttributes.put(VMWARE_MGED_OBJECT_ID_KEY, vmwareManagedObjectId);
    // retrieve the collection
    final String collectionName = ParameterMap.getKeyedString(parameters, "collection", ParameterMap.getKeyedString(parameters, "vmware-collection", null));
    final VmwareCimCollection collection = m_vmwareCimDatacollectionConfigDao.getVmwareCimCollection(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No collection found with name '%s'.", collectionName));
    }
    runtimeAttributes.put(VMWARE_COLLECTION_KEY, collection);
    // retrieve the server configuration
    final Map<String, VmwareServer> serverMap = m_vmwareConfigDao.getServerMap();
    if (serverMap == null) {
        throw new IllegalStateException(String.format("VmwareCollector: Error getting vmware-config.xml's server map."));
    }
    final VmwareServer vmwareServer = serverMap.get(vmwareManagementServer);
    if (vmwareServer == null) {
        throw new IllegalStateException(String.format("VmwareCollector: Error getting credentials for VMware management server: %s", vmwareManagementServer));
    }
    runtimeAttributes.put(VMWARE_SERVER_KEY, vmwareServer);
    return runtimeAttributes;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) CIMObject(org.sblim.wbem.cim.CIMObject) VmwareCimCollection(org.opennms.netmgt.config.vmware.cim.VmwareCimCollection)

Example 7 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class AbstractVmwareMonitor method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(MonitoredService svc, Map<String, Object> parameters) {
    if (m_nodeDao == null) {
        m_nodeDao = BeanUtils.getBean("daoContext", "nodeDao", NodeDao.class);
    }
    if (m_vmwareConfigDao == null) {
        m_vmwareConfigDao = BeanUtils.getBean("daoContext", "vmwareConfigDao", VmwareConfigDao.class);
    }
    final OnmsNode onmsNode = m_nodeDao.get(svc.getNodeId());
    if (onmsNode == null) {
        throw new IllegalArgumentException("No node found with ID: " + svc.getNodeId());
    }
    // retrieve the assets
    final String vmwareManagementServer = onmsNode.getAssetRecord().getVmwareManagementServer();
    final String vmwareManagedEntityType = onmsNode.getAssetRecord().getVmwareManagedEntityType();
    final String vmwareManagedObjectId = onmsNode.getForeignId();
    String vmwareMangementServerUsername = null;
    String vmwareMangementServerPassword = null;
    final Map<String, VmwareServer> serverMap = m_vmwareConfigDao.getServerMap();
    if (serverMap == null) {
        logger.error("Error getting vmware-config.xml's server map.");
    } else {
        final VmwareServer vmwareServer = serverMap.get(vmwareManagementServer);
        if (vmwareServer == null) {
            logger.error("Error getting credentials for VMware management server '{}'.", vmwareManagementServer);
        } else {
            vmwareMangementServerUsername = vmwareServer.getUsername();
            vmwareMangementServerPassword = vmwareServer.getPassword();
        }
    }
    return new ImmutableMap.Builder<String, Object>().put(VMWARE_MANAGEMENT_SERVER_KEY, vmwareManagementServer).put(VMWARE_MANAGED_ENTITY_TYPE_KEY, vmwareManagedEntityType).put(VMWARE_MANAGED_OBJECT_ID_KEY, vmwareManagedObjectId).put(VMWARE_MANAGEMENT_SERVER_USERNAME_KEY, vmwareMangementServerUsername).put(VMWARE_MANAGEMENT_SERVER_PASSWORD_KEY, vmwareMangementServerPassword).build();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) VmwareConfigDao(org.opennms.netmgt.dao.VmwareConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer)

Example 8 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareCimCollectorComplianceTest method getRequiredBeans.

@Override
public Map<String, Object> getRequiredBeans() {
    OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(anyInt())).thenReturn(node);
    when(node.getAssetRecord().getVmwareManagementServer()).thenReturn("mdx");
    when(node.getAssetRecord().getVmwareManagedEntityType()).thenReturn("tsx");
    when(node.getForeignId()).thenReturn("rsx");
    VmwareCimCollection collection = new VmwareCimCollection();
    VmwareCimDatacollectionConfigDao vmwareCimDatacollectionConfigDao = mock(VmwareCimDatacollectionConfigDao.class);
    when(vmwareCimDatacollectionConfigDao.getVmwareCimCollection(COLLECTION)).thenReturn(collection);
    when(vmwareCimDatacollectionConfigDao.getRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
    VmwareServer vmwareServer = new VmwareServer();
    vmwareServer.setHostname(InetAddrUtils.getLocalHostAddress().getCanonicalHostName());
    Map<String, VmwareServer> serverMap = new ImmutableMap.Builder<String, VmwareServer>().put("mdx", vmwareServer).build();
    VmwareConfigDao vmwareConfigDao = mock(VmwareConfigDao.class);
    when(vmwareConfigDao.getServerMap()).thenReturn(serverMap);
    return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("vmwareCimDatacollectionConfigDao", vmwareCimDatacollectionConfigDao).put("vmwareConfigDao", vmwareConfigDao).build();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) VmwareConfigDao(org.opennms.netmgt.dao.VmwareConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) VmwareCimDatacollectionConfigDao(org.opennms.netmgt.dao.VmwareCimDatacollectionConfigDao) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) VmwareCimCollection(org.opennms.netmgt.config.vmware.cim.VmwareCimCollection) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Example 9 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareRequisitionTool method main.

public static void main(String[] args) throws Exception {
    final Options options = new Options();
    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd = parser.parse(options, args);
    @SuppressWarnings("unchecked") List<String> arguments = (List<String>) cmd.getArgList();
    if (arguments.size() < 1) {
        usage(options, cmd);
        System.exit(1);
    }
    // Internal trick to avoid confusions.
    String urlString = arguments.remove(0).replaceFirst("vmware", "http");
    URL url = new URL(urlString);
    // Parse vmware-config.xml and retrieve the credentials to avoid initialize Spring
    if (!url.getQuery().contains("username") && url.getUserInfo() == null) {
        File cfg = new File(ConfigFileConstants.getFilePathString(), "vmware-config.xml");
        if (cfg.exists()) {
            String username = null;
            String password = null;
            VmwareConfig config = JaxbUtils.unmarshal(VmwareConfig.class, cfg);
            for (VmwareServer srv : config.getVmwareServerCollection()) {
                if (srv.getHostname().equals(url.getHost())) {
                    username = srv.getUsername();
                    password = srv.getPassword();
                }
            }
            if (username == null || password == null) {
                throw new IllegalArgumentException("Can't retrieve credentials for " + url.getHost() + " from " + cfg);
            }
            // Add credentials to URL
            urlString = urlString + ";username=" + username + ";password=" + password;
            url = new URL(urlString);
        }
    }
    VmwareRequisitionUrlConnection c = new VmwareRequisitionUrlConnection(url) {

        @Override
        protected Requisition getExistingRequisition(String foreignSource) {
            // This is not elegant but it is necessary to avoid booting Spring
            File req = new File(ConfigFileConstants.getFilePathString(), "imports" + File.separator + foreignSource + ".xml");
            if (req.exists()) {
                return JaxbUtils.unmarshal(Requisition.class, req);
            }
            return null;
        }
    };
    c.connect();
    InputStream is = c.getInputStream();
    if (is == null) {
        System.err.println("Couldn't generate requisition from " + urlString);
        System.exit(1);
    } else {
        System.out.println(IOUtils.toString(is, StandardCharsets.UTF_8));
    }
}
Also used : Options(org.apache.commons.cli.Options) InputStream(java.io.InputStream) PosixParser(org.apache.commons.cli.PosixParser) VmwareConfig(org.opennms.netmgt.config.vmware.VmwareConfig) URL(java.net.URL) CommandLine(org.apache.commons.cli.CommandLine) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) List(java.util.List) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File)

Aggregations

VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)9 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 HashMap (java.util.HashMap)4 VmwareCimCollection (org.opennms.netmgt.config.vmware.cim.VmwareCimCollection)3 VmwareCollection (org.opennms.netmgt.config.vmware.vijava.VmwareCollection)3 VmwareConfigDao (org.opennms.netmgt.dao.VmwareConfigDao)3 NodeDao (org.opennms.netmgt.dao.api.NodeDao)3 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 List (java.util.List)2 AttributeType (org.opennms.netmgt.collection.api.AttributeType)2 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)2 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)2 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)2 Resource (org.opennms.netmgt.collection.support.builder.Resource)2 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)2 VmwareViJavaAccess (org.opennms.protocols.vmware.VmwareViJavaAccess)2 CIMObject (org.sblim.wbem.cim.CIMObject)2 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)1 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)1