Search in sources :

Example 1 with EqRestriction

use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private LldpLinkNode convertFromModel(int nodeid, LldpLink link) {
    LldpLinkNode linknode = new LldpLinkNode();
    linknode.setLldpPortString(getPortString(link.getLldpPortId(), link.getLldpPortIdSubType()));
    linknode.setLldpPortDescr(link.getLldpPortDescr());
    linknode.setLldpPortUrl(getSnmpInterfaceUrl(Integer.valueOf(nodeid), link.getLldpPortIfindex()));
    linknode.setLldpRemSysName(link.getLldpRemSysname());
    linknode.setLldpRemPortString(getPortString(link.getLldpRemPortId(), link.getLldpRemPortIdSubType()));
    linknode.setLldpRemPortDescr(link.getLldpRemPortDescr());
    linknode.setLldpCreateTime(Util.formatDateToUIString(link.getLldpLinkCreateTime()));
    linknode.setLldpLastPollTime(Util.formatDateToUIString(link.getLldpLinkLastPollTime()));
    OnmsNode remNode = null;
    List<LldpElement> lldpremelements = m_lldpElementDao.findByChassisId(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType());
    if (lldpremelements.size() == 1) {
        remNode = lldpremelements.get(0).getNode();
    } else if (lldpremelements.size() > 1) {
        linknode.setLldpRemChassisIdString(getChassisIdString("Found " + lldpremelements.size() + " nodes for", link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        return linknode;
    } else {
        final Criteria criteria = new Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", link.getLldpRemSysname()));
        List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
        if (nodes.size() == 1)
            remNode = nodes.get(0);
    }
    if (remNode != null) {
        linknode.setLldpRemChassisIdString(getChassisIdString(remNode.getLabel(), link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        linknode.setLldpRemChassisIdUrl(getNodeUrl(remNode.getId()));
        if (link.getLldpRemPortIdSubType() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL) {
            try {
                Integer remIfIndex = Integer.getInteger(link.getLldpRemPortId());
                linknode.setLldpRemPortUrl(getSnmpInterfaceUrl(Integer.valueOf(remNode.getId()), remIfIndex));
            } catch (Exception e) {
            }
        }
    } else {
        linknode.setLldpRemChassisIdString(getChassisIdString(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
    }
    return linknode;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) List(java.util.List) ArrayList(java.util.ArrayList) LldpElement(org.opennms.netmgt.model.LldpElement) Criteria(org.opennms.core.criteria.Criteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EqRestriction

use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.

the class NetworkElementFactory method getIpPrimaryAddress.

/* (non-Javadoc)
	 * @see org.opennms.web.element.NetworkElementFactoryInterface#getIpPrimaryAddress(int)
	 */
@Override
public String getIpPrimaryAddress(int nodeId) {
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsIpInterface.class);
    cb.and(new EqRestriction("node.id", nodeId), new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
    final List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(cb.toCriteria());
    if (ifaces.size() > 0) {
        final OnmsIpInterface iface = ifaces.get(0);
        return InetAddressUtils.str(iface.getIpAddress());
    } else {
        return null;
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction)

Example 3 with EqRestriction

use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.

the class AlarmLifecycleEventsIT method canGenerateAlarmDeletedLifecycleEvents.

@Test
public void canGenerateAlarmDeletedLifecycleEvents() {
    // Expect an alarmCreated event
    m_eventMgr.getEventAnticipator().resetAnticipated();
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CREATED_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
    // Send a nodeDown
    sendNodeDownEvent(1);
    // Wait until we've received the alarmCreated event
    await().until(allAnticipatedEventsWereReceived());
    // Expect an alarmCreated and a alarmCleared event
    m_eventMgr.getEventAnticipator().resetAnticipated();
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CREATED_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CLEARED_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
    // Send a nodeUp
    sendNodeUpEvent(1);
    // Wait until we've received the alarmCreated and alarmCleared events
    // We need to wait for the cosmicClear automation, which currently runs every 30 seconds
    await().atMost(1, MINUTES).until(allAnticipatedEventsWereReceived());
    // Expect an alarmDeleted event
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_DELETED_EVENT_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
    // We need to wait for the cleanUp automation, which currently runs every 60 seconds
    // but it will only trigger then 'lastautomationtime' and 'lasteventtime' < "5 minutes ago"
    // so we cheat a little and update the timestamps ourselves instead of waiting
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            Criteria criteria = new Criteria(OnmsAlarm.class);
            criteria.addRestriction(new EqRestriction("node.id", 1));
            criteria.addRestriction(new EqRestriction("uei", EventConstants.NODE_DOWN_EVENT_UEI));
            for (OnmsAlarm alarm : m_alarmDao.findMatching(criteria)) {
                LocalDateTime tenMinutesAgo = LocalDateTime.now().minusMinutes(10);
                Date then = Date.from(tenMinutesAgo.toInstant(ZoneOffset.UTC));
                alarm.setLastAutomationTime(then);
                alarm.setLastEventTime(then);
                m_alarmDao.save(alarm);
            }
            m_alarmDao.flush();
        }
    });
    // Wait until we've received the alarmDeleted event
    await().atMost(2, MINUTES).until(allAnticipatedEventsWereReceived());
}
Also used : LocalDateTime(java.time.LocalDateTime) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) TransactionStatus(org.springframework.transaction.TransactionStatus) Criteria(org.opennms.core.criteria.Criteria) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Date(java.util.Date) Test(org.junit.Test)

Example 4 with EqRestriction

use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.

the class DefaultPollingContext method getInterfaceList.

protected OnmsIpInterfaceList getInterfaceList() {
    StringBuffer filterRules = new StringBuffer(getPackage().getEffectiveFilter());
    List<InetAddress> ipList = FilterDaoFactory.getInstance().getActiveIPAddressList(filterRules.toString());
    OnmsIpInterfaceList ifaces = new OnmsIpInterfaceList();
    // Only poll the primary interface
    final Criteria criteria = new Criteria(OnmsIpInterface.class);
    criteria.addRestriction(new EqRestriction("isSnmpPrimary", PrimaryType.PRIMARY));
    List<OnmsIpInterface> allValidIfaces = getIpInterfaceDao().findMatching(criteria);
    for (OnmsIpInterface iface : allValidIfaces) {
        if (ipList.contains(iface.getIpAddress())) {
            ifaces.add(iface);
        }
    }
    return ifaces;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) InetAddress(java.net.InetAddress) OnmsIpInterfaceList(org.opennms.netmgt.model.OnmsIpInterfaceList)

Example 5 with EqRestriction

use of org.opennms.core.criteria.restrictions.EqRestriction in project opennms by OpenNMS.

the class DefaultPollingContext method getNodeIpAddress.

/*
     * Return the IP address of the first interface on the node
     */
protected InetAddress getNodeIpAddress(OnmsNode node) {
    final Criteria criteria = new Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", node.getId()));
    List<OnmsIpInterface> matchingIfaces = getIpInterfaceDao().findMatching(criteria);
    return matchingIfaces.get(0).getIpAddress();
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria)

Aggregations

EqRestriction (org.opennms.core.criteria.restrictions.EqRestriction)23 Criteria (org.opennms.core.criteria.Criteria)16 Alias (org.opennms.core.criteria.Alias)12 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)5 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 NullRestriction (org.opennms.core.criteria.restrictions.NullRestriction)4 Test (org.junit.Test)3 NeRestriction (org.opennms.core.criteria.restrictions.NeRestriction)3 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)3 Transactional (org.springframework.transaction.annotation.Transactional)3 InetAddress (java.net.InetAddress)2 HashSet (java.util.HashSet)2 Criteria (org.opennms.features.topology.api.topo.Criteria)2 LldpElement (org.opennms.netmgt.model.LldpElement)2 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 LocalDateTime (java.time.LocalDateTime)1