protected final OnmsIpInterface getIpInterface() { return m_ifaceDao.load(m_ifaceId); }
protected final OnmsIpInterface getIpInterface() { return m_ifaceDao.load(m_ifaceId); }
private void setupInterface(OnmsIpInterface iface) { expect(m_ipIfDao.findByServiceType("SNMP")).andReturn(Collections.singletonList(iface)); expect(m_ipIfDao.load(iface.getId())).andReturn(iface).atLeastOnce(); }
@Test public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException { // create the agent OnmsNode node = mock(OnmsNode.class); OnmsIpInterface iface = mock(OnmsIpInterface.class); when(iface.getNode()).thenReturn(node); when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress()); IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); when(ifaceDao.load(1)).thenReturn(iface); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); final CollectionAgent agent = createAgent(1, ifaceDao, transMgr); // init() should execute without any exceptions final ServiceCollector opennmsCollector = getCollector(); initialize(opennmsCollector); // getEffectiveLocation() should execute without any exceptions // in this context there are no requirements on its return value final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID; opennmsCollector.getEffectiveLocation(targetLocation); // getRuntimeAttributes() should return a valid map final Map<String, Object> requiredParams = getRequiredParameters(); final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams)); // collect() should return a valid collection set final Map<String, Object> allParms = new HashMap<>(); allParms.putAll(requiredParams); allParms.putAll(runtimeAttrs); final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms)); assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); // getRrdRepository() should return a valid repository assertNotNull(opennmsCollector.getRrdRepository(getCollectionName())); }
@Test public void canCollectUsingOpenNMSWorkflow() throws CollectionInitializationException, CollectionException { // create the agent OnmsNode node = mock(OnmsNode.class); OnmsIpInterface iface = mock(OnmsIpInterface.class); when(iface.getNode()).thenReturn(node); when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress()); IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); when(ifaceDao.load(1)).thenReturn(iface); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); final CollectionAgent agent = createAgent(1, ifaceDao, transMgr); // init() should execute without any exceptions final ServiceCollector opennmsCollector = getCollector(); initialize(opennmsCollector); // getEffectiveLocation() should execute without any exceptions // in this context there are no requirements on its return value final String targetLocation = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID; opennmsCollector.getEffectiveLocation(targetLocation); // getRuntimeAttributes() should return a valid map final Map<String, Object> requiredParams = getRequiredParameters(); final Map<String, Object> runtimeAttrs = opennmsCollector.getRuntimeAttributes(agent, Collections.unmodifiableMap(requiredParams)); // collect() should return a valid collection set final Map<String, Object> allParms = new HashMap<>(); allParms.putAll(requiredParams); allParms.putAll(runtimeAttrs); final CollectionSet collectionSet = opennmsCollector.collect(agent, Collections.unmodifiableMap(allParms)); assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus()); // getRrdRepository() should return a valid repository assertNotNull(opennmsCollector.getRrdRepository(getCollectionName())); }
when(ifaceDao.load(1)).thenReturn(iface); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); final CollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
when(ifaceDao.load(1)).thenReturn(iface); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); final CollectionAgent agent = DefaultCollectionAgent.create(1, ifaceDao, transMgr);
private void createCollectableService() throws CollectionInitializationException, IOException { // Mock it all! OnmsIpInterface iface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS); IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); spec = mock(CollectionSpecification.class); scheduler = mock(Scheduler.class); SchedulingCompletedFlag schedulingCompletedFlag = mock(SchedulingCompletedFlag.class); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); RrdPersisterFactory persisterFactory = new RrdPersisterFactory(); persisterFactory.setRrdStrategy(rrdStrategy); ResourceStorageDao resourceStorageDao = mock(ResourceStorageDao.class); // Disable thresholding Map<String, Object> paramsMap = new HashMap<>(); paramsMap.put("thresholding-enabled", Boolean.FALSE.toString()); ServiceParameters params = new ServiceParameters(paramsMap); when(iface.getNode().getId()).thenReturn(1); when(spec.getServiceParameters()).thenReturn(params); when(spec.getRrdRepository(any())).thenReturn(createRrdRepository()); when(ifaceDao.load(any())).thenReturn(iface); when(iface.getIpAddress()).thenReturn(InetAddrUtils.getLocalHostAddress()); service = new CollectableService(iface, ifaceDao, spec, scheduler, schedulingCompletedFlag, transMgr, persisterFactory, resourceStorageDao); }
/** * Verifies that the SNMP agent configuration is retrieved using * the location name that is associated with the interface/node. */ @Test public void canGetLocationAwareAgentConfig() { // Mock the peer factory SnmpPeerFactory snmpPeerFactory = mock(SnmpPeerFactory.class); SnmpPeerFactory.setInstance(snmpPeerFactory); // Mock the other arguments required to create a DefaultCollectionAgent Integer ifaceId = 1; IpInterfaceDao ifaceDao = mock(IpInterfaceDao.class); PlatformTransactionManager transMgr = mock(PlatformTransactionManager.class); OnmsIpInterface ipIface = mock(OnmsIpInterface.class, RETURNS_DEEP_STUBS); when(ifaceDao.load(ifaceId)).thenReturn(ipIface); when(ipIface.getNode().getLocation().getLocationName()).thenReturn("Ocracoke"); // Retrieve the agent configuration SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(ifaceId, ifaceDao, transMgr); agent.getAgentConfig(); // Verify verify(snmpPeerFactory, times(1)).getAgentConfig(any(), eq("Ocracoke")); }
@Before public void setUp() throws Exception { MockLogAppender.setupLogging(); m_rrdStrategy = new JRobinRrdStrategy(); m_fileAnticipator = new FileAnticipator(); m_intf = new OnmsIpInterface(); m_node = new OnmsNode(); m_node.setId(1); m_intf.setNode(m_node); m_intf.setIpAddress(InetAddressUtils.addr("1.1.1.1")); m_intf.setId(27); m_ifDao = EasyMock.createMock(IpInterfaceDao.class); EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes(); EasyMock.replay(m_ifDao); }
EasyMock.expect(ifaceDao.load(iface.getId())).andReturn(iface).times(5); EasyMock.replay(ifaceDao);
private SnmpAttribute buildStringAttribute() { EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes(); m_easyMockUtils.replayAll(); SnmpCollectionAgent agent = DefaultSnmpCollectionAgent.create(m_intf.getId(), m_ifDao, m_transMgr); MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig(); OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient); NodeResourceType resourceType = new NodeResourceType(agent, collection); SnmpCollectionResource resource = new NodeInfo(resourceType, agent); MibObject mibObject = new MibObject(); mibObject.setOid(".1.1.1.1"); mibObject.setAlias("mibObjectAlias"); mibObject.setType("string"); mibObject.setInstance("0"); mibObject.setMaxval(null); mibObject.setMinval(null); SnmpAttributeType attributeType = new StringAttributeType(resourceType, "some-collection", mibObject, new AttributeGroupType("mibGroup", AttributeGroupType.IF_TYPE_IGNORE)); return new SnmpAttribute(resource, attributeType, SnmpUtils.getValueFactory().getOctetString("foo".getBytes())); }
protected void createAgent(int ifIndex, PrimaryType ifCollType) { m_node = new OnmsNode(); m_node.setSysObjectId(".1.2.3.4.5.6.7"); OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(m_node, ifIndex); m_iface = new OnmsIpInterface(); m_iface.setId(123); m_iface.setIpAddress(myLocalHost()); m_iface.setIsSnmpPrimary(ifCollType); m_iface.setSnmpInterface(snmpIface); m_node.addIpInterface(m_iface); EasyMock.expect(m_ifaceDao.load(m_iface.getId())).andReturn(m_iface).anyTimes(); m_easyMockUtils.replayAll(); m_agent = DefaultSnmpCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager()); }
EasyMock.expect(m_ifaceDao.load(2)).andReturn(ifaceBlder.getInterface()).anyTimes();
ipInterface.setIpAddress(InetAddressUtils.addr("192.168.1.1")); expect(m_ipInterfaceDao.load(1)).andReturn(ipInterface).times(5); // It used to be 3, but I think it is more correct to use getStoreDir from DefaultCollectionAgentService on DefaultCollectionAgent (NMS-7516)
node.setId(1); OnmsIpInterface ipInterface = node.getIpInterfaces().iterator().next(); EasyMock.expect(ipInterfaceDao.load(1)).andReturn(ipInterface).anyTimes(); EasyMock.replay(ipInterfaceDao);