use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class JmsNorthBounderTest method testObjectMessage.
@Test
public void testObjectMessage() throws Exception {
String xml = objectMessageConfigXml();
Resource resource = new ByteArrayResource(xml.getBytes());
JmsNorthbounderConfigDao dao = new JmsNorthbounderConfigDao();
dao.setConfigResource(resource);
dao.afterPropertiesSet();
JmsNorthbounderConfig config = dao.getConfig();
List<JmsDestination> destinations = config.getDestinations();
List<JmsNorthbounder> nbis = new LinkedList<>();
for (JmsDestination jmsDestination : destinations) {
JmsNorthbounder nbi = new JmsNorthbounder(config, m_jmsNorthbounderConnectionFactory, jmsDestination);
// nbi.setNodeDao(m_nodeDao);
nbi.afterPropertiesSet();
nbis.add(nbi);
}
List<NorthboundAlarm> alarms = new LinkedList<>();
OnmsNode node = new OnmsNode(null, NODE_LABEL);
node.setForeignSource("TestGroup");
node.setForeignId("2");
node.setId(m_nodeDao.getNextNodeId());
OnmsIpInterface ip = new OnmsIpInterface("127.0.0.1", node);
InetAddress ia = null;
try {
ia = InetAddress.getByName("127.0.0.1");
} catch (UnknownHostException e) {
}
m_nodeDao.save(node);
m_nodeDao.flush();
// TX via NBIs
for (JmsNorthbounder nbi : nbis) {
OnmsEvent event = new OnmsEvent();
event.setId(5);
event.setEventUei("uei.uei.org/uei");
event.setEventTime(new Date());
event.setEventHost("eventhost");
event.setEventSource("eventsource");
event.setIpAddr(ia);
event.setDistPoller(null);
event.setEventSnmpHost("eventsnmphost");
event.setServiceType(null);
event.setEventSnmp("eventsnmp");
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "syslogmessage", "Dec 22 2015 20:12:57.1 UTC : %UC_CTI-3-CtiProviderOpenFailure: %[CTIconnectionId%61232238][ Login User Id%61pguser][Reason code.%61-1932787616][UNKNOWN_PARAMNAME:IPAddress%61172.17.12.73][UNKNOWN_PARAMNAME:IPv6Address%61][App ID%61Cisco CTIManager][Cluster ID%61SplkCluster][Node ID%61splkcucm6p]: CTI application failed to open provider%59 application startup failed", "string"), new OnmsEventParameter(event, "severity", "Error", "string"), new OnmsEventParameter(event, "timestamp", "Dec 22 14:13:21", "string"), new OnmsEventParameter(event, "process", "229250", "string"), new OnmsEventParameter(event, "service", "local7", "string")));
event.setEventCreateTime(new Date());
event.setEventDescr("eventdescr");
event.setEventLogGroup("eventloggroup");
event.setEventLogMsg("eventlogmsg");
event.setEventSeverity(4);
event.setEventPathOutage(null);
event.setEventCorrelation(null);
event.setEventSuppressedCount(0);
event.setEventOperInstruct("operinstruct");
event.setEventAutoAction(null);
event.setEventOperAction(null);
event.setEventOperActionMenuText(null);
event.setEventNotification(null);
event.setEventTTicket("tticketid");
event.setEventTTicketState(1);
event.setEventForward(null);
event.setEventMouseOverText(null);
event.setEventLog(null);
event.setEventDisplay(null);
event.setEventAckUser(null);
event.setEventAckTime(null);
event.setAlarm(null);
event.setNode(node);
event.setNotifications(null);
event.setAssociatedServiceRegainedOutages(null);
event.setAssociatedServiceLostOutages(null);
OnmsAlarm alarm = new OnmsAlarm(9, event.getEventUei(), null, 1, 4, new Date(), event);
alarm.setNode(node);
alarm.setDescription(event.getEventDescr());
alarm.setApplicationDN("applicationDN");
alarm.setLogMsg(event.getEventLogMsg());
alarm.setManagedObjectInstance("managedObjectInstance");
alarm.setManagedObjectType("managedObjectType");
alarm.setOssPrimaryKey("ossPrimaryKey");
alarm.setQosAlarmState("qosAlarmState");
alarm.setTTicketId("tticketId");
alarm.setReductionKey("reductionKey");
alarm.setClearKey("clearKey");
alarm.setOperInstruct("operInstruct");
alarm.setFirstEventTime(new Date(0));
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setIpAddr(ia);
alarm.setLastEvent(event);
alarm.setX733AlarmType(NorthboundAlarm.x733AlarmType.get(1).name());
alarm.setX733ProbableCause(NorthboundAlarm.x733ProbableCause.get(1).getId());
NorthboundAlarm a = new NorthboundAlarm(alarm);
alarms.add(a);
nbi.forwardAlarms(alarms);
}
Thread.sleep(100);
// Let's become a consumer and receive the message
Message m = m_template.receive("ObjectTestQueue");
Assert.assertNotNull(m);
Object response = ((ObjectMessage) m).getObject();
Assert.assertNotNull(response);
Assert.assertTrue("message\n'" + response + "'\n not a NorthboundAlarm\n'" + "'.", (response instanceof NorthboundAlarm));
String rk = ((NorthboundAlarm) response).getAlarmKey();
Assert.assertEquals("received alarm has incorrect reduction key: " + rk, "reductionKey", rk);
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class SnmpTrapNorthbounderConfigDaoTest method createAlarm.
/**
* Creates the alarm.
*
* @return the northbound alarm
* @throws UnknownHostException the unknown host exception
*/
private NorthboundAlarm createAlarm() throws UnknownHostException {
// Build a test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Servers");
node.setForeignId("AAA11122");
node.setId(1);
node.setLabel("my-server");
// Build a test SNMP interface
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");
// Build a test IP interface
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("p-brane");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.addIpInterface(onmsIf);
// Build a test alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(10);
onmsAlarm.setNode(node);
onmsAlarm.setUei("uei.opennms.org/trap/myTrap1");
onmsAlarm.setLogMsg("everything is good");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "alarmId", "99", "Int32"), new OnmsEventParameter(this, "alarmMessage", "this is just a test", "String"), new OnmsEventParameter(this, "forwardAlarmToUserSnmpTrap", "true", "String")));
}
});
// Build a test northbound alarm
NorthboundAlarm alarm = new NorthboundAlarm(onmsAlarm);
Assert.assertEquals(node.getForeignSource(), alarm.getForeignSource());
Assert.assertEquals(node.getForeignId(), alarm.getForeignId());
return alarm;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class SnmpTrapNorthbounderTest method testNorthbounder.
/**
* Tests the trap northbounder.
*
* @throws Exception the exception
*/
// FIXME Verify the content of the trap sent.
@Test
public void testNorthbounder() throws Exception {
// Setup the configuration DAO
FileSystemResource resource = new FileSystemResource(new File("src/test/resources/etc/snmptrap-northbounder-config.xml"));
SnmpTrapNorthbounderConfigDao configDao = new SnmpTrapNorthbounderConfigDao();
configDao.setConfigResource(resource);
configDao.afterPropertiesSet();
// Setup the trap northbounder (overriding the settings of the first sink to use the test trap receiver)
SnmpTrapSink sink = configDao.getConfig().getSnmpTrapSink("localTest1");
sink.setIpAddress(TRAP_DESTINATION.getHostAddress());
sink.setPort(TRAP_PORT);
SnmpTrapNorthbounder nbi = new SnmpTrapNorthbounder(configDao, sink.getName());
nbi.afterPropertiesSet();
// Setup test node
OnmsNode node = new OnmsNode();
node.setForeignSource("Server-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")));
}
});
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));
nbi.forwardAlarms(Collections.singletonList(alarm));
// Introduce a delay to make sure the trap was sent and received.
Thread.sleep(5000);
Assert.assertEquals(1, getTrapsReceivedCount());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class SyslogNorthBounderWithFiltersTest method testForwardAlarms.
/* (non-Javadoc)
* @see org.opennms.netmgt.alarmd.northbounder.syslog.SyslogNorthBounderTest#testForwardAlarms()
*/
@Test
@Override
public void testForwardAlarms() throws Exception {
// Initialize the configuration
File configFile = new File("target/syslog-northbounder-config.xml");
FileUtils.copyFile(new File("src/test/resources/syslog-northbounder-config1.xml"), configFile);
// Initialize the configuration DAO
SyslogNorthbounderConfigDao dao = new SyslogNorthbounderConfigDao();
dao.setConfigResource(new FileSystemResource(configFile));
dao.afterPropertiesSet();
// Initialize the Syslog northbound interfaces
List<SyslogNorthbounder> nbis = new LinkedList<>();
for (SyslogDestination syslogDestination : dao.getConfig().getDestinations()) {
SyslogNorthbounder nbi = new SyslogNorthbounder(dao, syslogDestination.getName());
nbi.afterPropertiesSet();
nbis.add(nbi);
}
// Add a sample node to the database
OnmsNode node = new OnmsNode();
node.setForeignSource("TestGroup");
node.setForeignId("1");
node.setId(m_nodeDao.getNextNodeId());
node.setLabel("agalue");
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");
Set<OnmsIpInterface> ipInterfaces = new LinkedHashSet<>();
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("agalue");
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
ipInterfaces.add(onmsIf);
node.setIpInterfaces(ipInterfaces);
m_nodeDao.save(node);
m_nodeDao.flush();
// Create a sample Alarm
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(10);
onmsAlarm.setUei("uei.opennms.org/nodes/interfaceDown");
onmsAlarm.setNode(node);
onmsAlarm.setSeverityId(6);
onmsAlarm.setIpAddr(address);
onmsAlarm.setCounter(1);
onmsAlarm.setLogMsg("Interface Down");
onmsAlarm.setLastEvent(new OnmsEvent() {
{
this.setEventParameters(Lists.newArrayList(new OnmsEventParameter(this, "owner", "agalue", "String")));
}
});
NorthboundAlarm nbAlarm = new NorthboundAlarm(onmsAlarm);
List<NorthboundAlarm> alarms = new LinkedList<>();
alarms.add(nbAlarm);
// Verify filters and send alarms to the northbound interfaces
for (SyslogNorthbounder nbi : nbis) {
Assert.assertTrue(nbi.accepts(nbAlarm));
nbi.forwardAlarms(alarms);
}
// Induce a delay (based on the parent code)
Thread.sleep(100);
// Extract the log messages and verify the content
BufferedReader reader = new BufferedReader(new StringReader(m_logStream.readStream()));
List<String> messages = getMessagesFromBuffer(reader);
Assert.assertTrue("Log messages sent: 2, Log messages received: " + messages.size(), 2 == messages.size());
Assert.assertTrue(messages.get(0).contains("ALARM 10 FROM NODE agalue@TestGroup"));
Assert.assertTrue(messages.get(1).contains("ALARM 10 FROM INTERFACE 10.0.1.1"));
reader.close();
// Remove the temporary configuration file
configFile.delete();
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class QueryManagerDaoImpl method updateOpenOutageWithEventId.
/**
* {@inheritDoc}
*/
@Override
public void updateOpenOutageWithEventId(int outageId, int lostEventId) {
LOG.info("updating open outage {} with event id {}", outageId, lostEventId);
final OnmsEvent event = m_eventDao.get(lostEventId);
final OnmsOutage outage = m_outageDao.get(outageId);
if (outage == null) {
LOG.warn("Failed to update outage {} with event id {}. The outage no longer exists.", outageId, lostEventId);
return;
}
// Update the outage
outage.setServiceLostEvent(event);
m_outageDao.saveOrUpdate(outage);
}
Aggregations