Search in sources :

Example 1 with RequisitionMonitoredService

use of org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService in project opennms by OpenNMS.

the class HeartbeatConsumer method provision.

private void provision(final OnmsMinion minion, final String prevLocation, final String nextLocation) {
    // Return fast if automatic provisioning is disabled
    if (!PROVISIONING) {
        return;
    }
    // Return fast until the provisioner is running to pick up the events sent below
    if (!this.eventSubscriptionService.hasEventListener(EventConstants.RELOAD_IMPORT_UEI)) {
        return;
    }
    final String prevForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, prevLocation);
    final String nextForeignSource = String.format(PROVISIONING_FOREIGN_SOURCE_PATTERN, nextLocation);
    final Set<String> alteredForeignSources = Sets.newHashSet();
    // Remove the node from the previous requisition, if location has changed
    if (!Objects.equals(prevForeignSource, nextForeignSource)) {
        final Requisition prevRequisition = this.deployedForeignSourceRepository.getRequisition(prevForeignSource);
        if (prevRequisition != null && prevRequisition.getNode(minion.getId()) != null) {
            prevRequisition.deleteNode(minion.getId());
            prevRequisition.updateDateStamp();
            deployedForeignSourceRepository.save(prevRequisition);
            deployedForeignSourceRepository.flush();
            alteredForeignSources.add(prevForeignSource);
        }
    }
    Requisition nextRequisition = deployedForeignSourceRepository.getRequisition(nextForeignSource);
    if (nextRequisition == null) {
        nextRequisition = new Requisition(nextForeignSource);
        nextRequisition.updateDateStamp();
        // We have to save the requisition before we can alter the according foreign source definition
        deployedForeignSourceRepository.save(nextRequisition);
        // Remove all policies and detectors from the foreign source
        final ForeignSource foreignSource = deployedForeignSourceRepository.getForeignSource(nextForeignSource);
        foreignSource.setDetectors(Collections.emptyList());
        foreignSource.setPolicies(Collections.emptyList());
        deployedForeignSourceRepository.save(foreignSource);
        alteredForeignSources.add(nextForeignSource);
    }
    RequisitionNode requisitionNode = nextRequisition.getNode(minion.getId());
    if (requisitionNode == null) {
        final RequisitionMonitoredService requisitionMonitoredService = new RequisitionMonitoredService();
        requisitionMonitoredService.setServiceName("Minion-Heartbeat");
        final RequisitionInterface requisitionInterface = new RequisitionInterface();
        requisitionInterface.setIpAddr("127.0.0.1");
        requisitionInterface.putMonitoredService(requisitionMonitoredService);
        requisitionNode = new RequisitionNode();
        requisitionNode.setNodeLabel(minion.getId());
        requisitionNode.setForeignId(minion.getLabel() != null ? minion.getLabel() : minion.getId());
        requisitionNode.setLocation(minion.getLocation());
        requisitionNode.putInterface(requisitionInterface);
        nextRequisition.putNode(requisitionNode);
        nextRequisition.setDate(new Date());
        deployedForeignSourceRepository.save(nextRequisition);
        deployedForeignSourceRepository.flush();
        alteredForeignSources.add(nextForeignSource);
    }
    for (final String alteredForeignSource : alteredForeignSources) {
        final EventBuilder eventBuilder = new EventBuilder(EventConstants.RELOAD_IMPORT_UEI, "Web");
        eventBuilder.addParam(EventConstants.PARM_URL, String.valueOf(deployedForeignSourceRepository.getRequisitionURL(alteredForeignSource)));
        try {
            eventProxy.send(eventBuilder.getEvent());
        } catch (final EventProxyException e) {
            throw new DataAccessResourceFailureException("Unable to send event to import group " + alteredForeignSource, e);
        }
    }
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) Date(java.util.Date)

Example 2 with RequisitionMonitoredService

use of org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService in project opennms by OpenNMS.

the class DnsRequisitionProvider method createRequisitionNode.

/**
     * Creates an instance of the JaxB annotated RequisionNode class.
     * 
     * @param rec
     * @return a populated RequisitionNode based on defaults and data from the A
     *         record returned from a DNS zone transfer query.
     */
