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;
}
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;
}
}
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());
}
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;
}
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();
}
Aggregations