Search in sources :

Example 6 with RTCCategory

use of org.opennms.netmgt.rtc.datablock.RTCCategory in project opennms by OpenNMS.

the class LegacyEuiLevelMapper method convertToEuiLevelXML.

/**
 * Convert the 'RTCCategory' object to a 'EuiLevel' object.
 *
 * @param rtcCat
 *            the RTCCategory to be converted
 * @return a {@link org.opennms.netmgt.xml.rtc.EuiLevel} object.
 */
public EuiLevel convertToEuiLevelXML(RTCCategory rtcCat) {
    // current time
    Date curDate = new Date();
    long curTime = curDate.getTime();
    // get the rolling window
    long rWindow = 24L * 60L * 60L * 1000L;
    LOG.debug("curdate: {}", curDate);
    // create the data
    EuiLevel level = new EuiLevel();
    // set created in m_header and add to level
    m_header.setCreated(EventConstants.formatToString(curDate));
    level.setHeader(m_header);
    org.opennms.netmgt.xml.rtc.Category levelCat = new org.opennms.netmgt.xml.rtc.Category();
    // get a handle to data
    synchronized (m_dataMgr) {
        // category label
        levelCat.setCatlabel(rtcCat.getLabel());
        // availability value for this category
        levelCat.setCatvalue(m_dataMgr.getValue(rtcCat, curTime, rWindow));
        // nodes in this category
        for (int nodeID : m_dataMgr.getNodes(rtcCat)) {
            Node levelNode = new Node();
            levelNode.setNodeid(nodeID);
            // value for this node for this category
            levelNode.setNodevalue(m_dataMgr.getValue(nodeID, rtcCat, curTime, rWindow));
            // node service count
            levelNode.setNodesvccount(m_dataMgr.getServiceCount(nodeID, rtcCat));
            // node service down count
            levelNode.setNodesvcdowncount(m_dataMgr.getServiceDownCount(nodeID, rtcCat));
            // add the node
            levelCat.getNode().add(levelNode);
        }
    }
    // add category
    level.getCategory().add(levelCat);
    return level;
}
Also used : RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Node(org.opennms.netmgt.xml.rtc.Node) Date(java.util.Date) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel)

Example 7 with RTCCategory

use of org.opennms.netmgt.rtc.datablock.RTCCategory in project opennms by OpenNMS.

the class AvailabilityServiceIT method canCalculateAvailability.

@Test
public void canCalculateAvailability() throws Exception {
    final MockNetwork mockNetwork = new MockNetwork();
    // This test depends on the specifics in the standard network definition
    mockNetwork.createStandardNetwork();
    m_mockDatabase.populate(mockNetwork);
    final RTCCategory rtcCat = EasyMock.createNiceMock(RTCCategory.class);
    EasyMock.expect(rtcCat.getLabel()).andReturn("NOC").anyTimes();
    EasyMock.expect(rtcCat.getNodes()).andReturn(Lists.newArrayList(1, 2)).anyTimes();
    EasyMock.replay(rtcCat);
    // Verify the availability when no outages are present
    EuiLevel euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    Category category = euiLevel.getCategory().get(0);
    assertEquals(100.0, category.getCatvalue(), 0.001);
    assertEquals(2, category.getNode().size());
    // Assumes the nodes are sorted
    assertEquals(4, category.getNode().get(0).getNodesvccount());
    assertEquals(2, category.getNode().get(1).getNodesvccount());
    // Create an outage that is both open and closed within the window
    final Date now = new Date();
    final Date oneHourAgo = new Date(now.getTime() - (60 * 60 * 1000));
    final Date thirtyMinutesAgo = new Date(now.getTime() - (30 * 60 * 1000));
    final OnmsMonitoredService icmpService = toMonitoredService(mockNetwork.getService(1, "192.168.1.1", "ICMP"));
    OnmsOutage outage = new OnmsOutage();
    outage.setMonitoredService(icmpService);
    outage.setIfLostService(oneHourAgo);
    outage.setIfRegainedService(thirtyMinutesAgo);
    m_outageDao.save(outage);
    m_outageDao.flush();
    // Verify the availability when outages are present
    euiLevel = m_availabilityService.getEuiLevel(rtcCat);
    assertEquals(1, euiLevel.getCategory().size());
    category = euiLevel.getCategory().get(0);
    // This number should only need to be adjusted if the duration of the outage
    // or the number of services in the category changes
    assertEquals(RTCUtils.getOutagePercentage(1800000, 86400000, 6), category.getCatvalue(), 0.0001);
    assertEquals(2, category.getNode().size());
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) MockNetwork(org.opennms.netmgt.mock.MockNetwork) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Date(java.util.Date) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 8 with RTCCategory

