/** * <p>getAddress</p> * * @return a {@link java.net.InetAddress} object. */ public InetAddress getAddress() { return m_agent.getAddress(); }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final ServiceParameters serviceParams = new ServiceParameters(parameters); final String collectionName = serviceParams.getCollectionName(); final NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); if (collection == null) { throw new IllegalArgumentException(String.format("NSClientCollector: No collection found with name '%s'.", collectionName)); } runtimeAttributes.put(NSCLIENT_COLLECTION_KEY, collection); final NSClientAgentConfig agentConfig = NSClientPeerFactory.getInstance().getAgentConfig(agent.getAddress()); runtimeAttributes.put(NSCLIENT_AGENT_CONFIG_KEY, agentConfig); return runtimeAttributes; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final ServiceParameters serviceParams = new ServiceParameters(parameters); final String collectionName = serviceParams.getCollectionName(); final NsclientCollection collection = NSClientDataCollectionConfigFactory.getInstance().getNSClientCollection(collectionName); if (collection == null) { throw new IllegalArgumentException(String.format("NSClientCollector: No collection found with name '%s'.", collectionName)); } runtimeAttributes.put(NSCLIENT_COLLECTION_KEY, collection); final NSClientAgentConfig agentConfig = NSClientPeerFactory.getInstance().getAgentConfig(agent.getAddress()); runtimeAttributes.put(NSCLIENT_AGENT_CONFIG_KEY, agentConfig); return runtimeAttributes; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final String collectionName = ParameterMap.getKeyedString(parameters, "collection", ParameterMap.getKeyedString(parameters, "wmi-collection", null)); final WmiCollection collection = WmiDataCollectionConfigFactory.getInstance().getWmiCollection(collectionName); runtimeAttributes.put(WMI_COLLECTION_KEY, collection); final WmiAgentConfig agentConfig = WmiPeerFactory.getInstance().getAgentConfig(agent.getAddress()); runtimeAttributes.put(WMI_AGENT_CONFIG_KEY, agentConfig); return runtimeAttributes; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final String collectionName = ParameterMap.getKeyedString(parameters, "collection", ParameterMap.getKeyedString(parameters, "wmi-collection", null)); final WmiCollection collection = WmiDataCollectionConfigFactory.getInstance().getWmiCollection(collectionName); runtimeAttributes.put(WMI_COLLECTION_KEY, collection); final WmiAgentConfig agentConfig = WmiPeerFactory.getInstance().getAgentConfig(agent.getAddress()); runtimeAttributes.put(WMI_AGENT_CONFIG_KEY, agentConfig); return runtimeAttributes; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final String collectionName = ParameterMap.getKeyedString(parameters, "collection", null); if (collectionName == null) { throw new IllegalArgumentException("Collector configuration does not include the required 'collection' parameter."); } final Collection collection = m_wsManDataCollectionConfigDao.getCollectionByName(collectionName); if (collection == null) { throw new IllegalArgumentException("No collection found with name: " + collectionName); } final OnmsNode node = m_nodeDao.get(agent.getNodeId()); if (node == null) { throw new IllegalArgumentException("Could not find node with id: " + agent.getNodeId()); } final Definition agentConfig = m_wsManConfigDao.getAgentConfig(agent.getAddress()); final Groups groups = new Groups(m_wsManDataCollectionConfigDao.getGroupsForAgent(collection, agent, agentConfig, node)); runtimeAttributes.put(WSMAN_AGENT_CONFIG_KEY, agentConfig); runtimeAttributes.put(WSMAN_GROUPS_KEY, groups); return runtimeAttributes; }
@Override public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) { final Map<String, Object> runtimeAttributes = new HashMap<>(); final String collectionName = ParameterMap.getKeyedString(parameters, "collection", null); if (collectionName == null) { throw new IllegalArgumentException("Collector configuration does not include the required 'collection' parameter."); } final Collection collection = m_wsManDataCollectionConfigDao.getCollectionByName(collectionName); if (collection == null) { throw new IllegalArgumentException("No collection found with name: " + collectionName); } final OnmsNode node = m_nodeDao.get(agent.getNodeId()); if (node == null) { throw new IllegalArgumentException("Could not find node with id: " + agent.getNodeId()); } final Definition agentConfig = m_wsManConfigDao.getAgentConfig(agent.getAddress()); final Groups groups = new Groups(m_wsManDataCollectionConfigDao.getGroupsForAgent(collection, agent, agentConfig, node)); runtimeAttributes.put(WSMAN_AGENT_CONFIG_KEY, agentConfig); runtimeAttributes.put(WSMAN_GROUPS_KEY, groups); return runtimeAttributes; }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { LOG.debug("collect({}, {}, {})", agent, parameters); final WsmanAgentConfig config = (WsmanAgentConfig)parameters.get(WSMAN_AGENT_CONFIG_KEY); final Groups groups = (Groups)parameters.get(WSMAN_GROUPS_KEY); final WSManEndpoint endpoint = WSManConfigDao.getEndpoint(config, agent.getAddress()); final WSManClient client = m_factory.getClient(endpoint); final CollectionSetBuilder collectionSetBuilder = new CollectionSetBuilder(agent); if (LOG.isDebugEnabled()) { String groupNames = groups.getGroups().stream().map(Group::getName).collect(Collectors.joining(", ")); LOG.debug("Collecting attributes on {} from groups: {}", agent, groupNames); } for (Group group : groups.getGroups()) { try { collectGroupUsing(group, agent, client, config.getRetry() != null ? config.getRetry() : 0, collectionSetBuilder); } catch (InvalidResourceURI e) { LOG.info("Resource URI {} in group named {} is not available on {}.", group.getResourceUri(), group.getName(), agent); } catch (WSManException e) { // If collecting any individual group fails, mark the collection set as // failed, and abort trying to collect any other groups throw new CollectionException(String.format("Collecting group '%s' on %s failed with '%s'. See logs for details.", group.getName(), agent, e.getMessage()), e); } } return collectionSetBuilder.build(); }
@Override public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException { LOG.debug("collect({}, {}, {})", agent, parameters); final WsmanAgentConfig config = (WsmanAgentConfig)parameters.get(WSMAN_AGENT_CONFIG_KEY); final Groups groups = (Groups)parameters.get(WSMAN_GROUPS_KEY); final WSManEndpoint endpoint = WSManConfigDao.getEndpoint(config, agent.getAddress()); final WSManClient client = m_factory.getClient(endpoint); final CollectionSetBuilder collectionSetBuilder = new CollectionSetBuilder(agent); if (LOG.isDebugEnabled()) { String groupNames = groups.getGroups().stream().map(Group::getName).collect(Collectors.joining(", ")); LOG.debug("Collecting attributes on {} from groups: {}", agent, groupNames); } for (Group group : groups.getGroups()) { try { collectGroupUsing(group, agent, client, config.getRetry() != null ? config.getRetry() : 0, collectionSetBuilder); } catch (InvalidResourceURI e) { LOG.info("Resource URI {} in group named {} is not available on {}.", group.getResourceUri(), group.getName(), agent); } catch (WSManException e) { // If collecting any individual group fails, mark the collection set as // failed, and abort trying to collect any other groups throw new CollectionException(String.format("Collecting group '%s' on %s failed with '%s'. See logs for details.", group.getName(), agent, e.getMessage()), e); } } return collectionSetBuilder.build(); }
private static URI buildUri(final HttpCollectorAgent collectorAgent) throws URISyntaxException { HashMap<String,String> substitutions = new HashMap<String,String>(); substitutions.put("ipaddr", InetAddressUtils.str(collectorAgent.getAgent().getAddress())); substitutions.put("nodeid", Integer.toString(collectorAgent.getAgent().getNodeId())); final URIBuilder ub = new URIBuilder(); ub.setScheme(collectorAgent.getUriDef().getUrl().getScheme()); ub.setHost(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getHost(), "getHost")); ub.setPort(collectorAgent.getPort()); ub.setPath(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getPath(), "getURL")); final String query = substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getQuery().orElse(null), "getQuery"); if (query != null) { final List<NameValuePair> params = URLEncodedUtils.parse(query, StandardCharsets.UTF_8); ub.setParameters(params); } ub.setFragment(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getFragment().orElse(null), "getFragment")); return ub.build(); }
private static URI buildUri(final HttpCollectorAgent collectorAgent) throws URISyntaxException { HashMap<String,String> substitutions = new HashMap<String,String>(); substitutions.put("ipaddr", InetAddressUtils.str(collectorAgent.getAgent().getAddress())); substitutions.put("nodeid", Integer.toString(collectorAgent.getAgent().getNodeId())); final URIBuilder ub = new URIBuilder(); ub.setScheme(collectorAgent.getUriDef().getUrl().getScheme()); ub.setHost(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getHost(), "getHost")); ub.setPort(collectorAgent.getPort()); ub.setPath(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getPath(), "getURL")); final String query = substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getQuery().orElse(null), "getQuery"); if (query != null) { final List<NameValuePair> params = URLEncodedUtils.parse(query, StandardCharsets.UTF_8); ub.setParameters(params); } ub.setFragment(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getFragment().orElse(null), "getFragment")); return ub.build(); }
/** * <p>createForceResanEvent</p> * * @return a {@link org.opennms.netmgt.xml.event.Event} object. */ public Event createForceRescanEvent() { // create the event to be sent EventBuilder bldr = new EventBuilder(EventConstants.FORCE_RESCAN_EVENT_UEI, "SnmpCollector"); bldr.setNodeid(m_agent.getNodeId()); bldr.setInterface(m_agent.getAddress()); bldr.setService(AbstractSnmpCollector.SERVICE_NAME); bldr.setHost(InetAddressUtils.getLocalHostName()); return bldr.getEvent(); }
/** * This is the main method of the class. An instance is normally enqueued on * the scheduler which checks its <code>isReady</code> method to determine * execution. If the instance is ready for execution then it is started with * it's own thread context to execute the query. The last step in the method * before it exits is to reschedule the interface. */ @Override public void run() { Logging.withPrefix(Collectd.LOG4J_CATEGORY, () -> { Logging.putThreadContext("service", m_spec.getServiceName()); Logging.putThreadContext("ipAddress", m_agent.getAddress().getHostAddress()); Logging.putThreadContext("nodeId", Integer.toString(m_agent.getNodeId())); Logging.putThreadContext("nodeLabel", m_agent.getNodeLabel()); Logging.putThreadContext("foreignSource", m_agent.getForeignSource()); Logging.putThreadContext("foreignId", m_agent.getForeignId()); doRun(); }); }
public CollectionAgentDTO(CollectionAgent agent) { Objects.requireNonNull(agent); for (String attribute : agent.getAttributeNames()) { setAttribute(attribute, agent.getAttribute(attribute)); } address = agent.getAddress(); storeByForeignSource = agent.isStoreByForeignSource(); nodeId = agent.getNodeId(); nodeLabel = agent.getNodeLabel(); foreignSource = agent.getForeignSource(); foreignId = agent.getForeignId(); location = agent.getLocationName(); setStorageResourcePath(agent.getStorageResourcePath()); sysUpTime = agent.getSavedSysUpTime(); }
/** * Generate event and send it to eventd via the event proxy. * * uei Universal event identifier of event to generate. */ private void sendEvent(String uei, String reason) { EventBuilder builder = new EventBuilder(uei, "OpenNMS.Collectd"); builder.setNodeid(m_nodeId); builder.setInterface(m_agent.getAddress()); builder.setService(m_spec.getServiceName()); builder.setHost(InetAddressUtils.getLocalHostName()); if (reason != null) { builder.addParam("reason", reason); } // Send the event try { EventIpcManagerFactory.getIpcManager().sendNow(builder.getEvent()); LOG.debug("sendEvent: Sent event {} for {}/{}/{}", uei, m_nodeId, getHostAddress(), getServiceName()); } catch (Throwable e) { LOG.error("Failed to send the event {} for interface {}", uei, getHostAddress(), e); } }
assertEquals(iface.getIpAddress(), agent.getAddress()); assertEquals(node.getId().intValue(), agent.getNodeId());
NSClientAgentState agentState = new NSClientAgentState(agent.getAddress(), parameters, agentConfig);
final WmiAgentState agentState = new WmiAgentState(agent.getAddress(), agentConfig, parameters);
NSClientAgentState agentState = new NSClientAgentState(agent.getAddress(), parameters, agentConfig);
final WmiAgentState agentState = new WmiAgentState(agent.getAddress(), agentConfig, parameters);