use of org.opennms.netmgt.model.OnmsOutage 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.OnmsOutage 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.OnmsOutage in project opennms by OpenNMS.
the class DefaultSurveillanceViewService method getNodeListForCriteria.
/**
* Returns a list of node RTC calculations for the given criterias.
*
* @param serviceCriteria the service criteria
* @param outageCriteria the outage criteries
* @return the list of {@link org.opennms.features.vaadin.surveillanceviews.service.SurveillanceViewService.NodeRtc} instances
*/
private List<NodeRtc> getNodeListForCriteria(final Criteria serviceCriteria, final Criteria outageCriteria) {
List<Order> ordersService = new ArrayList<>();
ordersService.add(Order.asc("node.label"));
ordersService.add(Order.asc("node.id"));
ordersService.add(Order.asc("ipInterface.ipAddress"));
ordersService.add(Order.asc("serviceType.name"));
serviceCriteria.setOrders(ordersService);
Date periodEnd = new Date(System.currentTimeMillis());
Date periodStart = new Date(periodEnd.getTime() - (24 * 60 * 60 * 1000));
outageCriteria.addRestriction(Restrictions.any(Restrictions.isNull("ifRegainedService"), Restrictions.ge("ifLostService", periodStart), Restrictions.ge("ifRegainedService", periodStart)));
List<Order> ordersOutage = new ArrayList<>();
ordersOutage.add(Order.asc("monitoredService"));
ordersOutage.add(Order.asc("ifLostService"));
outageCriteria.setOrders(ordersOutage);
List<OnmsMonitoredService> services = m_monitoredServiceDao.findMatching(serviceCriteria);
List<OnmsOutage> outages = m_outageDao.findMatching(outageCriteria);
Map<OnmsMonitoredService, Long> serviceDownTime = calculateServiceDownTime(periodEnd, periodStart, outages);
List<NodeRtc> model = new ArrayList<>();
OnmsNode lastNode = null;
int serviceCount = 0;
int serviceDownCount = 0;
long downMillisCount = 0;
for (OnmsMonitoredService service : services) {
if (!service.getIpInterface().getNode().equals(lastNode) && lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount);
model.add(new NodeRtc(lastNode, serviceCount, serviceDownCount, availability));
serviceCount = 0;
serviceDownCount = 0;
downMillisCount = 0;
}
serviceCount++;
if (service.isDown()) {
serviceDownCount++;
}
Long downMillis = serviceDownTime.get(service);
if (downMillis != null) {
downMillisCount += downMillis;
}
lastNode = service.getIpInterface().getNode();
}
if (lastNode != null) {
Double availability = calculateAvailability(serviceCount, downMillisCount);
model.add(new NodeRtc(lastNode, serviceCount, serviceDownCount, availability));
}
return model;
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForInterface.
/**
* <p>closeOutagesForInterface</p>
*
* @param closeDate a {@link java.util.Date} object.
* @param eventId a int.
* @param nodeId a int.
* @param ipAddr a {@link java.lang.String} object.
*/
@Override
public void closeOutagesForInterface(Date closeDate, int eventId, int nodeId, String ipAddr) {
Criteria criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
criteria.addRestriction(new EqRestriction("ipInterface.ipAddress", addr(ipAddr)));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
outage.setServiceRegainedEvent(m_eventDao.get(eventId));
m_outageDao.update(outage);
}
}
use of org.opennms.netmgt.model.OnmsOutage in project opennms by OpenNMS.
the class QueryManagerDaoImpl method closeOutagesForUnmanagedServices.
/**
*/
@Override
public void closeOutagesForUnmanagedServices() {
Date closeDate = new java.util.Date();
Criteria criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService", "monitoredService", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new AnyRestriction(new EqRestriction("monitoredService.status", "D"), new EqRestriction("monitoredService.status", "F"), new EqRestriction("monitoredService.status", "U")));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
List<OnmsOutage> outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
m_outageDao.update(outage);
}
criteria = new Criteria(OnmsOutage.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new AnyRestriction(new EqRestriction("ipInterface.isManaged", "F"), new EqRestriction("ipInterface.isManaged", "U")));
criteria.addRestriction(new NullRestriction("ifRegainedService"));
outages = m_outageDao.findMatching(criteria);
for (OnmsOutage outage : outages) {
outage.setIfRegainedService(closeDate);
m_outageDao.update(outage);
}
}
Aggregations