use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmRepositoryFilterIT method testParmsNotLikeFilter.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testParmsNotLikeFilter() {
OnmsDistPoller poller = m_dbPopulator.getDistPollerDao().whoami();
assertNotNull(poller);
final OnmsEvent event1 = new OnmsEvent();
event1.setDistPoller(poller);
event1.setEventCreateTime(new Date(1436881548292L));
event1.setEventTime(new Date(1436881548292L));
event1.setEventCreateTime(new Date(1437061537126L));
event1.setEventDescr("This is the description of a test event.");
event1.setEventDisplay("Y");
event1.setEventHost("127.0.0.1");
event1.setEventLog("Y");
event1.setEventLogMsg("Test Event Log Message");
event1.setEventSeverity(1);
event1.setEventSource("test");
event1.setEventTime(new Date(1437061537105L));
event1.setEventUei("uei.opennms.org/test");
event1.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
event1.setNode(m_dbPopulator.getNode1());
event1.setServiceType(m_dbPopulator.getServiceTypeDao().findByName("ICMP"));
event1.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event1, "url", "http://localhost:8980/opennms/rtc/post/Network+Interfaces", "string"), new OnmsEventParameter(event1, "user", "rtc", "string"), new OnmsEventParameter(event1, "passwd", "rtc", "string"), new OnmsEventParameter(event1, "catlabel", "Network Interfaces", "string")));
m_dbPopulator.getEventDao().saveOrUpdate(event1);
m_dbPopulator.getEventDao().flush();
final OnmsEvent event2 = new OnmsEvent();
event2.setDistPoller(poller);
event2.setEventCreateTime(new Date(1436881548292L));
event2.setEventTime(new Date(1436881548292L));
event2.setEventCreateTime(new Date(1437061537126L));
event2.setEventDescr("This is the description of a test event.");
event2.setEventDisplay("Y");
event2.setEventHost("127.0.0.1");
event2.setEventLog("Y");
event2.setEventLogMsg("Test Event Log Message");
event2.setEventSeverity(1);
event2.setEventSource("test");
event2.setEventTime(new Date(1437061537105L));
event2.setEventUei("uei.opennms.org/test");
event2.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
event2.setNode(m_dbPopulator.getNode1());
event2.setServiceType(m_dbPopulator.getServiceTypeDao().findByName("ICMP"));
event2.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event2, "componentType", "serviceElement", "string"), new OnmsEventParameter(event2, "url", "http://localhost:8980/opennms/rtc/post/Network+Interfaces", "string"), new OnmsEventParameter(event2, "user", "rtcbomb", "string"), new OnmsEventParameter(event2, "passwd", "rtc", "string"), new OnmsEventParameter(event2, "catlabel", "Network Interfaces", "string")));
m_dbPopulator.getEventDao().saveOrUpdate(event2);
m_dbPopulator.getEventDao().flush();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp");
alarm.setLastEvent(event1);
alarm.setSeverityId(3);
alarm.setDistPoller(poller);
alarm.setCounter(100);
alarm.setLastEvent(event1);
AlarmDao alarmDao = m_dbPopulator.getAlarmDao();
alarmDao.save(alarm);
alarmDao.flush();
OnmsAlarm alarm2 = new OnmsAlarm();
alarm2.setUei("uei.opennms.org/vendor/Juniper/traps/jnxVpnIfUp");
alarm2.setLastEvent(event2);
alarm2.setSeverityId(3);
alarm2.setDistPoller(poller);
alarm2.setCounter(100);
alarm2.setLastEvent(event2);
alarmDao.save(alarm2);
alarmDao.flush();
NegativeEventParmLikeFilter parmFilter = new NegativeEventParmLikeFilter("user=rtc");
assertEquals("user is not \"rtc\"", parmFilter.getTextDescription());
AlarmCriteria criteria = new AlarmCriteria(parmFilter);
OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(criteria));
// alarm2 and the alarm from DatabasePopulator match this criteria
assertEquals(2, alarms.length);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class DaoWebEventRepository method mapOnmsEventToEvent.
private Event mapOnmsEventToEvent(OnmsEvent onmsEvent) {
LOG.debug("Mapping OnmsEvent to WebEvent for event with database id {}", onmsEvent.getId());
Event event = new Event();
event.acknowledgeTime = onmsEvent.getEventAckTime();
event.acknowledgeUser = onmsEvent.getEventAckUser();
event.alarmId = onmsEvent.getAlarm() != null ? onmsEvent.getAlarm().getId() : 0;
event.autoAction = onmsEvent.getEventAutoAction();
event.createTime = onmsEvent.getEventCreateTime();
event.description = onmsEvent.getEventDescr();
event.dpName = onmsEvent.getDistPoller() != null ? onmsEvent.getDistPoller().getId() : "";
event.eventDisplay = Boolean.valueOf(onmsEvent.getEventDisplay().equals("Y"));
event.forward = onmsEvent.getEventForward();
event.host = onmsEvent.getEventHost();
event.id = onmsEvent.getId();
event.ipAddr = onmsEvent.getIpAddr() == null ? null : InetAddressUtils.toIpAddrString(onmsEvent.getIpAddr());
event.logGroup = onmsEvent.getEventLogGroup();
event.logMessage = onmsEvent.getEventLogMsg();
event.mouseOverText = onmsEvent.getEventMouseOverText();
event.nodeLabel = getNodeLabelFromNode(onmsEvent);
LOG.debug("Found NodeLabel for mapped event:{}", event.getNodeLabel());
event.nodeID = getNodeIdFromNode(onmsEvent);
LOG.debug("Found NodeId for mapped event:{}", event.getNodeId());
event.nodeLocation = getNodeLocationFromNode(onmsEvent);
event.notification = onmsEvent.getEventNotification();
event.operatorAction = onmsEvent.getEventOperAction();
event.operatorActionMenuText = onmsEvent.getEventOperActionMenuText();
event.operatorInstruction = onmsEvent.getEventOperInstruct();
event.parms = onmsEvent.getEventParameters() == null ? Maps.newHashMap() : onmsEvent.getEventParameters().stream().collect(Collectors.toMap(OnmsEventParameter::getName, OnmsEventParameter::getValue));
event.serviceID = onmsEvent.getServiceType() != null ? onmsEvent.getServiceType().getId() : 0;
event.serviceName = onmsEvent.getServiceType() != null ? onmsEvent.getServiceType().getName() : "";
event.severity = OnmsSeverity.get(onmsEvent.getEventSeverity());
event.snmp = onmsEvent.getEventSnmp();
event.snmphost = onmsEvent.getEventSnmpHost();
event.time = onmsEvent.getEventTime();
event.troubleTicket = onmsEvent.getEventTTicket();
event.troubleTicketState = onmsEvent.getEventTTicketState();
event.uei = onmsEvent.getEventUei();
if (onmsEvent.getDistPoller() != null) {
event.location = onmsEvent.getDistPoller().getLocation();
event.systemId = onmsEvent.getDistPoller().getId();
}
return event;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class DaoWebEventRepository method unacknowledgeMatchingEvents.
/**
* {@inheritDoc}
*/
@Transactional
@Override
public void unacknowledgeMatchingEvents(EventCriteria criteria) {
List<OnmsEvent> events = m_eventDao.findMatching(getOnmsCriteria(criteria));
for (OnmsEvent event : events) {
event.setEventAckUser(null);
event.setEventAckTime(null);
m_eventDao.update(event);
}
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class SyslogIT method testNewSuspect.
@Test
public void testNewSuspect() throws Exception {
final Date startOfTest = new Date();
final String sender = testEnvironment.getContainerInfo(ContainerAlias.SNMPD).networkSettings().ipAddress();
// Wait for the minion to show up
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(MinionDaoHibernate.class), new CriteriaBuilder(OnmsMinion.class).gt("lastUpdated", startOfTest).eq("location", "MINION").toCriteria()), is(1));
// Send the initial message
sendMessage(ContainerAlias.MINION, sender, 1);
// Wait for the syslog message
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).toCriteria()), is(1));
// Wait for the new suspect
final OnmsEvent event = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/internal/discovery/newSuspect").ge("eventTime", startOfTest).eq("ipAddr", Inet4Address.getByName(sender)).isNull("node").toCriteria()), notNullValue());
assertThat(event.getDistPoller().getLocation(), is("MINION"));
// Check if the node was detected
final OnmsNode node = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(getDaoFactory().getDao(NodeDaoHibernate.class), new CriteriaBuilder(OnmsNode.class).eq("label", "snmpd").toCriteria()), notNullValue());
assertThat(node.getLocation().getLocationName(), is("MINION"));
// Check if the service was discovered
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(() -> getDaoFactory().getDao(MonitoredServiceDaoHibernate.class).getPrimaryService(node.getId(), "SNMP"), notNullValue());
// Send the second message
sendMessage(ContainerAlias.MINION, sender, 1);
// Wait for the second message with the node assigned
await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(getDaoFactory().getDao(EventDaoHibernate.class), new CriteriaBuilder(OnmsEvent.class).eq("eventUei", "uei.opennms.org/vendor/cisco/syslog/SEC-6-IPACCESSLOGP/aclDeniedIPTraffic").ge("eventCreateTime", startOfTest).eq("node", node).toCriteria()), is(1));
}
Aggregations