private static String determineResponseText(final Map<String, Object> parameters) { return ParameterMap.getKeyedString(parameters, PARAMETER_RESPONSE_TEXT, null); }
/** * <p>Constructor for SnmpThresholdConfiguration.</p> * * @param thresholdsDao a {@link org.opennms.netmgt.threshd.ThresholdsDao} object. * @param parms a {@link java.util.Map} object. */ public SnmpThresholdConfiguration(ThresholdsDao thresholdsDao, Map<?,?> parms) { setRange(ParameterMap.getKeyedInteger(parms, "range", SnmpThresholdConfiguration.DEFAULT_RANGE)); setInterval(ParameterMap.getKeyedInteger(parms, "interval", SnmpThresholdConfiguration.DEFAULT_INTERVAL)); setThresholdGroup(thresholdsDao.get(ParameterMap.getKeyedString(parms, "thresholding-group", DEFAULT_GROUP))); }
private String determineVirtualHost(final InetAddress addr, final Map<String, Object> parameters) { final boolean res = ParameterMap.getKeyedBoolean(parameters, PARAMETER_RESOLVE_IP, false); final boolean useNodeLabel = ParameterMap.getKeyedBoolean(parameters, PARAMETER_NODE_LABEL_HOST_NAME, false); String virtualHost = ParameterMap.getKeyedString(parameters, PARAMETER_HOST_NAME, null); if (isBlank(virtualHost)) { if (res) { return addr.getCanonicalHostName(); } else if (useNodeLabel) { return m_nodeLabel; } else { final String host = InetAddressUtils.str(addr); // Wrap IPv6 addresses in square brackets if (addr instanceof Inet6Address) { return "[" + host + "]"; } else { return host; } } } return virtualHost; }
/** * <p>Constructor for TimeoutTracker.</p> * * @param parameters a {@link java.util.Map} object. * @param defaultRetry a int. * @param defaultTimeout a int. */ public TimeoutTracker(Map<String,?> parameters, int defaultRetry, int defaultTimeout) { m_retry = ParameterMap.getKeyedInteger(parameters, "retry", defaultRetry); // make sure the timeout is a least 10 millis m_timeoutInMillis = Math.max(10L, ParameterMap.getKeyedInteger(parameters, "timeout", defaultTimeout)); m_timeoutInNanos = Math.max(10000000L, TimeUnit.NANOSECONDS.convert(m_timeoutInMillis, TimeUnit.MILLISECONDS)); m_timeoutInSeconds = Math.max(1L, TimeUnit.SECONDS.convert(m_timeoutInMillis, TimeUnit.MILLISECONDS)); m_strictTimeouts = ParameterMap.getKeyedBoolean(parameters, "strict-timeout", false); resetAttemptStartTime(); }
int port = ParameterMap.getKeyedInteger(parameters, "port", DEFAULT_PORT); int allowedSkew = ParameterMap.getKeyedInteger(parameters, "allowed-skew", DEFAULT_ALLOWED_SKEW); boolean persistSkew = ParameterMap.getKeyedBoolean(parameters, "persist-skew", DEFAULT_PERSIST_SKEW); String protocol = ParameterMap.getKeyedString(parameters, "protocol", DEFAULT_PROTOCOL).toLowerCase(); if (! protocol.equalsIgnoreCase("tcp") && ! protocol.equalsIgnoreCase("udp")) { throw new IllegalArgumentException("Unsupported protocol, only TCP and UDP currently supported");
@Override protected int determinePort(Map<String, Object> parameters) { return ParameterMap.getKeyedInteger(parameters, "port", DEFAULT_IMAPS_PORT); }
int port = ParameterMap.getKeyedInteger(parameters, "port", DEFAULT_PORT); String lookup = ParameterMap.getKeyedString(parameters, "lookup", null); if (lookup == null || lookup.length() == 0) { for (final int code : ParameterMap.getKeyedIntegerArray(parameters, "fatal-response-codes", DEFAULT_FATAL_RESP_CODES)) { fatalCodes.add(code); int minAnswers = ParameterMap.getKeyedInteger(parameters, "min-answers", DEFAULT_MIN_ANSWERS); int maxAnswers = ParameterMap.getKeyedInteger(parameters, "max-answers", DEFAULT_MAX_ANSWERS);
int retries = ParameterMap.getKeyedInteger(parameters, "retry", PingConstants.DEFAULT_RETRIES); long timeout = ParameterMap.getKeyedLong(parameters, "timeout", PingConstants.DEFAULT_TIMEOUT); int packetSize = ParameterMap.getKeyedInteger(parameters, "packet-size", PingConstants.DEFAULT_PACKET_SIZE); final int dscp = ParameterMap.getKeyedDecodedInteger(parameters, "dscp", 0); final boolean allowFragmentation = ParameterMap.getKeyedBoolean(parameters, "allow-fragmentation", true);
/** {@inheritDoc} */ @Override public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { int retries = ParameterMap.getKeyedInteger(parameters, "retry", PingConstants.DEFAULT_RETRIES); long timeout = ParameterMap.getKeyedLong(parameters, "timeout", PingConstants.DEFAULT_TIMEOUT); Long rtt = null; String phoneNumber = null; try { phoneNumber = phonebook.getTargetForAddress(svc.getIpAddr()); } catch (final PhonebookException e) { LOG.warn("Unable to get phonebook target for {}", svc.getIpAddr(), e); } if (phoneNumber != null) { try { rtt = SmsPinger.ping(phoneNumber, timeout, retries); } catch (final Exception e) { LOG.warn("Unable to ping phone number: {}", phoneNumber, e); } } if (rtt != null) { return PollStatus.available(rtt.doubleValue()); } else { return PollStatus.unavailable(); } } }
public static void setUseSystemProxyIfDefined(HttpClientWrapper httpClientWrapper, Map<String, Object> keyedParameters) { if (ParameterMap.getKeyedBoolean(keyedParameters, useSystemProxy.getKey(), false)) { httpClientWrapper.useSystemProxySettings(); LOG.debug("setting useSystemProxySettings() on HttpClientWrapper"); } }
/** * This method is used to lookup a specific key in the map. If the mapped * value is a string it is converted to an integer and the original string * value is replaced in the map. The converted value is returned to the * caller. If the value cannot be converted then the default value is stored * in the map. If the specified key does not exist in the map then the * default value is returned. * * @return The int value associated with the key. * @param map a {@link java.util.Map} object. * @param key a {@link java.lang.String} object. * @param defValue a int. */ public static int getKeyedInteger(@SuppressWarnings("rawtypes") final Map map, final String key, final int defValue) { return new Long(ParameterMap.getKeyedLong(map, key, defValue)).intValue(); }
retry = ParameterMap.getKeyedInteger(qualifiers, "retry", protoConfig.hasRetry() ? protoConfig.getRetry() : DEFAULT_RETRY); timeout = ParameterMap.getKeyedInteger(qualifiers, "timeout", protoConfig.hasTimeout() ? protoConfig.getTimeout() : DEFAULT_TIMEOUT); port = ParameterMap.getKeyedInteger(qualifiers, "port", DEFAULT_PORT); authenUser = ParameterMap.getKeyedString(qualifiers, "authenUser", DEFAULT_AUTHEN_USER); requestType = ParameterMap.getKeyedString(qualifiers, "request-type", DEFAULT_REQUEST_TYPE); mib = ParameterMap.getKeyedString(qualifiers, "mib", DEFAULT_REQUEST_MIB); table = ParameterMap.getKeyedString(qualifiers, "table", DEFAULT_REQUEST_TABLE); object = ParameterMap.getKeyedString(qualifiers, "object", DEFAULT_REQUEST_OBJECT); instance = ParameterMap.getKeyedString(qualifiers, "instance", DEFAULT_REQUEST_INSTANCE); instanceMatch = ParameterMap.getKeyedString(qualifiers, "instance-match", DEFAULT_INSTANCE_MATCH); valueOperator = ParameterMap.getKeyedString(qualifiers, "value-operator", "=="); valueOperand = ParameterMap.getKeyedString(qualifiers, "value-match", DEFAULT_VALUE_MATCH); valueCaseSensitive = ParameterMap.getKeyedBoolean(qualifiers, "value-case-sensitive", DEFAULT_VALUE_CASE_SENSITIVE); minMatches = ParameterMap.getKeyedInteger(qualifiers, "min-matches", DEFAULT_MIN_MATCHES); maxMatches = ParameterMap.getKeyedInteger(qualifiers, "max-matches", DEFAULT_MAX_MATCHES); String maxMatchesUnboundedStr = ParameterMap.getKeyedString(qualifiers, "max-matches", "unbounded"); maxMatchesUnbounded = (maxMatchesUnboundedStr.equalsIgnoreCase("unbounded"));
@Override protected int determinePort(Map<String, Object> parameters) { return ParameterMap.getKeyedInteger(parameters, "port", LDAPConnection.DEFAULT_SSL_PORT); }
long timeout = ParameterMap.getKeyedLong(parameters, "timeout", PingConstants.DEFAULT_TIMEOUT); int count = ParameterMap.getKeyedInteger(parameters, "ping-count", DEFAULT_MULTI_PING_COUNT); long pingInterval = ParameterMap.getKeyedLong(parameters, "wait-interval", DEFAULT_PING_INTERVAL); int failurePingCount = ParameterMap.getKeyedInteger(parameters, "failure-ping-count", DEFAULT_FAILURE_PING_COUNT); final int packetSize = ParameterMap.getKeyedInteger(parameters, "packet-size", PingConstants.DEFAULT_PACKET_SIZE); final int dscp = ParameterMap.getKeyedDecodedInteger(parameters, "dscp", 0); final boolean allowFragmentation = ParameterMap.getKeyedBoolean(parameters, "allow-fragmentation", true);
@Override public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) { Long ttlInMs = ParameterMap.getKeyedLong(parameters, "ttl", DEFAULT_TTL_IN_MS); if (ttlInMs < 1) { // Use the global default ttlInMs = null; } int messageSize = ParameterMap.getKeyedInteger(parameters, "message-size", DEFAULT_MESSAGE_SIZE); if (messageSize < 0) { messageSize = 0; } // Create the client final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.get().getClient(EchoRpcModule.INSTANCE); // Build the request final OnmsNode node = nodeDao.get().get(svc.getNodeId()); final EchoRequest request = new EchoRequest(); request.setId(System.currentTimeMillis()); request.setMessage(Strings.repeat("*", messageSize)); request.setLocation(node.getLocation().getLocationName()); request.setSystemId(node.getForeignId()); request.setTimeToLiveMs(ttlInMs); try { final EchoResponse response = client.execute(request).get(); final Long responseTime = System.currentTimeMillis() - response.getId(); return PollStatus.available(responseTime.doubleValue()); } catch (InterruptedException|ExecutionException t) { return RpcExceptionUtils.handleException(t, this); } }
private static String createLegacyUrl(InetAddress ipAddress, Map<String, String> properties) { final String ipAddrString = InetAddressUtils.toUrlIpAddress(ipAddress); final String port = properties.getOrDefault("port", "1099"); final String protocol = properties.getOrDefault("protocol", "rmi"); final String urlPath = properties.getOrDefault("urlPath", "/jmxrmi"); final String rmiServerPort = properties.getOrDefault("rmiServerport", "45444"); final boolean remote = ParameterMap.getKeyedBoolean(properties, "remoteJMX", false); if(remote) { final String url = String.format("service:jmx:%s:%s:%s://jndi/%s://%s:%s%s", protocol, ipAddrString, rmiServerPort, protocol, ipAddrString, port, urlPath); return url; } else { final String url = String.format("service:jmx:%s:///jndi/%s://%s:%s%s", protocol, protocol, ipAddrString, port, urlPath); return url; } }
private String getIpMatch(Map<String, Object> parameters) { return ParameterMap.getKeyedString(parameters, "ip-match", "*.*.*.*"); }
PollStatus ps = PollStatus.unavailable(); Statement st = null; String query = ParameterMap.getKeyedString(parameters, "query", null); String action = ParameterMap.getKeyedString(parameters, "action", "row_count"); String column = ParameterMap.getKeyedString(parameters, "column", null); String operator = ParameterMap.getKeyedString(parameters, "operator", ">="); String message = ParameterMap.getKeyedString(parameters, "message", null ); rs.last(); int rowCount = rs.getRow(); int expectedRowCount = ParameterMap.getKeyedInteger(parameters,"operand",1); if (integerCheck(rowCount,expectedRowCount,operator)) ps = PollStatus.available(); break; case QUERY_ACTION_COMPARE_STRING: String expectedString = ParameterMap.getKeyedString(parameters, "operand", null); String retrivedString = rs.getString(column); if ( expectedString.equals(retrivedString)) int expectedInt = ParameterMap.getKeyedInteger(parameters, "operand", 1); int retrivedInt = rs.getInt(column); if (integerCheck(retrivedInt,expectedInt,operator))
ub.setScheme(ParameterMap.getKeyedString(map, "scheme", DEFAULT_SCHEME)); ub.setHost(hostAddress); ub.setPort(ParameterMap.getKeyedInteger(map, "port", DEFAULT_PORT)); ub.setPath(ParameterMap.getKeyedString(map, "path", DEFAULT_PATH)); String queryString = ParameterMap.getKeyedString(map,"queryString",null); if (queryString != null && !queryString.trim().isEmpty()) { final List<NameValuePair> params = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8); clientWrapper.setConnectionTimeout(ParameterMap.getKeyedInteger(map, "timeout", DEFAULT_TIMEOUT)) .setSocketTimeout(ParameterMap.getKeyedInteger(map, "timeout", DEFAULT_TIMEOUT)); final String userAgent = ParameterMap.getKeyedString(map,"user-agent",DEFAULT_USER_AGENT); if (userAgent != null && !userAgent.trim().isEmpty()) { clientWrapper.setUserAgent(userAgent); final String virtualHost = ParameterMap.getKeyedString(map,"virtual-host", hostAddress); if (virtualHost != null && !virtualHost.trim().isEmpty()) { clientWrapper.setVirtualHost(virtualHost); if(ParameterMap.getKeyedBoolean(map, "http-1.0", false)) { clientWrapper.setVersion(HttpVersion.HTTP_1_0); final String key = okey.toString(); if(key.matches("header_[0-9]+$")){ final String headerName = ParameterMap.getKeyedString(map,key,null); final String headerValue = ParameterMap.getKeyedString(map,key + "_value",null); getMethod.setHeader(headerName, headerValue);
protected int determinePort(final Map<String, Object> parameters) { return ParameterMap.getKeyedInteger(parameters, "port", DEFAULT_PORT); }