use of org.opennms.netmgt.rtc.datablock.RTCCategory in project opennms by OpenNMS.

the class DataSenderTest method testSendData.

/*
     * This doesn't work unless we have a receiver on the other end.... more of an integration test
     */
@Test
@Ignore
public void testSendData() throws IOException, FilterParseException, SAXException, SQLException, RTCException {
    InputStream stream = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/config/rtc-configuration.xml");
    RTCConfigFactory configFactory = new RTCConfigFactory(stream);
    stream.close();
    Resource categoryResource = ConfigurationTestUtils.getSpringResourceForResource(this, "/org/opennms/netmgt/config/categories.xml");
    CategoryFactory.setInstance(new CategoryFactory(categoryResource));
    stream = ConfigurationTestUtils.getInputStreamForResource(this, "/org/opennms/netmgt/config/test-database-schema.xml");
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(stream));
    stream.close();
    DataManager dataManager = new DataManager();
    String categoryName = "Database Servers";
    String categoryNameUrl = "Database+Servers";
    Category category = new Category();
    category.setLabel(categoryName);
    category.setComment("Some database servers.  Exciting, eh?");
    category.setNormalThreshold(99.0);
    category.setWarningThreshold(97.0);
    RTCCategory rtcCategory = new RTCCategory(category, categoryName);
    Map<String, RTCCategory> rtcCategories = new HashMap<String, RTCCategory>();
    rtcCategories.put(categoryName, rtcCategory);
    DataSender sender = new DataSender(dataManager, configFactory);
    sender.subscribe("http://localhost:8080/opennms-webapp/rtc/post/" + categoryNameUrl, categoryName, "rtc", "rtc");
    sender.sendData();
}
Also used : Category(org.opennms.netmgt.config.categories.Category) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) DatabaseSchemaConfigFactory(org.opennms.netmgt.config.DatabaseSchemaConfigFactory) RTCConfigFactory(org.opennms.netmgt.config.RTCConfigFactory) CategoryFactory(org.opennms.netmgt.config.CategoryFactory) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with RTCCategory

use of org.opennms.netmgt.rtc.datablock.RTCCategory in project opennms by OpenNMS.

the class AvailabilityServiceHibernateImpl method getEuiLevel.

/**
 * Optimized method for calculating the category statistics.
 *
 * We start off by retrieving outages affecting the nodes and services
 * in the given category, and group these by node id.
 *
 * Using the outages, we calculate node-level statistics
 * and tally the values to calculate the category statistics.
 */
