@Test public void testCollector() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("port", getServer().getLocalPort()); NSClientCollector collector = getCollector(parameters); CollectionSet collectionSet = collector.collect(m_collectionAgent, m_eventProxy, parameters); Assert.assertEquals(ServiceCollector.COLLECTION_SUCCEEDED, collectionSet.getStatus()); CountResourcesVisitor visitor = new CountResourcesVisitor(); collectionSet.visit(visitor); Assert.assertEquals(42, visitor.getCount()); }
@Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters) { int status = ServiceCollector.COLLECTION_FAILED; final ServiceParameters serviceParams = new ServiceParameters(parameters); String collectionName = serviceParams.getCollectionName(); NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); NSClientAgentState agentState = m_scheduledNodes.get(agent.getNodeId()); NSClientCollectionSet collectionSet=new NSClientCollectionSet(agent, new Date()); NSClientCollectionResource collectionResource=collectionSet.getResource(); for (Wpm wpm : collection.getWpms().getWpm()) { AttributeGroupType attribGroupType=new AttributeGroupType(wpm.getName(),"all"); if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) { log().debug("Checking availability of group " + wpm.getName()); NsclientManager manager = null; try { manager = agentState.getManager(); manager.init(); NsclientCheckParams params = new NsclientCheckParams(wpm.getKeyvalue()); NsclientPacket result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); manager.close(); boolean isAvailable = (result.getResultCode() == NsclientPacket.RES_STATE_OK); agentState.setGroupIsAvailable(wpm.getName(), isAvailable); log().debug("Group "+wpm.getName()+" is "+(isAvailable?"":"not")+"available "); } catch (NsclientException e) { log().error("Error checking group (" + wpm.getName() + ") availability", e); agentState.setGroupIsAvailable(wpm.getName(), false); } finally { if (manager != null) { manager.close(); } } } if (agentState.groupIsAvailable(wpm.getName())) { try { NsclientManager manager = agentState.getManager(); manager.init(); for (Attrib attrib : wpm.getAttrib()) { NsclientPacket result = null; try { NsclientCheckParams params = new NsclientCheckParams(attrib.getName()); result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); } catch (NsclientException e) { log().info("unable to collect params for attribute '" + attrib.getName() + "'", e); } if (result != null) { if (result.getResultCode() != NsclientPacket.RES_STATE_OK) { log().info("not writing parameters for attribute '" + attrib.getName() + "', state is not 'OK'"); } else { NSClientCollectionAttributeType attribType=new NSClientCollectionAttributeType(attrib, attribGroupType); collectionResource.setAttributeValue(attribType, result.getResponse()); status = ServiceCollector.COLLECTION_SUCCEEDED; } } } manager.close(); } catch (NsclientException e) { log().error("Error collecting data", e); } } } collectionSet.setStatus(status); return collectionSet; }
NSClientCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters) { int status = ServiceCollector.COLLECTION_FAILED; final ServiceParameters serviceParams = new ServiceParameters(parameters); String collectionName = serviceParams.getCollectionName(); NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); NSClientAgentState agentState = m_scheduledNodes.get(agent.getNodeId()); NSClientCollectionSet collectionSet=new NSClientCollectionSet(agent, new Date()); NSClientCollectionResource collectionResource=collectionSet.getResource(); for (Wpm wpm : collection.getWpms().getWpm()) { AttributeGroupType attribGroupType=new AttributeGroupType(wpm.getName(),"all"); if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) { log().debug("Checking availability of group " + wpm.getName()); NsclientManager manager = null; try { manager = agentState.getManager(); manager.init(); NsclientCheckParams params = new NsclientCheckParams(wpm.getKeyvalue()); NsclientPacket result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); manager.close(); boolean isAvailable = (result.getResultCode() == NsclientPacket.RES_STATE_OK); agentState.setGroupIsAvailable(wpm.getName(), isAvailable); log().debug("Group "+wpm.getName()+" is "+(isAvailable?"":"not")+"available "); } catch (NsclientException e) { log().error("Error checking group (" + wpm.getName() + ") availability", e); agentState.setGroupIsAvailable(wpm.getName(), false); } finally { if (manager != null) { manager.close(); } } } if (agentState.groupIsAvailable(wpm.getName())) { try { NsclientManager manager = agentState.getManager(); manager.init(); for (Attrib attrib : wpm.getAttrib()) { NsclientPacket result = null; try { NsclientCheckParams params = new NsclientCheckParams(attrib.getName()); result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); } catch (NsclientException e) { log().info("unable to collect params for attribute '" + attrib.getName() + "'", e); } if (result != null) { if (result.getResultCode() != NsclientPacket.RES_STATE_OK) { log().info("not writing parameters for attribute '" + attrib.getName() + "', state is not 'OK'"); } else { NSClientCollectionAttributeType attribType=new NSClientCollectionAttributeType(attrib, attribGroupType); collectionResource.setAttributeValue(attribType, result.getResponse()); status = ServiceCollector.COLLECTION_SUCCEEDED; } } } manager.close(); } catch (NsclientException e) { log().error("Error collecting data", e); } } } collectionSet.setStatus(status); return collectionSet; } }
NSClientCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters) { int status = ServiceCollector.COLLECTION_FAILED; final ServiceParameters serviceParams = new ServiceParameters(parameters); String collectionName = serviceParams.getCollectionName(); NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); NSClientAgentState agentState = m_scheduledNodes.get(agent.getNodeId()); NSClientCollectionSet collectionSet=new NSClientCollectionSet(agent, new Date()); NSClientCollectionResource collectionResource=collectionSet.getResource(); for (Wpm wpm : collection.getWpms().getWpm()) { AttributeGroupType attribGroupType=new AttributeGroupType(wpm.getName(),"all"); if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) { log().debug("Checking availability of group " + wpm.getName()); NsclientManager manager = null; try { manager = agentState.getManager(); manager.init(); NsclientCheckParams params = new NsclientCheckParams(wpm.getKeyvalue()); NsclientPacket result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); manager.close(); boolean isAvailable = (result.getResultCode() == NsclientPacket.RES_STATE_OK); agentState.setGroupIsAvailable(wpm.getName(), isAvailable); log().debug("Group "+wpm.getName()+" is "+(isAvailable?"":"not")+"available "); } catch (NsclientException e) { log().error("Error checking group (" + wpm.getName() + ") availability", e); agentState.setGroupIsAvailable(wpm.getName(), false); } finally { if (manager != null) { manager.close(); } } } if (agentState.groupIsAvailable(wpm.getName())) { try { NsclientManager manager = agentState.getManager(); manager.init(); for (Attrib attrib : wpm.getAttrib()) { NsclientPacket result = null; try { NsclientCheckParams params = new NsclientCheckParams(attrib.getName()); result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); } catch (NsclientException e) { log().info("unable to collect params for attribute '" + attrib.getName() + "'", e); } if (result != null) { if (result.getResultCode() != NsclientPacket.RES_STATE_OK) { log().info("not writing parameters for attribute '" + attrib.getName() + "', state is not 'OK'"); } else { NSClientCollectionAttributeType attribType=new NSClientCollectionAttributeType(attrib, attribGroupType); collectionResource.setAttributeValue(attribType, result.getResponse()); status = ServiceCollector.COLLECTION_SUCCEEDED; } } } manager.close(); } catch (NsclientException e) { log().error("Error collecting data", e); } } } collectionSet.setStatus(status); return collectionSet; }  }
NSClientCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters) { int status = ServiceCollector.COLLECTION_FAILED; final ServiceParameters serviceParams = new ServiceParameters(parameters); String collectionName = serviceParams.getCollectionName(); NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); NSClientAgentState agentState = m_scheduledNodes.get(agent.getNodeId()); NSClientCollectionSet collectionSet=new NSClientCollectionSet(agent, new Date()); NSClientCollectionResource collectionResource=collectionSet.getResource(); for (Wpm wpm : collection.getWpms().getWpm()) { AttributeGroupType attribGroupType=new AttributeGroupType(wpm.getName(),"all"); if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) { log().debug("Checking availability of group " + wpm.getName()); NsclientManager manager = null; try { manager = agentState.getManager(); manager.init(); NsclientCheckParams params = new NsclientCheckParams(wpm.getKeyvalue()); NsclientPacket result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); manager.close(); boolean isAvailable = (result.getResultCode() == NsclientPacket.RES_STATE_OK); agentState.setGroupIsAvailable(wpm.getName(), isAvailable); log().debug("Group "+wpm.getName()+" is "+(isAvailable?"":"not")+"available "); } catch (NsclientException e) { log().error("Error checking group (" + wpm.getName() + ") availability", e); agentState.setGroupIsAvailable(wpm.getName(), false); } finally { if (manager != null) { manager.close(); } } } if (agentState.groupIsAvailable(wpm.getName())) { try { NsclientManager manager = agentState.getManager(); manager.init(); for (Attrib attrib : wpm.getAttrib()) { NsclientPacket result = null; try { NsclientCheckParams params = new NsclientCheckParams(attrib.getName()); result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); } catch (NsclientException e) { log().info("unable to collect params for attribute '" + attrib.getName() + "'", e); } if (result != null) { if (result.getResultCode() != NsclientPacket.RES_STATE_OK) { log().info("not writing parameters for attribute '" + attrib.getName() + "', state is not 'OK'"); } else { NSClientCollectionAttributeType attribType=new NSClientCollectionAttributeType(attrib, attribGroupType); collectionResource.setAttributeValue(attribType, result.getResponse()); status = ServiceCollector.COLLECTION_SUCCEEDED; } } } manager.close(); } catch (NsclientException e) { log().error("Error collecting data", e); } } } collectionSet.setStatus(status); return collectionSet; }  @Override CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters); @Override void initialize(Map<String, String> parameters); @Override void initialize(CollectionAgent agent, Map<String, Object> parameters); @Override void release(); @Override void release(final CollectionAgent agent); @Override RrdRepository getRrdRepository(String collectionName); }
NSClientCollector implements ServiceCollector { @Override public CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters) { int status = ServiceCollector.COLLECTION_FAILED; final ServiceParameters serviceParams = new ServiceParameters(parameters); String collectionName = serviceParams.getCollectionName(); NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); NSClientAgentState agentState = m_scheduledNodes.get(agent.getNodeId()); NSClientCollectionSet collectionSet=new NSClientCollectionSet(agent, new Date()); NSClientCollectionResource collectionResource=collectionSet.getResource(); for (Wpm wpm : collection.getWpms().getWpm()) { AttributeGroupType attribGroupType=new AttributeGroupType(wpm.getName(),"all"); if (agentState.shouldCheckAvailability(wpm.getName(), wpm.getRecheckInterval())) { log().debug("Checking availability of group " + wpm.getName()); NsclientManager manager = null; try { manager = agentState.getManager(); manager.init(); NsclientCheckParams params = new NsclientCheckParams(wpm.getKeyvalue()); NsclientPacket result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); manager.close(); boolean isAvailable = (result.getResultCode() == NsclientPacket.RES_STATE_OK); agentState.setGroupIsAvailable(wpm.getName(), isAvailable); log().debug("Group "+wpm.getName()+" is "+(isAvailable?"":"not")+"available "); } catch (NsclientException e) { log().error("Error checking group (" + wpm.getName() + ") availability", e); agentState.setGroupIsAvailable(wpm.getName(), false); } finally { if (manager != null) { manager.close(); } } } if (agentState.groupIsAvailable(wpm.getName())) { try { NsclientManager manager = agentState.getManager(); manager.init(); for (Attrib attrib : wpm.getAttrib()) { NsclientPacket result = null; try { NsclientCheckParams params = new NsclientCheckParams(attrib.getName()); result = manager.processCheckCommand(NsclientManager.CHECK_COUNTER, params); } catch (NsclientException e) { log().info("unable to collect params for attribute '" + attrib.getName() + "'", e); } if (result != null) { if (result.getResultCode() != NsclientPacket.RES_STATE_OK) { log().info("not writing parameters for attribute '" + attrib.getName() + "', state is not 'OK'"); } else { NSClientCollectionAttributeType attribType=new NSClientCollectionAttributeType(attrib, attribGroupType); collectionResource.setAttributeValue(attribType, result.getResponse()); status = ServiceCollector.COLLECTION_SUCCEEDED; } } } manager.close(); } catch (NsclientException e) { log().error("Error collecting data", e); } } } collectionSet.setStatus(status); return collectionSet; }  @Override CollectionSet collect(CollectionAgent agent, EventProxy eproxy, Map<String, Object> parameters); @Override void initialize(Map<String, String> parameters); @Override void initialize(CollectionAgent agent, Map<String, Object> parameters); @Override void release(); @Override void release(final CollectionAgent agent); @Override RrdRepository getRrdRepository(String collectionName);  }