use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AvailabilityDatabasePopulator method populateDatabase.
public void populateDatabase() {
OnmsCategory ac = getCategory("DEV_AC");
OnmsCategory mid = getCategory("IMP_mid");
OnmsCategory ops = getCategory("OPS_Online");
OnmsCategory catRouter = getCategory("Routers");
@SuppressWarnings("unused") OnmsCategory catSwitches = getCategory("Switches");
OnmsCategory catServers = getCategory("Servers");
getCategory("Production");
getCategory("Test");
getCategory("Development");
getServiceType("ICMP");
getServiceType("SNMP");
getServiceType("HTTP");
// m_db.update("insert into node (nodeID, nodelabel, nodeCreateTime, nodeType) values (1,'test1.availability.opennms.org','2004-03-01 09:00:00','A')");
// m_db.update("insert into node (nodeID, nodelabel, nodeCreateTime, nodeType) values (2,'test2.availability.opennms.org','2004-03-01 09:00:00','A')");
//
// m_db.update("insert into service (serviceid, servicename) values\n"
// + "(1, 'ICMP');");
// m_db.update("insert into service (serviceid, servicename) values\n"
// + "(2, 'HTTP');");
// m_db.update("insert into service (serviceid, servicename) values\n"
// + "(3, 'SNMP');");
//
// m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
// + "(1, 1,'192.168.100.1','M');");
// m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
// + "(2, 2,'192.168.100.2','M');");
// m_db.update("insert into ipinterface (id, nodeid, ipaddr, ismanaged) values\n"
// + "(3, 2,'192.168.100.3','M');");
//
// m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
// + "(1,'192.168.100.1',1,'A', 1);");
// m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
// + "(2,'192.168.100.2',1,'A', 2);");
// /*
// * m_db.update("insert into ifservices (nodeid, ipaddr, serviceid,
// * status, ipInterfaceId) values " + "(2,'192.168.100.2',2,'A', 2);");
// */
// m_db.update("insert into ifservices (nodeid, ipaddr, serviceid, status, ipInterfaceId) values "
// + "(2,'192.168.100.3',1,'A', 3);");
NetworkBuilder builder = new NetworkBuilder();
setNode1(builder.addNode("test1.availability.opennms.org").setId(1).setType(NodeType.ACTIVE).getNode());
Assert.assertNotNull("newly built node 1 should not be null", getNode1());
builder.addCategory(ac);
builder.addCategory(mid);
builder.addCategory(ops);
builder.addCategory(catRouter);
builder.setBuilding("HQ");
builder.addInterface("192.168.100.1").setIsManaged("M");
// getNodeDao().save(builder.getCurrentNode());
// getNodeDao().flush();
builder.addService(getServiceType("ICMP")).setStatus("A");
getNodeDao().save(builder.getCurrentNode());
getNodeDao().flush();
builder.addNode("test2.availability.opennms.org").setId(2).setType(NodeType.ACTIVE);
builder.addCategory(mid);
builder.addCategory(catServers);
builder.setBuilding("HQ");
builder.addInterface("192.168.100.2").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(getServiceType("ICMP")).setStatus("A");
// builder.addService(getServiceType("SNMP")).setStatus("A");;
builder.addInterface("192.168.100.3").setIsManaged("M");
builder.addService(getServiceType("ICMP")).setStatus("A");
// builder.addService(getServiceType("HTTP")).setStatus("A");
getNodeDao().save(builder.getCurrentNode());
getNodeDao().flush();
OnmsEvent event = new OnmsEvent();
event.setDistPoller(builder.getDistPoller());
event.setEventUei("uei.opennms.org/test");
event.setEventTime(new Date());
event.setEventSource("test");
event.setEventCreateTime(new Date());
event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
getEventDao().save(event);
getEventDao().flush();
// + "(2,2,'192.168.100.2',1,'2005-05-01 10:00:00','2005-05-02 10:00:00');");
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
OnmsMonitoredService node1If1Svc1 = getMonitoredServiceDao().get(1, InetAddressUtils.addr("192.168.100.1"), "ICMP");
OnmsMonitoredService node2If1Svc1 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.2"), "ICMP");
@SuppressWarnings("unused") OnmsMonitoredService node2If1Svc2 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.2"), "SNMP");
OnmsMonitoredService node2If2Svc1 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.3"), "ICMP");
@SuppressWarnings("unused") OnmsMonitoredService node2If2Svc2 = getMonitoredServiceDao().get(2, InetAddressUtils.addr("192.168.100.3"), "HTTP");
OnmsOutage outage1 = new OnmsOutage(df.parse("2005-05-01 09:00:00"), df.parse("2005-05-01 09:30:00"), event, event, node1If1Svc1, null, null);
getOutageDao().save(outage1);
getOutageDao().flush();
OnmsOutage outage2 = new OnmsOutage(df.parse("2005-05-01 10:00:00"), df.parse("2005-05-02 10:00:00"), event, event, node2If1Svc1, null, null);
getOutageDao().save(outage2);
getOutageDao().flush();
// test data for LastMonthsDailyAvailability report
// // insert 30 minute outage on one node - 99.3056% availability
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(3,1,'192.168.100.1',1,'2005-04-02 10:00:00','2005-04-02 10:30:00');");
OnmsOutage outage3 = new OnmsOutage(df.parse("2005-04-02 10:00:00"), df.parse("2005-04-02 10:30:00"), event, event, node1If1Svc1, null, null);
getOutageDao().save(outage3);
getOutageDao().flush();
// // insert 60 minute outage on one interface and 59 minute outages on
// // another - 97.2454
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(4,1,'192.168.100.1',1,'2005-04-03 11:30:00','2005-04-03 12:30:00');");
OnmsOutage outage4 = new OnmsOutage(df.parse("2005-04-03 11:30:00"), df.parse("2005-04-03 12:30:00"), event, event, node1If1Svc1, null, null);
getOutageDao().save(outage4);
getOutageDao().flush();
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(5,2,'192.168.100.2',1,'2005-04-03 23:00:00','2005-04-03 23:59:00');");
OnmsOutage outage5 = new OnmsOutage(df.parse("2005-04-03 23:00:00"), df.parse("2005-04-03 23:59:00"), event, event, node2If1Svc1, null, null);
getOutageDao().save(outage5);
getOutageDao().flush();
// // test an outage that spans 60 minutes across midnight - 99.3056% on
// // each day, well, not exactly
// // its 29 minutes 99.3059 on the fist day and 31 minutes 99.3052 on
// // the second.
// m_db.update("insert into outages (outageid, nodeid, ipaddr, serviceid, ifLostService, ifRegainedService) values "
// + "(6,2,'192.168.100.3',1,'2005-04-04 23:30:00','2005-04-05 00:30:00');");
OnmsOutage outage6 = new OnmsOutage(df.parse("2005-04-04 23:30:00"), df.parse("2005-04-05 00:30:00"), event, event, node2If2Svc1, null, null);
getOutageDao().save(outage6);
getOutageDao().flush();
} catch (final ParseException e) {
LOG.warn("populating database failed", e);
}
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmMapperTest method canMapAlarm.
@Test
public void canMapAlarm() throws IOException {
Event eventConf = new Event();
eventConf.setUei("uei.opennms.org/nodes/interfaceDown");
eventConf.setEventLabel("OpenNMS-defined node event: interfaceDown");
eventConfDao.addEvent(eventConf);
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(34);
alarm.setUei("uei.opennms.org/nodes/interfaceDown");
OnmsMonitoringSystem monitoringSystem = new OnmsMonitoringSystem();
monitoringSystem.setLocation("Default");
alarm.setDistPoller(monitoringSystem);
OnmsNode node = new OnmsNode();
node.setId(1);
node.setLabel("n1");
alarm.setNode(node);
alarm.setIpAddr(InetAddress.getByName("10.8.0.30"));
alarm.setReductionKey("uei.opennms.org/nodes/interfaceDown::1:10.8.0.30");
alarm.setAlarmType(1);
alarm.setCounter(1);
alarm.setSeverity(OnmsSeverity.MINOR);
alarm.setFirstEventTime(new Date(1503412443118L));
alarm.setDescription("All services are down on interface 10.8.0.30.");
alarm.setLogMsg("Interface 10.8.0.30 is down.");
alarm.setSuppressedUntil(new Date(1503412443118L));
alarm.setSuppressedTime(new Date(1503412443118L));
alarm.setLastEventTime(new Date(1503412443118L));
alarm.setX733ProbableCause(0);
OnmsServiceType serviceType = new OnmsServiceType();
serviceType.setName("ICMP");
serviceType.setId(3);
alarm.setServiceType(serviceType);
OnmsEvent event = new OnmsEvent();
event.setId(2035);
event.setEventUei("uei.opennms.org/nodes/interfaceDown");
event.setEventTime(new Date(1503412443118L));
event.setEventHost("noise");
event.setEventSource("OpenNMS.Poller.DefaultPollContext");
event.setIpAddr(InetAddress.getByName("10.8.0.30"));
event.setEventCreateTime(new Date(1503412443118L));
event.setEventDescr("All services are down on interface 10.8.0.30.");
event.setEventLogMsg("Interface 10.8.0.30 is down.");
event.setEventSeverity(OnmsSeverity.MINOR.getId());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setNode(node);
event.setDistPoller(monitoringSystem);
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "test", "testVal", "string")));
event.setServiceType(serviceType);
alarm.setLastEvent(event);
alarm.setTTicketId("NMS-9587");
alarm.setTTicketState(TroubleTicketState.OPEN);
AlarmDTO alarmDTO = alarmMapper.alarmToAlarmDTO(alarm);
mapAndMarshalToFromXmlAndJson(alarmDTO, "alarm.34.dto.xml", "alarm.34.dto.json");
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class EventMapperTest method canMapEvent.
@Test
public void canMapEvent() {
Event eventConf = new Event();
eventConf.setUei("some-uei");
eventConf.setEventLabel("some-label");
eventConfDao.addEvent(eventConf);
OnmsEvent event = new OnmsEvent();
event.setId(1);
event.setEventUei("some-uei");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
EventDTO eventDTO = eventMapper.eventToEventDTO(event);
assertThat(eventDTO.getId(), equalTo(1));
assertThat(eventDTO.getLabel(), equalTo("some-label"));
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AckdIT method createAckStructure.
private VerificationObject createAckStructure() {
final Date time = new Date();
VerificationObject vo = new VerificationObject();
List<OnmsNode> nodes = m_nodeDao.findAll();
Assert.assertTrue("List of nodes should not be empty", nodes.size() > 0);
OnmsNode node = m_nodeDao.get(nodes.get(0).getId());
vo.m_nodeId = node.getId();
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_populator.getDistPollerDao().whoami());
event.setNode(node);
event.setEventCreateTime(time);
event.setEventDescr("Test node down event.");
event.setEventSeverity(OnmsSeverity.MAJOR.getId());
event.setEventSource("AckdTest");
event.setEventTime(time);
event.setEventUei(EventConstants.NODE_DOWN_EVENT_UEI);
event.setIpAddr(node.getPrimaryInterface().getIpAddress());
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogMsg("Testing node down event from AckdTest.");
m_eventDao.save(event);
m_eventDao.flush();
vo.m_eventID = event.getId();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setClearKey(EventConstants.NODE_UP_EVENT_UEI + ":localhost:1");
alarm.setCounter(1);
alarm.setDescription(event.getEventDescr());
alarm.setDistPoller(event.getDistPoller());
alarm.setFirstEventTime(event.getEventTime());
alarm.setIpAddr(event.getIpAddr());
alarm.setLastEvent(event);
alarm.setLastEventTime(event.getEventTime());
alarm.setLogMsg("Some Log Message");
alarm.setNode(event.getNode());
alarm.setReductionKey("xyz");
alarm.setServiceType(event.getServiceType());
alarm.setSeverity(OnmsSeverity.get(event.getEventSeverity()));
alarm.setUei(event.getEventUei());
m_alarmDao.save(alarm);
m_alarmDao.flush();
vo.m_alarmId = alarm.getId();
event.setAlarm(alarm);
OnmsNotification notif = new OnmsNotification();
notif.setEvent(event);
notif.setEventUei(event.getEventUei());
notif.setIpAddress(event.getIpAddr());
notif.setNode(event.getNode());
notif.setNotifConfigName("abc");
notif.setNumericMsg(event.getEventLogMsg());
notif.setPageTime(event.getEventTime());
notif.setServiceType(event.getServiceType());
notif.setSubject("notifyid: 1, node down");
notif.setTextMsg(event.getEventLogMsg());
m_notificationDao.save(notif);
vo.m_notifId = notif.getNotifyId();
OnmsUserNotification userNotif = new OnmsUserNotification();
userNotif.setAutoNotify("Y");
userNotif.setContactInfo("me@yourock.com");
userNotif.setMedia("page");
userNotif.setNotification(notif);
userNotif.setNotifyTime(event.getEventTime());
userNotif.setUserId("me");
Set<OnmsUserNotification> usersnotifieds = new HashSet<>();
usersnotifieds.add(userNotif);
m_userNotificationDao.save(userNotif);
vo.m_userNotifId = userNotif.getId();
notif.setUsersNotified(usersnotifieds);
m_notificationDao.update(notif);
m_eventDao.update(event);
m_eventDao.flush();
return vo;
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class DefaultAckServiceIT method notificationWithMissingAlarm.
@Test(expected = IllegalStateException.class)
public void notificationWithMissingAlarm() {
OnmsNode dbNode = m_nodeDao.get(m_populator.getNode1().getId());
OnmsEvent event = getEvent(dbNode);
OnmsAlarm alarm = new OnmsAlarm();
alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
alarm.setDescription(event.getEventDescr());
alarm.setDistPoller(event.getDistPoller());
alarm.setFirstEventTime(event.getEventTime());
alarm.setIfIndex(event.getIfIndex());
alarm.setIpAddr(event.getIpAddr());
alarm.setLastEvent(event);
alarm.setLastEventTime(event.getEventTime());
alarm.setLogMsg(event.getEventLogMsg());
alarm.setMouseOverText(event.getEventMouseOverText());
alarm.setNode(dbNode);
alarm.setSeverityId(event.getEventSeverity());
alarm.setUei(event.getEventUei());
alarm.setCounter(1);
m_alarmDao.save(alarm);
m_alarmDao.flush();
getNotification(event);
OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setRefId(alarm.getAckId());
ack.setAckType(alarm.getType());
m_alarmDao.delete(alarm);
m_alarmDao.flush();
m_ackDao.processAck(ack);
}
Aggregations