@Test public void testInterfaceResourceWithDBAttributeFilter() throws Exception { Integer ifIndex = 1; Long ifSpeed = 10000000l; String ifName = "wlan0"; addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifOutOctets", ifName, ifIndex.toString()); addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString()); ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); runInterfaceResource(visitor, "127.0.0.1", ifName, ifSpeed, ifIndex, 10000, 46000); // real value = (46000 - 10000)/300 = 120 verifyEvents(0); }
private void runTestForBug2711(Integer ifIndex, Integer remainingEvents) throws Exception { Long ifSpeed = 10000000l; String ifName = "wlan0"; initFactories("/threshd-configuration.xml","/test-thresholds-2.xml"); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "SNMP", 1, 90.0, 50.0, 120.0, ifName, ifIndex.toString(), "ifOutOctets", ifName, ifIndex.toString(), m_anticipator, m_anticipatedEvents); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "SNMP", 1, 90.0, 50.0, 120.0, ifName, ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString(), m_anticipator, m_anticipatedEvents); ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); runInterfaceResource(visitor, "0.0.0.0", ifName, ifSpeed, ifIndex, 10000, 46000); // real value = (46000 - 10000)/300 = 120 verifyEvents(remainingEvents); }
@Test public void testBug3428_noMatch() throws Exception { initFactories("/threshd-configuration.xml","/test-thresholds-bug3428.xml"); Integer ifIndex = 1; Long ifSpeed = 10000000l; // 10Mbps - Bad Speed String ifName = "wlan0"; addHighThresholdEvent(1, 90, 50, 120, "Unknown", ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString()); ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); runInterfaceResource(visitor, "127.0.0.1", ifName, ifSpeed, ifIndex, 10000, 46000); // real value = (46000 - 10000)/300 = 120 verifyEvents(1); }
@Test public void testBug3428_match() throws Exception { initFactories("/threshd-configuration.xml","/test-thresholds-bug3428.xml"); Integer ifIndex = 1; Long ifSpeed = 100000000l; // 100Mbps - Correct Speed! String ifName = "wlan0"; addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString()); ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); runInterfaceResource(visitor, "127.0.0.1", ifName, ifSpeed, ifIndex, 10000, 46000); // real value = (46000 - 10000)/300 = 120 verifyEvents(0); }
@Test public void testInterfaceResourceWithStringAttributeFilter() throws Exception { Integer ifIndex = 1; Long ifSpeed = 10000000l; String ifName = "sis0"; addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifOutOctets", ifName, ifIndex.toString()); addHighThresholdEvent(1, 90, 50, 120, ifName, ifIndex.toString(), "ifInOctets", ifName, ifIndex.toString()); // Creating strings.properties file ResourcePath path = ResourcePath.get("snmp", "1", ifName); m_resourceStorageDao.setStringAttribute(path, "myMockParam", "myMockValue"); ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); runInterfaceResource(visitor, "127.0.0.1", ifName, ifSpeed, ifIndex, 10000, 46000); // real value = (46000 - 10000)/300 = 120 verifyEvents(0); }
private void runInterfaceResource(ThresholdingVisitor visitor, String ipAddress, String ifName, Long ifSpeed, Integer ifIndex, long v1, long v2) { SnmpIfData ifData = createSnmpIfData(ipAddress, ifName, ifSpeed, ifIndex, true); SnmpCollectionAgent agent = createCollectionAgent(); IfResourceType resourceType = createInterfaceResourceType(agent); // Step 1 visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime())); SnmpCollectionResource resource = new IfInfo(resourceType, agent, ifData); addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v1); addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v1); resource.visit(visitor); // Step 2 - Increment Counters visitor.visitCollectionSet(createAnonymousCollectionSet(visitor.getCollectionTimestamp().getTime()+300000)); resource = new IfInfo(resourceType, agent, ifData); addAttributeToCollectionResource(resource, resourceType, "ifInOctets", "counter", "ifIndex", v2); addAttributeToCollectionResource(resource, resourceType, "ifOutOctets", "counter", "ifIndex", v2); resource.visit(visitor); EasyMock.verify(agent); }
@Test public void testBug3554_withMockFilterDao() throws Exception { initFactories("/threshd-configuration-bug3554.xml","/test-thresholds-bug3554.xml"); // Visitor with Mock FavoriteFilterDao ThresholdingVisitor visitor = createVisitor(); visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime())); // Do nothing, just to check visitor runInterfaceResource(visitor, "127.0.0.1", "eth0", 10000000l, 1, 10000, 46000); // real value = (46000 - 10000)/300 = 120 // Do nothing, just to check visitor runGaugeDataTest(visitor, 12000); // Do nothing, just to check visitor SnmpCollectionAgent agent = createCollectionAgent(); GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "ciscoEnvMonTemperatureStatusIndex"); SnmpCollectionResource resource = new GenericIndexResource(resourceType, "ciscoEnvMonTemperatureStatusIndex", new SnmpInstId(45)); resource.visit(visitor); EasyMock.verify(agent); }
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp)); IfInfo ifInfo = new IfInfo(resourceType, agent, ifData); addAttributeToCollectionResource(ifInfo, resourceType, "ifInOctets", "counter", "ifIndex", 10000); visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp+300000)); ifInfo = new IfInfo(resourceType, agent, ifData); addAttributeToCollectionResource(ifInfo, resourceType, "ifInOctets", "counter", "ifIndex", 46000);
visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp)); BigDecimal n = new BigDecimal(Math.pow(2, bits) - 20000); SnmpValue snmpValue1 = SnmpUtils.getValueFactory().getCounter64(n.toBigInteger()); visitor.visitCollectionSet(ThresholdingVisitorIT.createAnonymousCollectionSet(timestamp+300000)); SnmpValue snmpValue2 = SnmpUtils.getValueFactory().getCounter64(new BigInteger("40000")); SnmpCollectionResource resource2 = new IfInfo(resourceType, agent, ifData);
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+300000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+600000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+300000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(5500)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+600000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(6100));
visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate)); SnmpCollectionResource resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(2000)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+300000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(20000)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+600000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(53000)); visitor.visitCollectionSet(createAnonymousCollectionSet(baseDate+900000)); resource = new NodeInfo(resourceType, agent); resource.setAttributeValue(attributeType, SnmpUtils.getValueFactory().getCounter32(65000));