private RequisitionNode createRequisitionNode(DnsRequisitionRequest request, Record rec) {
    String addr = null;
    if ("A".equals(Type.string(rec.getType()))) {
        final ARecord arec = (ARecord) rec;
        addr = StringUtils.stripStart(arec.getAddress().toString(), "/");
    } else if ("AAAA".equals(Type.string(rec.getType()))) {
        final AAAARecord aaaarec = (AAAARecord) rec;
        addr = aaaarec.rdataToString();
    } else {
        throw new IllegalArgumentException("Invalid record type " + Type.string(rec.getType()) + ". A or AAAA expected.");
    }
    final RequisitionNode n = new RequisitionNode();
    final String host = rec.getName().toString();
    final String nodeLabel = StringUtils.stripEnd(StringUtils.stripStart(host, "."), ".");
    n.setBuilding(request.getForeignSource());
    switch(request.getForeignIdHashSource()) {
        case NODE_LABEL:
            n.setForeignId(computeHashCode(nodeLabel));
            LOG.debug("Generating foreignId from hash of nodelabel {}", nodeLabel);
            break;
        case IP_ADDRESS:
            n.setForeignId(computeHashCode(addr));
            LOG.debug("Generating foreignId from hash of ipAddress {}", addr);
            break;
        case NODE_LABEL_AND_IP_ADDRESS:
            n.setForeignId(computeHashCode(nodeLabel + addr));
            LOG.debug("Generating foreignId from hash of nodelabel+ipAddress {}{}", nodeLabel, addr);
            break;
        default:
            n.setForeignId(computeHashCode(nodeLabel));
            LOG.debug("Default case: Generating foreignId from hash of nodelabel {}", nodeLabel);
            break;
    }
    n.setNodeLabel(nodeLabel);
    final RequisitionInterface i = new RequisitionInterface();
    i.setDescr("DNS-" + Type.string(rec.getType()));
    i.setIpAddr(addr);
    i.setSnmpPrimary(PrimaryType.PRIMARY);
    i.setManaged(Boolean.TRUE);
    i.setStatus(Integer.valueOf(1));
    for (String service : request.getServices()) {
        service = service.trim();
        i.insertMonitoredService(new RequisitionMonitoredService(service));
        LOG.debug("Adding provisioned service {}", service);
    }
    n.putInterface(i);
    return n;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) ARecord(org.xbill.DNS.ARecord) AAAARecord(org.xbill.DNS.AAAARecord) AAAARecord(org.xbill.DNS.AAAARecord) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Example 3 with RequisitionMonitoredService

use of org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService in project opennms by OpenNMS.

the class VmwareImporter method getRequisition.

