use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class UserNotificationDaoIT method testSaveUserNotification.
@Test
@Transactional
public void testSaveUserNotification() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/UserNotificationDaoTest");
OnmsAlarm alarm = new OnmsAlarm();
event.setAlarm(alarm);
OnmsNode node = (OnmsNode) m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = (OnmsIpInterface) node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = (OnmsMonitoredService) iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
event.setIpAddr(iface.getIpAddress());
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/UserNotificationDaoTest", newEvent.getEventUei());
OnmsNotification notification = new OnmsNotification();
notification.setEvent(newEvent);
notification.setTextMsg("Tests are fun!");
m_notificationDao.save(notification);
OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
assertEquals("uei://org/opennms/test/UserNotificationDaoTest", newNotification.getEvent().getEventUei());
OnmsUserNotification userNotif = new OnmsUserNotification();
userNotif.setNotification(notification);
userNotif.setNotifyTime(new Date());
userNotif.setUserId("OpenNMS User");
userNotif.setMedia("E-mail");
userNotif.setContactInfo("test@opennms.org");
m_userNotificationDao.save(userNotif);
assertNotNull(userNotif.getNotification());
assertEquals(userNotif.getUserId(), "OpenNMS User");
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class LocationMonitorDaoHibernateIT method addStatusChangesForMonitorAndService.
private void addStatusChangesForMonitorAndService(OnmsLocationMonitor monitor, Set<OnmsMonitoredService> services) {
for (OnmsMonitoredService service : services) {
OnmsLocationSpecificStatus status = new OnmsLocationSpecificStatus();
status.setLocationMonitor(monitor);
status.setMonitoredService(service);
status.setPollResult(PollStatus.available());
m_locationMonitorDao.saveStatusChange(status);
// System.err.println("Adding status for " + status.getMonitoredService() + " from " + status.getLocationMonitor().getId());
}
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class PathOutageManagerDaoImpl method getLabelAndStatus.
/**
* This method is responsible for determining the
* node label of a node, and the up/down status
* and status color
*
* @param nodeIDStr a {@link java.lang.String} object.
* @param conn a {@link java.sql.Connection} object.
* @return an array of {@link java.lang.String} objects.
* @throws java.sql.SQLException if any.
*/
@Override
public String[] getLabelAndStatus(String nodeIDStr, Connection conn) {
String[] result = new String[3];
result[1] = "Cleared";
result[2] = "Unmanaged";
int nodeID = WebSecurityUtils.safeParseInt(nodeIDStr);
OnmsNode node = nodeDao.get(nodeID);
if (node == null) {
// TODO Log that node could not be found in database
return result;
}
result[0] = node.getLabel();
final org.opennms.core.criteria.Criteria crit = new org.opennms.core.criteria.Criteria(OnmsMonitoredService.class).setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.INNER_JOIN) })).addRestriction(new EqRestriction("status", "A")).addRestriction(new EqRestriction("ipInterface.node", node));
// Get all active services on the node
List<OnmsMonitoredService> services = monitoredServiceDao.findMatching(crit);
int countManagedSvcs = services.size();
// Count how many of these services have open outages
int countOutages = 0;
for (OnmsMonitoredService service : services) {
OnmsOutage out = outageDao.currentOutageForService(service);
if (out != null) {
countOutages++;
}
}
if (countManagedSvcs == countOutages) {
result[1] = "Critical";
result[2] = "All Services Down";
} else if (countOutages == 0) {
result[1] = "Normal";
result[2] = "All Services Up";
} else {
result[1] = "Minor";
result[2] = "Some Services Down";
}
return result;
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class PathOutageManagerDaoImpl method getCriticalPathData.
/**
* This method is responsible for determining the
* data related to the critical path:
* node label, nodeId, the number of nodes
* dependent on this path, and the managed state
* of the path
*
* @param criticalPathIp a {@link java.lang.String} object.
* @param criticalPathServiceName a {@link java.lang.String} object.
* @return an array of {@link java.lang.String} objects.
* @throws java.sql.SQLException if any.
*/
@Override
public String[] getCriticalPathData(String criticalPathIp, String criticalPathServiceName) {
String[] result = new String[4];
// Fetch all non-deleted nodes that have the critical path IP address
List<OnmsNode> nList = nodeDao.findByIpAddressAndService(InetAddressUtils.addr(criticalPathIp), criticalPathServiceName);
if (nList.size() < 1) {
// Didn't find the critical node so just return an empty result
return result;
} else if (nList.size() == 1) {
OnmsNode node = nList.get(0);
result[0] = node.getLabel();
result[1] = node.getNodeId();
} else if (nList.size() > 1) {
OnmsNode node = nList.get(0);
result[0] = "(" + nList.size() + " nodes have this IP)";
result[1] = node.getNodeId();
}
result[2] = String.valueOf(pathOutageDao.getNodesForPathOutage(InetAddressUtils.addr(criticalPathIp), criticalPathServiceName).size());
OnmsMonitoredService service = monitoredServiceDao.get(Integer.valueOf(result[1]), InetAddressUtils.addr(criticalPathIp), criticalPathServiceName);
if (service != null) {
OnmsOutage outage = outageDao.currentOutageForService(service);
if (outage == null) {
result[3] = "Normal";
} else {
result[3] = "Critical";
}
} else {
result[3] = "Cleared";
}
return result;
}
use of org.opennms.netmgt.model.OnmsMonitoredService 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);
}
}
Aggregations