Search in sources :

Example 46 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class SnmpHardwareInventoryProvisioningAdapter method synchronizeInventory.

/**
 * Synchronize inventory.
 * <p>Obtain the ENTITY-MIB and vendor attributes from the target node through SNMP.</p>
 * <p>If the node has a hardware inventory data on the database, this is going to be overridden only,
 * if the gathered data differs from the data at the database, otherwise the gathered data will be
 * discarded.</p>
 *
 * @param nodeId the node id
 */
private void synchronizeInventory(int nodeId) {
    final OnmsNode node = m_nodeDao.get(nodeId);
    if (node == null) {
        throw new ProvisioningAdapterException("Failed to return node for given nodeId: " + nodeId);
    }
    final OnmsIpInterface intf = node.getPrimaryInterface();
    if (intf == null) {
        throw new ProvisioningAdapterException("Can't find the SNMP Primary IP address for nodeId: " + nodeId);
    }
    final InetAddress ipAddress = intf.getIpAddress();
    EventBuilder ebldr = null;
    try {
        if (node.getSysObjectId() == null) {
            LOG.warn("Skiping hardware discover because the node {} doesn't support SNMP", nodeId);
            return;
        }
        OnmsMonitoringLocation location = node.getLocation();
        String locationName = (location == null) ? null : location.getLocationName();
        SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipAddress, locationName);
        final OnmsHwEntity newRoot = getRootEntity(agentConfig, node);
        newRoot.setNode(node);
        final OnmsHwEntity currentRoot = m_hwEntityDao.findRootByNodeId(node.getId());
        if (newRoot.equals(currentRoot)) {
            LOG.info("No changes detected on the hardware inventory for nodeId {}", nodeId);
            return;
        }
        if (currentRoot == null) {
            LOG.info("Saving hardware inventory for nodeId {}", nodeId);
        } else {
            LOG.info("Updating hardware inventory for nodeId {}", nodeId);
            m_hwEntityDao.delete(currentRoot);
            m_hwEntityDao.flush();
        }
        m_hwEntityDao.saveOrUpdate(newRoot);
        ebldr = new EventBuilder(EventConstants.HARDWARE_INVENTORY_SUCCESSFUL_UEI, PREFIX + NAME);
    } catch (Throwable e) {
        ebldr = new EventBuilder(EventConstants.HARDWARE_INVENTORY_FAILED_UEI, PREFIX + NAME);
        ebldr.addParam(EventConstants.PARM_REASON, e.getMessage());
    }
    if (ebldr != null) {
        ebldr.setNodeid(nodeId);
        ebldr.setInterface(ipAddress);
        getEventForwarder().sendNow(ebldr.getEvent());
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsHwEntity(org.opennms.netmgt.model.OnmsHwEntity) OnmsNode(org.opennms.netmgt.model.OnmsNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) InetAddress(java.net.InetAddress) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 47 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class DefaultProvisionService method createUndiscoveredNode.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public OnmsNode createUndiscoveredNode(final String ipAddress, final String foreignSource, final String locationString) {
    final String effectiveForeignSource = foreignSource == null ? FOREIGN_SOURCE_FOR_DISCOVERED_NODES : foreignSource;
    final String effectiveLocationName = MonitoringLocationUtils.isDefaultLocationName(locationString) ? null : locationString;
    final OnmsNode node = new UpsertTemplate<OnmsNode, NodeDao>(m_transactionManager, m_nodeDao) {

        @Override
        protected OnmsNode query() {
            // Find all of the nodes in the target requisition with the given IP address
            return m_nodeDao.findByForeignSourceAndIpAddress(effectiveForeignSource, ipAddress).stream().filter(n -> {
                // Now filter the nodes by location
                final String existingLocationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(n);
                return Objects.equals(existingLocationName, effectiveLocationName);
            }).findFirst().orElse(null);
        }

        @Override
        protected OnmsNode doUpdate(OnmsNode existingNode) {
            // we found an existing node so exit by returning null;
            return null;
        }

        @Override
        protected OnmsNode doInsert() {
            final Date now = new Date();
            OnmsMonitoringLocation location = createLocationIfNecessary(locationString);
            // Associate the location with the node
            final OnmsNode node = new OnmsNode(location);
            final String hostname = getHostnameResolver().getHostname(addr(ipAddress), locationString);
            if (hostname == null || ipAddress.equals(hostname)) {
                node.setLabel(ipAddress);
                node.setLabelSource(NodeLabelSource.ADDRESS);
            } else {
                node.setLabel(hostname);
                node.setLabelSource(NodeLabelSource.HOSTNAME);
            }
            node.setForeignSource(effectiveForeignSource);
            node.setType(NodeType.ACTIVE);
            node.setLastCapsdPoll(now);
            final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr(ipAddress), node);
            iface.setIsManaged("M");
            iface.setIpHostName(hostname);
            iface.setIsSnmpPrimary(PrimaryType.NOT_ELIGIBLE);
            iface.setIpLastCapsdPoll(now);
            m_nodeDao.save(node);
            m_nodeDao.flush();
            return node;
        }
    }.execute();
    if (node != null) {
        if (effectiveForeignSource != null) {
            node.setForeignId(node.getNodeId());
            createUpdateRequistion(ipAddress, node, effectiveLocationName, effectiveForeignSource);
        }
        // we do this here rather than in the doInsert method because
        // the doInsert may abort
        node.visit(new AddEventVisitor(m_eventForwarder));
    }
    return node;
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) NodeType(org.opennms.netmgt.model.OnmsNode.NodeType) OnmsNodeRequisition(org.opennms.netmgt.provision.persist.OnmsNodeRequisition) AbstractEntityVisitor(org.opennms.netmgt.model.AbstractEntityVisitor) Date(java.util.Date) MonitoringLocationUtils(org.opennms.netmgt.dao.api.MonitoringLocationUtils) UpsertTemplate(org.opennms.netmgt.dao.support.UpsertTemplate) LocationAwareDnsLookupClient(org.opennms.netmgt.provision.LocationAwareDnsLookupClient) InetAddressUtils.str(org.opennms.core.utils.InetAddressUtils.str) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventUtils(org.opennms.netmgt.model.events.EventUtils) InetAddressUtils.addr(org.opennms.core.utils.InetAddressUtils.addr) IpInterfacePolicy(org.opennms.netmgt.provision.IpInterfacePolicy) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) InetAddress(java.net.InetAddress) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) NodeLabelSource(org.opennms.netmgt.model.OnmsNode.NodeLabelSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Map(java.util.Map) Resource(org.springframework.core.io.Resource) IpInterfaceDao(org.opennms.netmgt.dao.api.IpInterfaceDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) InetAddressUtils(org.opennms.core.utils.InetAddressUtils) Collection(java.util.Collection) UpdateEventVisitor(org.opennms.netmgt.model.events.UpdateEventVisitor) Set(java.util.Set) CreateIfNecessaryTemplate(org.opennms.netmgt.dao.support.CreateIfNecessaryTemplate) AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) BeanUtils(org.opennms.core.spring.BeanUtils) Objects(java.util.Objects) List(java.util.List) RequisitionCategory(org.opennms.netmgt.provision.persist.requisition.RequisitionCategory) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) PathElement(org.opennms.netmgt.model.PathElement) LocationAwareSnmpClient(org.opennms.netmgt.snmp.proxy.LocationAwareSnmpClient) RequisitionedCategoryAssociation(org.opennms.netmgt.model.RequisitionedCategoryAssociation) DeleteEventVisitor(org.opennms.netmgt.model.events.DeleteEventVisitor) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) NodePolicy(org.opennms.netmgt.provision.NodePolicy) Duration(org.joda.time.Duration) EntityVisitor(org.opennms.netmgt.model.EntityVisitor) HashMap(java.util.HashMap) EventConstants(org.opennms.netmgt.events.api.EventConstants) RequisitionedCategoryAssociationDao(org.opennms.netmgt.dao.api.RequisitionedCategoryAssociationDao) RequisitionInterface(org.opennms.netmgt.provision.persist.requisition.RequisitionInterface) TreeSet(java.util.TreeSet) InitializingBean(org.springframework.beans.factory.InitializingBean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) PrimaryType(org.opennms.netmgt.model.PrimaryType) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ServiceTypeDao(org.opennms.netmgt.dao.api.ServiceTypeDao) ForeignSourceRepository(org.opennms.netmgt.provision.persist.ForeignSourceRepository) PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsNode(org.opennms.netmgt.model.OnmsNode) RequisitionFileUtils(org.opennms.netmgt.provision.persist.RequisitionFileUtils) CategoryDao(org.opennms.netmgt.dao.api.CategoryDao) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) DateTime(org.joda.time.DateTime) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) LocationAwareDetectorClient(org.opennms.netmgt.provision.LocationAwareDetectorClient) MonitoringLocationDao(org.opennms.netmgt.dao.api.MonitoringLocationDao) EventForwarder(org.opennms.netmgt.events.api.EventForwarder) RequisitionInterfaceCollection(org.opennms.netmgt.provision.persist.requisition.RequisitionInterfaceCollection) Collections(java.util.Collections) ForeignSourceRepositoryException(org.opennms.netmgt.provision.persist.ForeignSourceRepositoryException) SnmpInterfacePolicy(org.opennms.netmgt.provision.SnmpInterfacePolicy) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) AddEventVisitor(org.opennms.netmgt.model.events.AddEventVisitor) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Date(java.util.Date) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class EnLinkdIT method testLoadFourLevelTopology.

