use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmPersisterImpl method addOrReduceEventAsAlarm.
private OnmsAlarmAndLifecycleEvent addOrReduceEventAsAlarm(Event event, boolean eagerlyLoadAlarm) {
// 2012-03-11 pbrane: for some reason when we get here the event from the DB doesn't have the LogMsg (in my tests anyway)
OnmsEvent e = m_eventDao.get(event.getDbid());
Assert.notNull(e, "Event was deleted before we could retrieve it and create an alarm.");
final String reductionKey = event.getAlarmData().getReductionKey();
LOG.debug("addOrReduceEventAsAlarm: looking for existing reduction key: {}", reductionKey);
OnmsAlarm alarm = m_alarmDao.findByReductionKey(reductionKey);
final EventBuilder ebldr;
if (alarm == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("addOrReduceEventAsAlarm: reductionKey:{} not found, instantiating new alarm", reductionKey);
}
alarm = createNewAlarm(e, event);
// FIXME: this should be a cascaded save
m_alarmDao.save(alarm);
m_eventDao.saveOrUpdate(e);
ebldr = new EventBuilder(EventConstants.ALARM_CREATED_UEI, Alarmd.NAME);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("addOrReduceEventAsAlarm: reductionKey:{} found, reducing event to existing alarm: {}", reductionKey, alarm.getIpAddr());
}
reduceEvent(e, alarm, event);
m_alarmDao.update(alarm);
m_eventDao.update(e);
if (event.getAlarmData().isAutoClean()) {
m_eventDao.deletePreviousEventsForAlarm(alarm.getId(), e);
}
ebldr = new EventBuilder(EventConstants.ALARM_UPDATED_WITH_REDUCED_EVENT_UEI, Alarmd.NAME);
}
if (eagerlyLoadAlarm) {
// Load fields which are known to be used by the NBIs
if (alarm.getServiceType() != null) {
// To avoid potential LazyInitializationException when dealing with NorthboundAlarm
alarm.getServiceType().getName();
}
if (alarm.getNodeId() != null) {
// This should trigger the lazy loading of the node object, to properly populate the NorthboundAlarm class.
alarm.getNode().getForeignSource();
}
Hibernate.initialize(alarm.getEventParameters());
}
ebldr.addParam(EventConstants.PARM_ALARM_UEI, alarm.getUei());
ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
return new OnmsAlarmAndLifecycleEvent(alarm, ebldr.getEvent());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class VacuumdIT method createDownAlarm.
/**
* Creates the down alarm.
*
* @param node the node
* @param eventTime the event time
* @return the alarm
*/
@Transactional
public OnmsAlarm createDownAlarm(OnmsNode node, Date eventTime) {
final String uei = "uei.opennms.org/nodes/nodeDown";
OnmsEvent event = new OnmsEvent();
event.setEventSource("JUnit");
event.setDistPoller(m_distPoller);
event.setNode(node);
event.setEventUei(uei);
event.setEventCreateTime(eventTime);
event.setEventTime(eventTime);
event.setEventDisplay("Y");
event.setEventLog("Y");
event.setEventLogMsg("Node is down");
event.setEventSeverity(OnmsSeverity.MAJOR.getId());
event.setSeverityLabel(OnmsSeverity.MAJOR.getLabel());
m_eventDao.save(event);
m_eventDao.flush();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setDistPoller(m_distPoller);
alarm.setCounter(1);
alarm.setLastEvent(event);
alarm.setLastEventTime(event.getEventTime());
alarm.setNode(node);
alarm.setUei(uei);
alarm.setAlarmType(1);
alarm.setSeverity(OnmsSeverity.MAJOR);
alarm.setReductionKey(uei + "::" + node.getId());
m_alarmDao.save(alarm);
m_alarmDao.flush();
return alarm;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class VacuumdIT method createUpAlarm.
/**
* Creates the up alarm.
*
* @param node the node
* @param eventTime the event time
* @return the alarm
*/
@Transactional
public OnmsAlarm createUpAlarm(OnmsNode node, Date eventTime) {
final String uei = "uei.opennms.org/nodes/nodeUp";
OnmsEvent event = new OnmsEvent();
event.setEventSource("JUnit");
event.setDistPoller(m_distPoller);
event.setNode(node);
event.setEventUei(uei);
event.setEventCreateTime(eventTime);
event.setEventTime(eventTime);
event.setEventDisplay("Y");
event.setEventLog("Y");
event.setEventLogMsg("Node is Up");
event.setEventSeverity(OnmsSeverity.NORMAL.getId());
event.setSeverityLabel(OnmsSeverity.NORMAL.getLabel());
m_eventDao.save(event);
m_eventDao.flush();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setDistPoller(m_distPoller);
alarm.setCounter(1);
alarm.setLastEvent(event);
alarm.setLastEventTime(event.getEventTime());
alarm.setNode(node);
alarm.setUei(uei);
alarm.setAlarmType(2);
alarm.setSeverity(OnmsSeverity.NORMAL);
alarm.setReductionKey(uei + "::" + node.getId());
alarm.setClearKey("uei.opennms.org/nodes/nodeDown::" + node.getId());
m_alarmDao.save(alarm);
m_alarmDao.flush();
return alarm;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class EmailNorthbounderTest method testNorthbounderForServers.
/**
* Test northbounder for servers.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounderForServers() throws Exception {
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Servers-MacOS");
node.setForeignId("1");
node.setId(1);
node.setLabel("my-test-server");
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
snmpInterface.setId(1);
snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
snmpInterface.setIfDescr("en1");
snmpInterface.setIfName("en1/0");
snmpInterface.setPhysAddr("00:00:00:00:00:01");
InetAddress address = InetAddress.getByName("10.0.1.1");
OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
onmsIf.setSnmpInterface(snmpInterface);
onmsIf.setId(1);
onmsIf.setIfIndex(1);
onmsIf.setIpHostName("my-test-server");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.getIpInterfaces().add(onmsIf);
// Setup test alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(100);
onmsAlarm.setNode(node);
onmsAlarm.setIpAddr(address);
onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
}
});
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
// Verify the nortbound alarm and send it to the test receiver
Assert.assertTrue(nbi.accepts(alarm));
SendmailConfig sendmail = nbi.getSendmailConfig(alarm);
Assert.assertEquals("noc@networksRus.com", sendmail.getSendmailMessage().getTo());
Assert.assertEquals("ALARM 100 FROM NODE my-test-server@Servers-MacOS", sendmail.getSendmailMessage().getSubject());
Assert.assertEquals("ALARM 100 FROM NODE my-test-server@Servers-MacOS: Test log message\nDescription: Test description", sendmail.getSendmailMessage().getBody());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class EmailNorthbounderTest method testNorthbounderForRouters.
/**
* Test northbounder for routers.
*
* @throws Exception the exception
*/
@Test
public void testNorthbounderForRouters() throws Exception {
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Routers-Cisco");
node.setForeignId("1");
node.setId(1);
node.setLabel("my-test-router");
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
snmpInterface.setId(1);
snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
snmpInterface.setIfDescr("en1");
snmpInterface.setIfName("en1/0");
snmpInterface.setPhysAddr("00:00:00:00:00:01");
InetAddress address = InetAddress.getByName("10.0.1.1");
OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
onmsIf.setSnmpInterface(snmpInterface);
onmsIf.setId(1);
onmsIf.setIfIndex(1);
onmsIf.setIpHostName("my-test-router");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.getIpInterfaces().add(onmsIf);
// Setup test alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(100);
onmsAlarm.setNode(node);
onmsAlarm.setIpAddr(address);
onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "10", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is a test", "string")));
}
});
onmsAlarm.setLogMsg("Test log message");
onmsAlarm.setDescription("Test description");
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(2, alarm.getEventParametersCollection().size());
// Verify the nortbound alarm and send it to the test receiver
Assert.assertTrue(nbi.accepts(alarm));
SendmailConfig sendmail = nbi.getSendmailConfig(alarm);
Assert.assertEquals("tarus@opennms.org, jeff@opennms.org", sendmail.getSendmailMessage().getTo());
Assert.assertEquals("my-test-router : Something is wrong!", sendmail.getSendmailMessage().getSubject());
Assert.assertEquals("Test log message - Test description", sendmail.getSendmailMessage().getBody());
}
Aggregations