public Requisition getRequisition() {
    logger.debug("Getting existing requisition (if any) for VMware management server {}", request.getHostname());
    Requisition curReq = request.getExistingRequisition();
    logger.debug("Building new requisition for VMware management server {}", request.getHostname());
    Requisition newReq = buildVMwareRequisition();
    logger.debug("Finished building new requisition for VMware management server {}", request.getHostname());
    if (curReq == null) {
        if (newReq == null) {
            // FIXME Is this correct ? This is the old behavior
            newReq = new Requisition(request.getForeignSource());
        }
    } else {
        if (newReq == null) {
            // If there is a requisition and the vCenter is not responding for some reason, it is better to use the old requisition,
            // instead of returning an empty one, which can cause the lost of all the nodes from the DB.
            newReq = curReq;
        } else {
            // The VMWare related assets and categories will be preserved.
            for (RequisitionNode newNode : newReq.getNodes()) {
                for (RequisitionNode curNode : curReq.getNodes()) {
                    if (newNode.getForeignId().equals(curNode.getForeignId())) {
                        // Add existing custom assets
                        for (RequisitionAsset asset : curNode.getAssets()) {
                            if (!asset.getName().startsWith("vmware")) {
                                newNode.putAsset(asset);
                            }
                        }
                        // Add existing custom categories
                        for (RequisitionCategory cat : curNode.getCategories()) {
                            if (!cat.getName().startsWith("VMWare")) {
                                newNode.putCategory(cat);
                            }
                        }
                        /*
                             * For each interface on the new requisition,
                             * - Retrieve the list of custom services from the corresponding interface on the existing requisition,
                             *   matching the interface by the IP address
                             * - If the list of services is not empty, add them to the new interface
                             */
                        for (RequisitionInterface intf : curNode.getInterfaces()) {
                            List<RequisitionMonitoredService> services = getManualyConfiguredServices(intf);
                            if (!services.isEmpty()) {
                                RequisitionInterface newIntf = getRequisitionInterface(newNode, intf.getIpAddr());
                                if (newIntf != null) {
                                    newIntf.getMonitoredServices().addAll(services);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return newReq;
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Example 4 with RequisitionMonitoredService

use of org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService in project opennms by OpenNMS.

the class VmwareImporter method createRequisitionNode.

/**
     * Creates a requisition node for the given managed entity and type.
     *
     * @param ipAddresses   the set of Ip addresses
     * @param managedEntity the managed entity
     * @return the generated requisition node
     */
private RequisitionNode createRequisitionNode(Set<String> ipAddresses, ManagedEntity managedEntity, int apiVersion, VmwareViJavaAccess vmwareViJavaAccess) {
    RequisitionNode requisitionNode = new RequisitionNode();
    // Setting the node label
    requisitionNode.setNodeLabel(managedEntity.getName());
    // Foreign Id consisting of managed entity Id
    requisitionNode.setForeignId(managedEntity.getMOR().getVal());
    if (managedEntity instanceof VirtualMachine) {
        boolean firstInterface = true;
        // add all given interfaces
        for (String ipAddress : ipAddresses) {
            try {
                if ((request.isPersistIPv4() && InetAddressUtils.isIPv4Address(ipAddress)) || (request.isPersistIPv6() && InetAddressUtils.isIPv6Address(ipAddress))) {
                    InetAddress inetAddress = InetAddress.getByName(ipAddress);
                    if (!inetAddress.isLoopbackAddress()) {
                        RequisitionInterface requisitionInterface = new RequisitionInterface();
                        requisitionInterface.setIpAddr(ipAddress);
                        //  the first one will be primary
                        if (firstInterface) {
                            requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
                            for (String service : request.getVirtualMachineServices()) {
                                requisitionInterface.insertMonitoredService(new RequisitionMonitoredService(service.trim()));
                            }
                            firstInterface = false;
                        } else {
                            requisitionInterface.setSnmpPrimary(PrimaryType.SECONDARY);
                        }
                        requisitionInterface.setManaged(Boolean.TRUE);
                        requisitionInterface.setStatus(Integer.valueOf(1));
                        requisitionNode.putInterface(requisitionInterface);
                    }
                }
            } catch (UnknownHostException unknownHostException) {
                logger.warn("Invalid IP address '{}'", unknownHostException.getMessage());
            }
        }
    } else {
        if (managedEntity instanceof HostSystem) {
            boolean reachableInterfaceFound = false, firstInterface = true;
            List<RequisitionInterface> requisitionInterfaceList = new ArrayList<RequisitionInterface>();
            RequisitionInterface primaryInterfaceCandidate = null;
            // add all given interfaces
            for (String ipAddress : ipAddresses) {
                try {
                    if ((request.isPersistIPv4() && InetAddressUtils.isIPv4Address(ipAddress)) || (request.isPersistIPv6() && InetAddressUtils.isIPv6Address(ipAddress))) {
                        InetAddress inetAddress = InetAddress.getByName(ipAddress);
                        if (!inetAddress.isLoopbackAddress()) {
                            RequisitionInterface requisitionInterface = new RequisitionInterface();
                            requisitionInterface.setIpAddr(ipAddress);
                            if (firstInterface) {
                                primaryInterfaceCandidate = requisitionInterface;
                                firstInterface = false;
                            }
                            if (!reachableInterfaceFound && reachableCimService(vmwareViJavaAccess, (HostSystem) managedEntity, ipAddress)) {
                                primaryInterfaceCandidate = requisitionInterface;
                                reachableInterfaceFound = true;
                            }
                            requisitionInterface.setManaged(Boolean.TRUE);
                            requisitionInterface.setStatus(Integer.valueOf(1));
                            requisitionInterface.setSnmpPrimary(PrimaryType.SECONDARY);
                            requisitionInterfaceList.add(requisitionInterface);
                        }
                    }
                } catch (UnknownHostException unknownHostException) {
                    logger.warn("Invalid IP address '{}'", unknownHostException.getMessage());
                }
            }
            if (primaryInterfaceCandidate != null) {
                if (reachableInterfaceFound) {
                    logger.warn("Found reachable primary interface '{}'", primaryInterfaceCandidate.getIpAddr());
                } else {
                    logger.warn("Only non-reachable interfaces found, using first one for primary interface '{}'", primaryInterfaceCandidate.getIpAddr());
                }
                primaryInterfaceCandidate.setSnmpPrimary(PrimaryType.PRIMARY);
                for (String service : request.getHostSystemServices()) {
                    if (reachableInterfaceFound || !"VMwareCim-HostSystem".equals(service)) {
                        primaryInterfaceCandidate.insertMonitoredService(new RequisitionMonitoredService(service.trim()));
                    }
                }
            } else {
                logger.warn("No primary interface found");
            }
            for (RequisitionInterface requisitionInterface : requisitionInterfaceList) {
                requisitionNode.putInterface(requisitionInterface);
            }
        } else {
            logger.error("Undefined type of managedEntity '{}'", managedEntity.getMOR().getType());
            return null;
        }
    }
    /*
         * For now we use displaycategory, notifycategory and pollercategory for storing
         * the vcenter Ip address, the username and the password
         */
    String powerState = "unknown";
    StringBuffer vmwareTopologyInfo = new StringBuffer();
    // putting parents to topology information
    ManagedEntity parentEntity = managedEntity.getParent();
    do {
        if (vmwareTopologyInfo.length() > 0) {
            vmwareTopologyInfo.append(", ");
        }
        try {
            if (parentEntity != null && parentEntity.getMOR() != null) {
                vmwareTopologyInfo.append(parentEntity.getMOR().getVal() + "/" + URLEncoder.encode(parentEntity.getName(), StandardCharsets.UTF_8.name()));
            } else {
                logger.warn("Can't add topologyInformation because either the parentEntity or the MOR is null for " + managedEntity.getName());
            }
        } catch (UnsupportedEncodingException e) {
            logger.warn("Unsupported encoding '{}'", e.getMessage());
        }
        parentEntity = parentEntity == null ? null : parentEntity.getParent();
    } while (parentEntity != null);
    if (managedEntity instanceof HostSystem) {
        HostSystem hostSystem = (HostSystem) managedEntity;
        HostRuntimeInfo hostRuntimeInfo = hostSystem.getRuntime();
        if (hostRuntimeInfo == null) {
            logger.debug("hostRuntimeInfo=null");
        } else {
            HostSystemPowerState hostSystemPowerState = hostRuntimeInfo.getPowerState();
            if (hostSystemPowerState == null) {
                logger.debug("hostSystemPowerState=null");
            } else {
                powerState = hostSystemPowerState.toString();
            }
        }
        try {
            if (request.isTopologyDatastores()) {
                for (Datastore datastore : hostSystem.getDatastores()) {
                    if (vmwareTopologyInfo.length() > 0) {
                        vmwareTopologyInfo.append(", ");
                    }
                    try {
                        vmwareTopologyInfo.append(datastore.getMOR().getVal() + "/" + URLEncoder.encode(datastore.getSummary().getName(), StandardCharsets.UTF_8.name()));
                    } catch (UnsupportedEncodingException e) {
                        logger.warn("Unsupported encoding '{}'", e.getMessage());
                    }
                }
            }
        } catch (RemoteException e) {
            logger.warn("Cannot retrieve datastores for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
        }
        try {
            if (request.isTopologyNetworks()) {
                for (Network network : hostSystem.getNetworks()) {
                    if (vmwareTopologyInfo.length() > 0) {
                        vmwareTopologyInfo.append(", ");
                    }
                    try {
                        if (network instanceof DistributedVirtualPortgroup ? request.isTopologyPortGroups() : true) {
                            vmwareTopologyInfo.append(network.getMOR().getVal() + "/" + URLEncoder.encode(network.getSummary().getName(), StandardCharsets.UTF_8.name()));
                        }
                    } catch (UnsupportedEncodingException e) {
                        logger.warn("Unsupported encoding '{}'", e.getMessage());
                    }
                }
            }
        } catch (RemoteException e) {
            logger.warn("Cannot retrieve networks for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
        }
    } else {
        if (managedEntity instanceof VirtualMachine) {
            VirtualMachine virtualMachine = (VirtualMachine) managedEntity;
            VirtualMachineRuntimeInfo virtualMachineRuntimeInfo = virtualMachine.getRuntime();
            if (virtualMachineRuntimeInfo == null) {
                logger.debug("virtualMachineRuntimeInfo=null");
            } else {
                VirtualMachinePowerState virtualMachinePowerState = virtualMachineRuntimeInfo.getPowerState();
                if (virtualMachinePowerState == null) {
                    logger.debug("virtualMachinePowerState=null");
                } else {
                    powerState = virtualMachinePowerState.toString();
                }
            }
            try {
                if (request.isTopologyDatastores()) {
                    for (Datastore datastore : virtualMachine.getDatastores()) {
                        if (vmwareTopologyInfo.length() > 0) {
                            vmwareTopologyInfo.append(", ");
                        }
                        try {
                            vmwareTopologyInfo.append(datastore.getMOR().getVal() + "/" + URLEncoder.encode(datastore.getSummary().getName(), StandardCharsets.UTF_8.name()));
                        } catch (UnsupportedEncodingException e) {
                            logger.warn("Unsupported encoding '{}'", e.getMessage());
                        }
                    }
                }
            } catch (RemoteException e) {
                logger.warn("Cannot retrieve datastores for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
            }
            try {
                if (request.isTopologyNetworks()) {
                    for (Network network : virtualMachine.getNetworks()) {
                        if (vmwareTopologyInfo.length() > 0) {
                            vmwareTopologyInfo.append(", ");
                        }
                        try {
                            if (network instanceof DistributedVirtualPortgroup ? request.isTopologyPortGroups() : true) {
                                vmwareTopologyInfo.append(network.getMOR().getVal() + "/" + URLEncoder.encode(network.getSummary().getName(), StandardCharsets.UTF_8.name()));
                            }
                        } catch (UnsupportedEncodingException e) {
                            logger.warn("Unsupported encoding '{}'", e.getMessage());
                        }
                    }
                }
            } catch (RemoteException e) {
                logger.warn("Cannot retrieve networks for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
            }
            if (vmwareTopologyInfo.length() > 0) {
                vmwareTopologyInfo.append(", ");
            }
            try {
                if (m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()) != null) {
                    vmwareTopologyInfo.append(virtualMachine.getRuntime().getHost().getVal() + "/" + URLEncoder.encode(m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()), StandardCharsets.UTF_8.name()));
                } else {
                    logger.warn("Problem building topology information for virtual machine '{}' with power state '{}' running on host system '{}'", virtualMachine.getMOR().getVal(), powerState, virtualMachine.getRuntime().getHost().getVal());
                }
            } catch (UnsupportedEncodingException e) {
                logger.warn("Unsupported encoding '{}'", e.getMessage());
            }
        } else {
            logger.error("Undefined type of managedEntity '{}'", managedEntity.getMOR().getType());
            return null;
        }
    }
    RequisitionAsset requisitionAssetHostname = new RequisitionAsset("vmwareManagementServer", request.getHostname());
    requisitionNode.putAsset(requisitionAssetHostname);
    RequisitionAsset requisitionAssetType = new RequisitionAsset("vmwareManagedEntityType", (managedEntity instanceof HostSystem ? "HostSystem" : "VirtualMachine"));
    requisitionNode.putAsset(requisitionAssetType);
    RequisitionAsset requisitionAssetId = new RequisitionAsset("vmwareManagedObjectId", managedEntity.getMOR().getVal());
    requisitionNode.putAsset(requisitionAssetId);
    RequisitionAsset requisitionAssetTopologyInfo = new RequisitionAsset("vmwareTopologyInfo", vmwareTopologyInfo.toString());
    requisitionNode.putAsset(requisitionAssetTopologyInfo);
    RequisitionAsset requisitionAssetState = new RequisitionAsset("vmwareState", powerState);
    requisitionNode.putAsset(requisitionAssetState);
    requisitionNode.putCategory(new RequisitionCategory("VMware" + apiVersion));
    return requisitionNode;
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) HostRuntimeInfo(com.vmware.vim25.HostRuntimeInfo) UnknownHostException(java.net.UnknownHostException) VirtualMachineRuntimeInfo(com.vmware.vim25.VirtualMachineRuntimeInfo) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService) HostSystemPowerState(com.vmware.vim25.HostSystemPowerState) RequisitionAsset(org.opennms.netmgt.provision.persist.requisition.RequisitionAsset) DistributedVirtualPortgroup(com.vmware.vim25.mo.DistributedVirtualPortgroup) VirtualMachinePowerState(com.vmware.vim25.VirtualMachinePowerState) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) Datastore(com.vmware.vim25.mo.Datastore) Network(com.vmware.vim25.mo.Network) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) HostSystem(com.vmware.vim25.mo.HostSystem) RemoteException(java.rmi.RemoteException) InetAddress(java.net.InetAddress) VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Example 5 with RequisitionMonitoredService

use of org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService in project opennms by OpenNMS.

the class CsvRequisitionParser method createOrUpdateRequistion.

private static void createOrUpdateRequistion(RequisitionData rd) throws UnknownHostException {
    Requisition r = null;
    RequisitionNode rn = new RequisitionNode();
    String foreignSource = rd.getForeignSource();
    r = m_fsr.getRequisition(foreignSource);
    if (r == null) {
        r = new Requisition(foreignSource);
    }
    System.err.println("Creating/Updating requistion: " + foreignSource);
    r.updateDateStamp();
    RequisitionMonitoredServiceCollection services = new RequisitionMonitoredServiceCollection();
    for (String svc : m_serviceList) {
        services.add(new RequisitionMonitoredService(svc));
    }
    RequisitionInterface iface = new RequisitionInterface();
    iface.setDescr("mgmt-if");
    iface.setIpAddr(rd.getPrimaryIp());
    iface.setManaged(true);
    iface.setSnmpPrimary(PrimaryType.PRIMARY);
    iface.setStatus(Integer.valueOf(1));
    iface.setMonitoredServices(services.getObjects());
    RequisitionInterfaceCollection ric = new RequisitionInterfaceCollection();
    ric.add(iface);
    //add categories requisition level categories
    RequisitionCategoryCollection rcc = new RequisitionCategoryCollection();
    if (m_categoryList != null && m_categoryList.size() > 0) {
        for (String cat : m_categoryList) {
            rcc.add(new RequisitionCategory(cat));
        }
    }
    //add categories already on the node to the requisition
    if (rd.getCategories() != null) {
        for (String cat : rd.getCategories()) {
            rcc.add(new RequisitionCategory(cat));
        }
    }
    rn.setBuilding(foreignSource);
    if (rcc.size() >= 1) {
        rn.setCategories(rcc.getObjects());
    }
    rn.setForeignId(rd.getForeignId());
    rn.setInterfaces(ric.getObjects());
    String nodeLabel = rd.getNodeLabel();
    if (m_resolveIps) {
        InetAddress addr = InetAddress.getByName(rd.getPrimaryIp());
        nodeLabel = addr.getCanonicalHostName();
    }
    rn.setNodeLabel(nodeLabel);
    //r.insertNode(rn);
    r.putNode(rn);
    m_fsr.save(r);
}
Also used : RequisitionCategoryCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionCategoryCollection) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) RequisitionMonitoredServiceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredServiceCollection) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) InetAddress(java.net.InetAddress) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) RequisitionMonitoredService(org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)

Aggregations

RequisitionInterface (org.opennms.netmgt.provision.persist.requisition.RequisitionInterface)6 RequisitionMonitoredService (org.opennms.netmgt.provision.persist.requisition.RequisitionMonitoredService)6 RequisitionNode (org.opennms.netmgt.provision.persist.requisition.RequisitionNode)6 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)3 RequisitionCategory (org.opennms.netmgt.provision.persist.requisition.RequisitionCategory)3 InetAddress (java.net.InetAddress)2 RequisitionAsset (org.opennms.netmgt.provision.persist.requisition.RequisitionAsset)2 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)1 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)1 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)1 VirtualMachinePowerState (com.vmware.vim25.VirtualMachinePowerState)1 VirtualMachineRuntimeInfo (com.vmware.vim25.VirtualMachineRuntimeInfo)1 Datastore (com.vmware.vim25.mo.Datastore)1 DistributedVirtualPortgroup (com.vmware.vim25.mo.DistributedVirtualPortgroup)1 HostSystem (com.vmware.vim25.mo.HostSystem)1 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)1 Network (com.vmware.vim25.mo.Network)1 VirtualMachine (com.vmware.vim25.mo.VirtualMachine)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1