@Override
@Transactional(readOnly = true)
public synchronized EuiLevel getEuiLevel(RTCCategory category) {
    final Header header = new Header();
    header.setVer("1.9a");
    header.setMstation("");
    // current time
    final Date curDate = new Date();
    final long curTime = curDate.getTime();
    // get the rolling window
    final long rWindow = 24L * 60L * 60L * 1000L;
    LOG.debug("Retrieving availability statistics for {} with current date: {} and rolling window: {}", category.getLabel(), curDate, rWindow);
    // create the data
    final EuiLevel level = new EuiLevel();
    // set created in m_header and add to level
    header.setCreated(EventConstants.formatToString(curDate));
    level.setHeader(header);
    final Category levelCat = new Category();
    // category label
    levelCat.setCatlabel(category.getLabel());
    double outageTimeInCategory = 0.0;
    int numServicesInCategory = 0;
    // window bounds
    final Date windowStart = new Date(curTime - rWindow);
    final Date windowEnd = new Date(curTime);
    // category specifics
    final List<Integer> nodeIds = getNodes(category);
    final List<String> serviceNames = category.getServices();
    // retrieve the outages associated with the given nodes, only retrieving those that affect our window
    final Map<Integer, List<OnmsOutage>> outagesByNode = getOutages(nodeIds, serviceNames, windowStart, windowEnd);
    // calculate the node level statistics
    for (final int nodeId : nodeIds) {
        List<OnmsOutage> outages = outagesByNode.get(nodeId);
        if (outages == null) {
            outages = Lists.newArrayList();
        }
        // sum the outage time
        final double outageTime = getOutageTimeInWindow(outages, windowStart, windowEnd);
        // determine the number of services
        final int numServices = getNumServices(nodeId, serviceNames);
        // count the number of outstanding outages
        final long numServicesDown = outages.stream().filter(outage -> outage.getIfRegainedService() == null).count();
        final Node levelNode = new Node();
        levelNode.setNodeid(nodeId);
        // value for this node for this category
        levelNode.setNodevalue(RTCUtils.getOutagePercentage(outageTime, rWindow, numServices));
        // node service count
        levelNode.setNodesvccount(numServices);
        // node service down count
        levelNode.setNodesvcdowncount(numServicesDown);
        // add the node
        levelCat.getNode().add(levelNode);
        // update the category statistics
        numServicesInCategory += numServices;
        outageTimeInCategory += outageTime;
    }
    // calculate the outage percentage using tallied values
    levelCat.setCatvalue(RTCUtils.getOutagePercentage(outageTimeInCategory, rWindow, numServicesInCategory));
    // add category
    level.getCategory().add(levelCat);
    LOG.debug("Done retrieving availability statistics for {} with {} services.", category.getLabel(), numServicesInCategory);
    return level;
}
Also used : NullRestriction(org.opennms.core.criteria.restrictions.NullRestriction) AllRestriction(org.opennms.core.criteria.restrictions.AllRestriction) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventConstants(org.opennms.netmgt.events.api.EventConstants) MonitoredServiceDao(org.opennms.netmgt.dao.api.MonitoredServiceDao) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Lists(com.google.common.collect.Lists) Map(java.util.Map) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Node(org.opennms.netmgt.xml.rtc.Node) Header(org.opennms.netmgt.xml.rtc.Header) GtRestriction(org.opennms.core.criteria.restrictions.GtRestriction) Logger(org.slf4j.Logger) OutageDao(org.opennms.netmgt.dao.api.OutageDao) FilterDao(org.opennms.netmgt.filter.api.FilterDao) Category(org.opennms.netmgt.xml.rtc.Category) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) LeRestriction(org.opennms.core.criteria.restrictions.LeRestriction) List(java.util.List) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) Preconditions(com.google.common.base.Preconditions) CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Transactional(org.springframework.transaction.annotation.Transactional) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) Category(org.opennms.netmgt.xml.rtc.Category) Node(org.opennms.netmgt.xml.rtc.Node) Date(java.util.Date) Header(org.opennms.netmgt.xml.rtc.Header) List(java.util.List) EuiLevel(org.opennms.netmgt.xml.rtc.EuiLevel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with RTCCategory

use of org.opennms.netmgt.rtc.datablock.RTCCategory in project opennms by OpenNMS.

the class DataManager method interfaceReparented.

/**
 * Reparent an interface. This effectively means updating the nodelist of
 * the categories and the map
 *
 * Use the ip/oldnodeid combination to get all nodes that will be affected -
 * for each of these nodes, remove the old entry and add a new one with new
 * keys to the map
 *
 * <em>Note:</em> Each of these nodes could belong to more than one
 * category. However, category rule evaluation is done based ONLY on the IP -
 * therefore changing the nodeID on the node should update the categories
 * appropriately
 *
 * @param ip
 *            the interface to reparent
 * @param oldNodeId
 *            the node that the IP belonged to earlier
 * @param newNodeId
 *            the node that the IP now belongs to
 */
public synchronized void interfaceReparented(InetAddress ip, int oldNodeId, int newNodeId) {
    // get all RTCNodes with the IP/old node ID
    for (RTCNode rtcN : m_map.getRTCNodes(oldNodeId, ip)) {
        // remove the node with the old node id from the map
        m_map.delete(rtcN);
        // change the node ID on the RTCNode
        rtcN.setNodeID(newNodeId);
        // now add the node with the new node ID
        m_map.add(rtcN);
        // and the new node ID
        for (String catlabel : rtcN.getCategories()) {
            RTCCategory rtcCat = m_categories.get(catlabel);
            rtcCat.deleteNode(oldNodeId);
            rtcCat.addNode(newNodeId);
        }
    }
}
Also used : RTCNode(org.opennms.netmgt.rtc.datablock.RTCNode) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory)

Aggregations

RTCCategory (org.opennms.netmgt.rtc.datablock.RTCCategory)11 EuiLevel (org.opennms.netmgt.xml.rtc.EuiLevel)6 InputStream (java.io.InputStream)3 Date (java.util.Date)3 Test (org.junit.Test)3 Category (org.opennms.netmgt.xml.rtc.Category)3 Node (org.opennms.netmgt.xml.rtc.Node)3 StringReader (java.io.StringReader)2 HashMap (java.util.HashMap)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 HttpPostInfo (org.opennms.netmgt.rtc.datablock.HttpPostInfo)2 RTCNode (org.opennms.netmgt.rtc.datablock.RTCNode)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1