use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class SyslogFilterTest method testFilterParsing.
/**
* Test filter parsing.
*
* @throws Exception the exception
*/
@Test
public void testFilterParsing() throws Exception {
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "user", "agalue", "string"), new OnmsEventParameter(event, "passwd", "0nmsRules", "string")));
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setLastEvent(event);
onmsAlarm.setUei("uei.opennms.org/junit/test");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
SyslogFilter filter = new SyslogFilter("test", "uei matches '^uei\\.opennms\\.org.*' and parameters['user'] == 'agalue'", "localhost");
Assert.assertTrue(filter.passFilter(alarm));
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class AlarmRepositoryFilterIT method testParmsLikeFilter.
@Test
@Transactional
@JUnitTemporaryDatabase
public void testParmsLikeFilter() {
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();
EventParmLikeFilter eventParmFilter = new EventParmLikeFilter("user=rtc");
assertEquals("user=\"rtc\"", eventParmFilter.getTextDescription());
AlarmCriteria criteria = new AlarmCriteria(eventParmFilter);
OnmsAlarm[] alarms = m_daoAlarmRepo.getMatchingAlarms(AlarmUtil.getOnmsCriteria(criteria));
assertEquals(1, alarms.length);
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class NCSEdgeStatusProvider method getNCSImpactedAlarms.
private Set<String> getNCSImpactedAlarms() {
org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsAlarm.class);
criteria.addRestriction(new EqRestriction("uei", "uei.opennms.org/internal/ncs/componentImpacted"));
List<OnmsAlarm> alarms = getAlarmDao().findMatching(criteria);
Set<String> alarmsSet = new HashSet<>();
for (OnmsAlarm alarm : alarms) {
final Optional<String> foreignSource = alarm.findEventParameter("foreignSource").map(OnmsEventParameter::getValue);
final Optional<String> foreignId = alarm.findEventParameter("foreignId").map(OnmsEventParameter::getValue);
if (foreignSource.isPresent() && foreignId.isPresent()) {
alarmsSet.add(foreignSource.get() + "::" + foreignId.get());
}
}
return alarmsSet;
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class NotificationManagerIT method canMatchEventParametersWhenAcknowledgingNotices.
@Test
@JUnitTemporaryDatabase
public void canMatchEventParametersWhenAcknowledgingNotices() throws IOException, SQLException {
// Insert some event in the database with a few event parameters
OnmsEvent dbEvent = new OnmsEvent();
dbEvent.setDistPoller(m_distPollerDao.whoami());
dbEvent.setEventUei(EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI);
dbEvent.setEventCreateTime(new Date());
dbEvent.setEventLog("Y");
dbEvent.setEventDisplay("Y");
dbEvent.setEventSeverity(OnmsSeverity.CRITICAL.getId());
dbEvent.setEventSource("test");
dbEvent.setEventTime(new Date());
dbEvent.setNode(node1);
dbEvent.setEventParameters(Arrays.asList(new OnmsEventParameter(dbEvent, "some-parameter", "some-specific-value", "string"), new OnmsEventParameter(dbEvent, "some-other-parameter", "some-other-specific-value", "string")));
m_eventDao.save(dbEvent);
m_eventDao.flush();
// Create some notification referencing the event we just created
Notification notification = new Notification();
Map<String, String> params = new ImmutableMap.Builder<String, String>().put(NotificationManager.PARAM_TEXT_MSG, "some text message").put(NotificationManager.PARAM_NODE, node1.getNodeId()).put(NotificationManager.PARAM_INTERFACE, InetAddressUtils.toIpAddrString(ipInterfaceOnNode1.getIpAddress())).put(NotificationManager.PARAM_SERVICE, "ICMP").put("eventUEI", dbEvent.getEventUei()).put("eventID", Integer.toString(dbEvent.getId())).build();
m_notificationManager.insertNotice(1, params, "q1", notification);
final String[] parmMatchList = new String[] { "parm[some-parameter]", "parm[#2]" };
// Verify that we're able to match the the notice when we have the same parameters set
Event e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "some-specific-value").addParam("some-other-parameter", "some-other-specific-value").getEvent();
Collection<Integer> eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(1, eventIds.size());
assertEquals(dbEvent.getId(), eventIds.iterator().next());
unacknowledgeAllNotices();
// It should not match when either of the event parameters are different
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "!some-specific-value").addParam("some-other-parameter", "some-other-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "some-specific-value").addParam("some-other-parameter", "!some-other-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
// It should not match when either of the event parameters are missing
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-other-parameter", "some-other-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").addParam("some-parameter", "some-specific-value").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, parmMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
// Now try matching on other fields without any event parameters
final String[] fieldMatchList = new String[] { "nodeid", "interfaceid", "serviceid" };
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").setNodeid(node1.getId()).setInterface(ipInterfaceOnNode1.getIpAddress()).setService("ICMP").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, fieldMatchList);
assertEquals(1, eventIds.size());
unacknowledgeAllNotices();
// Expect no match if we set different values responsive event
e = new EventBuilder(EventConstants.SERVICE_RESPONSIVE_EVENT_UEI, "test").setNodeid(node1.getId() + 1).setInterface(InetAddressUtils.UNPINGABLE_ADDRESS).setService("HTTP").getEvent();
eventIds = m_notificationManager.acknowledgeNotice(e, EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI, fieldMatchList);
assertEquals(0, eventIds.size());
unacknowledgeAllNotices();
}
use of org.opennms.netmgt.model.OnmsEventParameter in project opennms by OpenNMS.
the class DatabasePopulator method buildEvent.
public OnmsEvent buildEvent(final OnmsDistPoller distPoller) {
final OnmsEvent event = new OnmsEvent();
event.setDistPoller(distPoller);
event.setEventCreateTime(new Date(1437061537126L));
event.setEventDescr("This is the description of a test event.");
event.setEventDisplay("Y");
// TODO: Figure out exactly what this field is storing
event.setEventHost("127.0.0.1");
event.setEventLog("Y");
event.setEventLogMsg("Test Event Log Message");
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "testParm", "HelloWorld", "string")));
event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
event.setEventSource("test");
event.setEventTime(new Date(1437061537105L));
event.setEventUei("uei.opennms.org/test");
event.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
event.setNode(m_node1);
event.setServiceType(m_serviceTypeDao.findByName("ICMP"));
return event;
}
Aggregations