public WSManEndpoint build() { return new WSManEndpoint(this); } }
public boolean isBasicAuth() { return !isGSSAuth() && username != null; }
public String toString() { return String.format("WSManEndpoint[url='%s', isGSSAuth='%s', isBasicAuth='%s', isStrictSSL='%s', " + "serverVersion='%s', maxElements='%s', maxEnvelopeSize='%s'" + "connectionTimeout='%s', receiveTimeout='%s']", url, isGSSAuth(), isBasicAuth(), isStrictSSL(), serverVersion, maxElements, maxEnvelopeSize, connectionTimeout, receiveTimeout); } }
public static Map<String, String> toMap(WSManEndpoint endpoint) { Map<String, String> attributes = new HashMap<>(); attributes.put(URL, endpoint.getUrl().toString()); attributes.put(SERVER_VERSION, endpoint.getServerVersion().toString()); attributes.put(GSS_AUTH, Boolean.toString(endpoint.isGSSAuth())); attributes.put(STRICT_SSL, Boolean.toString(endpoint.isStrictSSL())); if (endpoint.isBasicAuth()) { attributes.put(USERNAME, endpoint.getUsername()); attributes.put(PASSWORD, endpoint.getPassword()); } if (endpoint.getConnectionTimeout() != null) { attributes.put(CONNECTION_TIMEOUT, endpoint.getConnectionTimeout().toString()); } if (endpoint.getMaxElements() != null) { attributes.put(MAX_ELEMENTS, endpoint.getMaxElements().toString()); } if (endpoint.getMaxEnvelopeSize() != null) { attributes.put(MAX_ENVELOPE_SIZE, endpoint.getMaxEnvelopeSize().toString()); } if (endpoint.getReceiveTimeout() != null) { attributes.put(RECEIVE_TIMEOUT, endpoint.getReceiveTimeout().toString()); } return attributes; }
public static WSManEndpoint fromMap(Map<String, String> attributes) throws MalformedURLException { WSManEndpoint.Builder builder = new WSManEndpoint.Builder(attributes.get(URL)); builder.withServerVersion(WSManVersion.valueOf(attributes.get(SERVER_VERSION))); if (Boolean.parseBoolean(attributes.get(GSS_AUTH))) { builder.withGSSAuth(); } builder.withStrictSSL(Boolean.parseBoolean(attributes.get(STRICT_SSL))); if (attributes.containsKey(USERNAME)) { builder.withBasicAuth(attributes.get(USERNAME), attributes.get(PASSWORD)); } if (attributes.containsKey(CONNECTION_TIMEOUT)) { builder.withConnectionTimeout(Integer.parseInt(attributes.get(CONNECTION_TIMEOUT))); } if (attributes.containsKey(MAX_ELEMENTS)) { builder.withMaxElements(Integer.parseInt(attributes.get(MAX_ELEMENTS))); } if (attributes.containsKey(MAX_ENVELOPE_SIZE)) { builder.withMaxEnvelopeSize(Integer.parseInt(attributes.get(MAX_ENVELOPE_SIZE))); } if (attributes.containsKey(RECEIVE_TIMEOUT)) { builder.withReceiveTimeout(Integer.parseInt(attributes.get(RECEIVE_TIMEOUT))); } return builder.build(); }
final WSManClient client = m_factory.getClient(endpoint); final RetryNTimesLoop retryLoop = new RetryNTimesLoop(config.getRetry() != null ? config.getRetry() : 0); while (retryLoop.shouldContinue()) { try { node = client.get(resourceUri, selectors); break; } catch (WSManException e) { retryLoop.takeException(e); return PollStatus.down(e.getMessage()); final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node); try { ResponseHandlingUtils.getMatchingIndex(rule, elementValues);
RetryNTimesLoop retryLoop = new RetryNTimesLoop(retries); while (retryLoop.shouldContinue()) { try { if (group.getFilter() == null) { LOG.debug("Enumerating and pulling {} on {}.", group.getResourceUri(), client); client.enumerateAndPull(group.getResourceUri(), nodes, true); } else { LOG.debug("Enumerating and pulling {} with dialect {} and filter {} on {}.", group.getResourceUri(), group.getDialect(), group.getFilter(), client); client.enumerateAndPullUsingFilter(group.getResourceUri(), group.getDialect(), group.getFilter(), nodes, true); retryLoop.takeException(e);
public DetectResults isServiceDetected(InetAddress address, WSManEndpoint endpoint) { // Issue the "Identify" request final WSManClient client = m_factory.getClient(endpoint); Identity identity = null; final Map<String, String> attributes = new HashMap<>(); try { identity = client.identify(); LOG.info("Identify succeeded for address {} with product vendor '{}' and product version '{}'.", address, identity.getProductVendor(), identity.getProductVersion()); attributes.put(UPDATE_ASSETS, Boolean.toString(m_updateAssets)); attributes.put(PRODUCT_VENDOR, identity.getProductVendor()); attributes.put(PRODUCT_VERSION, identity.getProductVersion()); } catch (WSManException e) { LOG.info("Identify failed for address {} with endpoint {}.", address, endpoint, e); } return new DetectResultsImpl(identity != null, attributes); }
public DetectResults isServiceDetected(InetAddress address, WSManEndpoint endpoint) { // Issue the query! List<Node> nodes = Lists.newLinkedList(); final WSManClient client = m_factory.getClient(endpoint); try { LOG.debug("Issuing an ENUM on '{}' with query '{}'", resourceUri, wql); client.enumerateAndPullUsingFilter(resourceUri, WSManConstants.XML_NS_WQL_DIALECT, wql, nodes, true); } catch (WSManException e) { LOG.debug("ENUM failed for address '{}' with endpoint '{}', resourceUri '{}', query '{}'", address, endpoint, resourceUri, wql, e); } return new DetectResultsImpl(nodes.size() > 0); }
wqls.add(wqlobj.getWql()); resourceUris.add(wqlobj.getResourceUri()); client.enumerateAndPullUsingFilter(wqlobj.getResourceUri(), WSManConstants.XML_NS_WQL_DIALECT, wqlobj.getWql(), nodes, true); if (!nodes.isEmpty()) { values.add(nodes.get(0).getTextContent()); LOG.debug("fetchWsManAssetString: Failed to fetch any WsMan values for endpoint {}", endpoint.getUrl()); throw new MissingFormatArgumentException("fetchWsManAssetString: Failed to fetch any WsMan values for endpoint " + endpoint.getUrl()); } else { LOG.debug("fetchWsManAssetString: Fetched asset properties from WsMan agent:\n {}", formatPropertiesAsString(substitutions));
@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(); }
public static Map<String, String> toMap(WSManEndpoint endpoint) { Map<String, String> attributes = new HashMap<>(); attributes.put(URL, endpoint.getUrl().toString()); attributes.put(SERVER_VERSION, endpoint.getServerVersion().toString()); attributes.put(GSS_AUTH, Boolean.toString(endpoint.isGSSAuth())); attributes.put(STRICT_SSL, Boolean.toString(endpoint.isStrictSSL())); if (endpoint.isBasicAuth()) { attributes.put(USERNAME, endpoint.getUsername()); attributes.put(PASSWORD, endpoint.getPassword()); } if (endpoint.getConnectionTimeout() != null) { attributes.put(CONNECTION_TIMEOUT, endpoint.getConnectionTimeout().toString()); } if (endpoint.getMaxElements() != null) { attributes.put(MAX_ELEMENTS, endpoint.getMaxElements().toString()); } if (endpoint.getMaxEnvelopeSize() != null) { attributes.put(MAX_ENVELOPE_SIZE, endpoint.getMaxEnvelopeSize().toString()); } if (endpoint.getReceiveTimeout() != null) { attributes.put(RECEIVE_TIMEOUT, endpoint.getReceiveTimeout().toString()); } return attributes; }
public static WSManEndpoint fromMap(Map<String, String> attributes) throws MalformedURLException { WSManEndpoint.Builder builder = new WSManEndpoint.Builder(attributes.get(URL)); builder.withServerVersion(WSManVersion.valueOf(attributes.get(SERVER_VERSION))); if (Boolean.parseBoolean(attributes.get(GSS_AUTH))) { builder.withGSSAuth(); } builder.withStrictSSL(Boolean.parseBoolean(attributes.get(STRICT_SSL))); if (attributes.containsKey(USERNAME)) { builder.withBasicAuth(attributes.get(USERNAME), attributes.get(PASSWORD)); } if (attributes.containsKey(CONNECTION_TIMEOUT)) { builder.withConnectionTimeout(Integer.parseInt(attributes.get(CONNECTION_TIMEOUT))); } if (attributes.containsKey(MAX_ELEMENTS)) { builder.withMaxElements(Integer.parseInt(attributes.get(MAX_ELEMENTS))); } if (attributes.containsKey(MAX_ENVELOPE_SIZE)) { builder.withMaxEnvelopeSize(Integer.parseInt(attributes.get(MAX_ENVELOPE_SIZE))); } if (attributes.containsKey(RECEIVE_TIMEOUT)) { builder.withReceiveTimeout(Integer.parseInt(attributes.get(RECEIVE_TIMEOUT))); } return builder.build(); }
final WSManClient client = m_factory.getClient(endpoint); final RetryNTimesLoop retryLoop = new RetryNTimesLoop(config.getRetry() != null ? config.getRetry() : 0); while (retryLoop.shouldContinue()) { try { node = client.get(resourceUri, selectors); break; } catch (WSManException e) { retryLoop.takeException(e); return PollStatus.down(e.getMessage()); final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node); try { ResponseHandlingUtils.getMatchingIndex(rule, elementValues);
RetryNTimesLoop retryLoop = new RetryNTimesLoop(retries); while (retryLoop.shouldContinue()) { try { if (group.getFilter() == null) { LOG.debug("Enumerating and pulling {} on {}.", group.getResourceUri(), client); client.enumerateAndPull(group.getResourceUri(), nodes, true); } else { LOG.debug("Enumerating and pulling {} with dialect {} and filter {} on {}.", group.getResourceUri(), group.getDialect(), group.getFilter(), client); client.enumerateAndPullUsingFilter(group.getResourceUri(), group.getDialect(), group.getFilter(), nodes, true); retryLoop.takeException(e);
public DetectResults isServiceDetected(InetAddress address, WSManEndpoint endpoint) { // Issue the "Identify" request final WSManClient client = m_factory.getClient(endpoint); Identity identity = null; final Map<String, String> attributes = new HashMap<>(); try { identity = client.identify(); LOG.info("Identify succeeded for address {} with product vendor '{}' and product version '{}'.", address, identity.getProductVendor(), identity.getProductVersion()); attributes.put(UPDATE_ASSETS, Boolean.toString(m_updateAssets)); attributes.put(PRODUCT_VENDOR, identity.getProductVendor()); attributes.put(PRODUCT_VERSION, identity.getProductVersion()); } catch (WSManException e) { LOG.info("Identify failed for address {} with endpoint {}.", address, endpoint, e); } return new DetectResultsImpl(identity != null, attributes); }
public DetectResults isServiceDetected(InetAddress address, WSManEndpoint endpoint) { // Issue the query! List<Node> nodes = Lists.newLinkedList(); final WSManClient client = m_factory.getClient(endpoint); try { LOG.debug("Issuing an ENUM on '{}' with query '{}'", resourceUri, wql); client.enumerateAndPullUsingFilter(resourceUri, WSManConstants.XML_NS_WQL_DIALECT, wql, nodes, true); } catch (WSManException e) { LOG.debug("ENUM failed for address '{}' with endpoint '{}', resourceUri '{}', query '{}'", address, endpoint, resourceUri, wql, e); } return new DetectResultsImpl(nodes.size() > 0); }
@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(); }
final WSManEndpoint.Builder builder = new WSManEndpoint.Builder(url) .withServerVersion(WSManVersion.WSMAN_1_0); if (agentConfig.getUsername() != null && agentConfig.getPassword() != null) { builder.withBasicAuth(agentConfig.getUsername(), agentConfig.getPassword()); builder.withGSSAuth(); builder.withMaxElements(agentConfig.getMaxElements()); builder.withStrictSSL(false); builder.withConnectionTimeout(agentConfig.getTimeout()) .withReceiveTimeout(agentConfig.getTimeout()); return builder.build();
final WSManEndpoint.Builder builder = new WSManEndpoint.Builder(url) .withServerVersion(WSManVersion.WSMAN_1_0); if (agentConfig.getUsername() != null && agentConfig.getPassword() != null) { builder.withBasicAuth(agentConfig.getUsername(), agentConfig.getPassword()); builder.withGSSAuth(); builder.withMaxElements(agentConfig.getMaxElements()); builder.withStrictSSL(false); builder.withConnectionTimeout(agentConfig.getTimeout()) .withReceiveTimeout(agentConfig.getTimeout()); return builder.build();