/*
     * 1400=
     *      [1544, 1534]
     *             1534=
     *                   [1364, 405, 1310]}
     *                    1364=
     *                          [2965, 5022]
     */
@Test
public void testLoadFourLevelTopology() {
    final OnmsMonitoringLocation location = new OnmsMonitoringLocation(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
    OnmsNode lnode1400 = new OnmsNode();
    lnode1400.setId(1400);
    lnode1400.setForeignSource("linkd");
    lnode1400.setForeignId("lnode1400");
    lnode1400.setLabel("lnode1400");
    lnode1400.setLocation(location);
    OnmsNode lnode1544 = new OnmsNode();
    lnode1544.setId(1544);
    lnode1544.setForeignSource("linkd");
    lnode1544.setForeignId("lnode1544");
    lnode1544.setLabel("lnode1544");
    lnode1544.setLocation(location);
    OnmsNode lnode1534 = new OnmsNode();
    lnode1534.setId(1534);
    lnode1534.setForeignSource("linkd");
    lnode1534.setForeignId("lnode1534");
    lnode1534.setLabel("lnode1534");
    lnode1534.setLocation(location);
    OnmsNode lnode1364 = new OnmsNode();
    lnode1364.setId(1364);
    lnode1364.setForeignSource("linkd");
    lnode1364.setForeignId("lnode1364");
    lnode1364.setLabel("lnode1364");
    lnode1364.setLocation(location);
    OnmsNode lnode1310 = new OnmsNode();
    lnode1310.setId(1310);
    lnode1310.setForeignSource("linkd");
    lnode1310.setForeignId("lnode1310");
    lnode1310.setLabel("lnode1310");
    lnode1310.setLocation(location);
    OnmsNode lnode405 = new OnmsNode();
    lnode405.setId(405);
    lnode405.setForeignSource("linkd");
    lnode405.setForeignId("lnode405");
    lnode405.setLabel("lnode405");
    lnode405.setLocation(location);
    OnmsNode lnode2965 = new OnmsNode();
    lnode2965.setId(2965);
    lnode2965.setForeignSource("linkd");
    lnode2965.setForeignId("lnode2965");
    lnode2965.setLabel("lnode2965");
    lnode2965.setLocation(location);
    OnmsNode lnode5022 = new OnmsNode();
    lnode5022.setId(5022);
    lnode5022.setForeignSource("linkd");
    lnode5022.setForeignId("lnode5022");
    lnode5022.setLabel("lnode5022");
    lnode5022.setLocation(location);
    m_nodeDao.save(lnode1400);
    m_nodeDao.save(lnode1544);
    m_nodeDao.save(lnode1534);
    m_nodeDao.save(lnode1364);
    m_nodeDao.save(lnode1310);
    m_nodeDao.save(lnode405);
    m_nodeDao.save(lnode2965);
    m_nodeDao.save(lnode5022);
    OnmsNode node1400 = m_nodeDao.findByForeignId("linkd", "lnode1400");
    OnmsNode node1544 = m_nodeDao.findByForeignId("linkd", "lnode1544");
    OnmsNode node1534 = m_nodeDao.findByForeignId("linkd", "lnode1534");
    OnmsNode node1364 = m_nodeDao.findByForeignId("linkd", "lnode1364");
    OnmsNode node1310 = m_nodeDao.findByForeignId("linkd", "lnode1310");
    OnmsNode node405 = m_nodeDao.findByForeignId("linkd", "lnode405");
    OnmsNode node2965 = m_nodeDao.findByForeignId("linkd", "lnode2965");
    OnmsNode node5022 = m_nodeDao.findByForeignId("linkd", "lnode5022");
    BridgeBridgeLink link7 = new BridgeBridgeLink();
    link7.setNode(node5022);
    link7.setBridgePort(4);
    link7.setDesignatedNode(node2965);
    link7.setDesignatedPort(5);
    link7.setBridgeBridgeLinkLastPollTime(link7.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link7);
    m_bridgeBridgeLinkDao.flush();
    BridgeBridgeLink link1 = new BridgeBridgeLink();
    link1.setNode(node1544);
    link1.setBridgePort(15);
    link1.setDesignatedNode(node1400);
    link1.setDesignatedPort(1);
    link1.setBridgeBridgeLinkLastPollTime(link1.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link1);
    m_bridgeBridgeLinkDao.flush();
    BridgeBridgeLink link3 = new BridgeBridgeLink();
    link3.setNode(node1310);
    link3.setBridgePort(1);
    link3.setDesignatedNode(node1534);
    link3.setDesignatedPort(1);
    link3.setBridgeBridgeLinkLastPollTime(link3.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link3);
    m_bridgeBridgeLinkDao.flush();
    BridgeBridgeLink link4 = new BridgeBridgeLink();
    link4.setNode(node1364);
    link4.setBridgePort(24);
    link4.setDesignatedNode(node1534);
    link4.setDesignatedPort(4);
    link4.setBridgeBridgeLinkLastPollTime(link4.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link4);
    m_bridgeBridgeLinkDao.flush();
    BridgeBridgeLink link2 = new BridgeBridgeLink();
    link2.setNode(node1534);
    link2.setBridgePort(11);
    link2.setDesignatedNode(node1400);
    link2.setDesignatedPort(11);
    link2.setBridgeBridgeLinkLastPollTime(link2.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link2);
    m_bridgeBridgeLinkDao.flush();
    BridgeBridgeLink link6 = new BridgeBridgeLink();
    link6.setNode(node2965);
    link6.setBridgePort(2);
    link6.setDesignatedNode(node1364);
    link6.setDesignatedPort(5);
    link6.setBridgeBridgeLinkLastPollTime(link6.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link6);
    m_bridgeBridgeLinkDao.flush();
    BridgeBridgeLink link5 = new BridgeBridgeLink();
    link5.setNode(node405);
    link5.setBridgePort(1);
    link5.setDesignatedNode(node1534);
    link5.setDesignatedPort(1);
    link5.setBridgeBridgeLinkLastPollTime(link5.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(link5);
    m_bridgeBridgeLinkDao.flush();
    assertEquals(0, m_bridgeMacLinkDao.countAll());
    assertEquals(7, m_bridgeBridgeLinkDao.countAll());
    assertNotNull(m_bridgeTopologyDao);
    m_linkd.getQueryManager().loadBridgeTopology();
    assertEquals(1, m_linkd.getQueryManager().getAllBroadcastDomains().size());
    BroadcastDomain fourlevelDomain = m_linkd.getQueryManager().getAllBroadcastDomains().iterator().next();
    assertEquals(8, fourlevelDomain.getBridgeNodesOnDomain().size());
    System.err.println(fourlevelDomain.printTopology());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Test(org.junit.Test)

Example 49 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class AgentConfigurationResource method getResponses.

protected List<AgentResponse> getResponses(final String filterName, final String serviceName) throws ConfigurationResourceException {
    LOG.debug("getAgentsForService(): filterName={}, serviceName={}", filterName, serviceName);
    if (filterName == null || serviceName == null) {
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("You must specify a filter name and service name!").build());
    }
    final Filter filter = m_collectdConfigurationResource.get().getFilter(filterName);
    if (filter == null) {
        LOG.warn("No filter matching {} could be found.", filterName);
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    final List<InetAddress> addresses = m_filterDao.getActiveIPAddressList(filter.getContent());
    LOG.debug("Matched {} IP addresses for filter {}", addresses == null ? 0 : addresses.size(), filterName);
    if (addresses == null || addresses.size() == 0) {
        return Collections.emptyList();
    }
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsMonitoredService.class);
    builder.createAlias("ipInterface", "iface");
    builder.createAlias("serviceType", "type");
    builder.createAlias("iface.node", "node");
    builder.in("iface.ipAddress", addresses);
    builder.eq("type.name", serviceName);
    final List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(builder.toCriteria());
    int defaultPort = -1;
    // TODO: We shouldn't have to hardcode like this; what's the right way to know the port to return?
    final CollectdConfiguration collectdConfiguration = m_collectdConfigurationResource.get();
    org.opennms.netmgt.config.collectd.Package pack = collectdConfiguration.getPackage(filterName);
    if (pack == null) {
        for (final org.opennms.netmgt.config.collectd.Package p : collectdConfiguration.getPackages()) {
            if (filterName.equals(p.getFilter().getName())) {
                pack = p;
                break;
            }
        }
    }
    if (pack != null) {
        final Service svc = pack.getService(serviceName);
        final String port = svc.getParameter("port");
        if (port != null) {
            try {
                defaultPort = Integer.valueOf(port);
            } catch (final NumberFormatException e) {
                LOG.debug("Unable to turn port {} from service {} into a number.", port, serviceName);
            }
        }
    }
    final List<AgentResponse> responses = new ArrayList<>();
    for (final OnmsMonitoredService service : services) {
        final InetAddress ipAddress = service.getIpAddress();
        final OnmsIpInterface iface = service.getIpInterface();
        OnmsNode node = null;
        if (iface != null) {
            node = iface.getNode();
        }
        final Map<String, String> parameters = new TreeMap<String, String>();
        // all service parameters from collectd configuration to parameters map
        for (Parameter eachParameter : pack.getService(serviceName).getParameters()) {
            parameters.put(eachParameter.getKey(), eachParameter.getValue());
        }
        int port = defaultPort;
        if ("SNMP".equals(serviceName)) {
            final String sysObjectId = node == null ? null : node.getSysObjectId();
            if (sysObjectId != null) {
                parameters.put("sysObjectId", sysObjectId);
            }
            OnmsMonitoringLocation location = (node == null) ? null : node.getLocation();
            String locationName = (location == null) ? null : location.getLocationName();
            final SnmpAgentConfig config = m_agentConfigFactory.getAgentConfig(ipAddress, locationName);
            if (config != null) {
                port = config.getPort();
            }
        }
        if (node != null) {
            if (node.getNodeId() != null && !node.getNodeId().trim().isEmpty()) {
                parameters.put("nodeId", node.getNodeId());
            }
            if (node.getForeignSource() != null && !node.getForeignSource().trim().isEmpty()) {
                parameters.put("foreignSource", node.getForeignSource());
            }
            if (node.getForeignId() != null && !node.getForeignId().trim().isEmpty()) {
                parameters.put("foreignId", node.getForeignId());
            }
        }
        responses.add(new AgentResponse(ipAddress, port, service.getServiceName(), parameters));
    }
    return responses;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) AgentResponse(org.opennms.netmgt.config.agents.AgentResponse) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsNode(org.opennms.netmgt.model.OnmsNode) Service(org.opennms.netmgt.config.collectd.Service) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) TreeMap(java.util.TreeMap) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Filter(org.opennms.netmgt.config.collectd.Filter) Parameter(org.opennms.netmgt.config.collectd.Parameter) InetAddress(java.net.InetAddress) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 50 with OnmsMonitoringLocation

use of org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation in project opennms by OpenNMS.

the class NodeRestService method doCreate.

@Override
public Response doCreate(final SecurityContext securityContext, final UriInfo uriInfo, final OnmsNode object) {
    if (object == null) {
        throw getException(Status.BAD_REQUEST, "Node object cannot be null");
    }
    if (object.getLocation() == null) {
        OnmsMonitoringLocation location = m_locationDao.getDefaultLocation();
        LOG.debug("doCreate: Assigning new node to default location: {}", location.getLocationName());
        object.setLocation(location);
    }
    // See NMS-9855
    if (object.getAssetRecord() != null && object.getAssetRecord().getNode() == null) {
        object.getAssetRecord().setNode(object);
    }
    final Integer id = getDao().save(object);
    final Event e = EventUtils.createNodeAddedEvent("Rest", id, object.getLabel(), object.getLabelSource());
    sendEvent(e);
    return Response.created(RedirectHelper.getRedirectUri(uriInfo, id)).build();
}
Also used : Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)58 OnmsNode (org.opennms.netmgt.model.OnmsNode)19 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)18 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)13 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)12 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)10 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 Test (org.junit.Test)8 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)8 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)7 HashSet (java.util.HashSet)5 Before (org.junit.Before)5 InetAddress (java.net.InetAddress)4 HashMap (java.util.HashMap)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)4 LinkedHashMap (java.util.LinkedHashMap)3