From 0c91d185c6b169cb4faa10ba55f9573a538a1d70 Mon Sep 17 00:00:00 2001
From: Ronald Roskens close setBanner setMatch setClientBanner
wrapSocket
* diff --git a/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/SmtpPlugin.java b/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/SmtpPlugin.java index ef5b60b..f35bf70 100644 --- a/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/SmtpPlugin.java +++ b/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/SmtpPlugin.java @@ -40,9 +40,9 @@ import java.net.NoRouteToHostException; import java.net.Socket; import java.util.Map; import java.util.StringTokenizer; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; -import org.apache.regexp.RE; -import org.apache.regexp.RESyntaxException; import org.opennms.core.utils.InetAddressUtils; import org.opennms.core.utils.ParameterMap; import org.slf4j.Logger; @@ -68,9 +68,9 @@ public final class SmtpPlugin extends AbstractPlugin { * The regular expression test used to determine if the reply is a multi * line reply. A multi line reply is one that each line, but the last, is in * the form of "ddd-" where 'ddd' is the result code. - * + * */ - private static final RE MULTILINE_RESULT; + private static final Pattern MULTILINE_RESULT; /** *@@ -103,8 +103,8 @@ public final class SmtpPlugin extends AbstractPlugin { static { try { - MULTILINE_RESULT = new RE("^[1-5][0-9]{2}-"); - } catch (RESyntaxException re) { + MULTILINE_RESULT = Pattern.compile("^[1-5][0-9]{2}-"); + } catch (PatternSyntaxException re) { throw new java.lang.reflect.UndeclaredThrowableException(re); } } @@ -116,12 +116,12 @@ public final class SmtpPlugin extends AbstractPlugin { * true is returned from the method. Otherwise a false value is returned to * the caller. *
- * + * * @param host * The remote host to connect to. * @param port * The remote port on the host. - * + * * @return True if server supports SMTP on the specified port, false * otherwise */ @@ -149,7 +149,7 @@ public final class SmtpPlugin extends AbstractPlugin { do { result = lineRdr.readLine(); - } while (result != null && result.length() > 0 && MULTILINE_RESULT.match(result)); + } while (result != null && result.length() > 0 && MULTILINE_RESULT.matcher(result).find()); if (result == null || result.length() == 0) { LOG.info("Received truncated response from SMTP server {}", InetAddressUtils.str(host)); @@ -186,7 +186,7 @@ public final class SmtpPlugin extends AbstractPlugin { do { result = lineRdr.readLine(); - } while (result != null && result.length() > 0 && MULTILINE_RESULT.match(result)); + } while (result != null && result.length() > 0 && MULTILINE_RESULT.matcher(result).find()); if (result == null || result.length() == 0) { LOG.info("Received truncated response from SMTP server {}", InetAddressUtils.str(host)); @@ -222,7 +222,7 @@ public final class SmtpPlugin extends AbstractPlugin { do { result = lineRdr.readLine(); - } while (result != null && result.length() > 0 && MULTILINE_RESULT.match(result)); + } while (result != null && result.length() > 0 && MULTILINE_RESULT.matcher(result).find()); if (result == null || result.length() == 0) { LOG.info("Received truncated response from SMTP server {}", InetAddressUtils.str(host)); diff --git a/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/TcpPlugin.java b/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/TcpPlugin.java index 4c1f7ca..0547ae2 100644 --- a/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/TcpPlugin.java +++ b/opennms-services/src/main/java/org/opennms/netmgt/capsd/plugins/TcpPlugin.java @@ -39,9 +39,9 @@ import java.net.InetSocketAddress; import java.net.NoRouteToHostException; import java.net.Socket; import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; -import org.apache.regexp.RE; -import org.apache.regexp.RESyntaxException; import org.opennms.core.utils.InetAddressUtils; import org.opennms.core.utils.ParameterMap; import org.slf4j.Logger; @@ -86,7 +86,7 @@ public final class TcpPlugin extends AbstractPlugin { * caller. In order to return true the remote host must generate a banner * line which contains the text from the bannerMatch argument. * - * + * * @param host * The remote host to connect to. * @param port @@ -94,11 +94,11 @@ public final class TcpPlugin extends AbstractPlugin { * @param bannerResult * Banner line generated by the remote host must contain this * text. - * + * * @return True if a connection is established with the host and the banner * line contains the bannerMatch text. */ - private boolean isServer(InetAddress host, int port, int retries, int timeout, RE regex, StringBuffer bannerResult) { + private boolean isServer(InetAddress host, int port, int retries, int timeout, Pattern regex, StringBuffer bannerResult) { boolean isAServer = false; for (int attempts = 0; attempts <= retries && !isAServer; attempts++) { @@ -128,7 +128,7 @@ public final class TcpPlugin extends AbstractPlugin { // service. // String response = lineRdr.readLine(); - if (regex.match(response)) { + if (regex.matcher(response).find()) { LOG.debug("isServer: matching response= {}", response); isAServer = true; @@ -237,25 +237,26 @@ public final class TcpPlugin extends AbstractPlugin { try { StringBuffer bannerResult = null; - RE regex = null; + Pattern regex = null; if (match == null && (banner == null || banner.equals("*"))) { regex = null; } else if (match != null) { - regex = new RE(match); + regex = Pattern.compile(match); bannerResult = new StringBuffer(); } else if (banner != null) { - regex = new RE(banner); + regex = Pattern.compile(banner); bannerResult = new StringBuffer(); } - + boolean result = isServer(address, port, retries, timeout, regex, bannerResult); if (result && qualifiers != null) { - if (bannerResult != null && bannerResult.length() > 0) + if (bannerResult != null && bannerResult.length() > 0) { qualifiers.put("banner", bannerResult.toString()); + } } return result; - } catch (RESyntaxException e) { + } catch (PatternSyntaxException e) { throw new java.lang.reflect.UndeclaredThrowableException(e); } } diff --git a/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SmtpMonitor.java b/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SmtpMonitor.java index f534c8a..cc6132f 100644 --- a/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SmtpMonitor.java +++ b/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SmtpMonitor.java @@ -39,9 +39,9 @@ import java.net.NoRouteToHostException; import java.net.Socket; import java.util.Map; import java.util.StringTokenizer; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; -import org.apache.regexp.RE; -import org.apache.regexp.RESyntaxException; import org.opennms.core.utils.InetAddressUtils; import org.opennms.core.utils.ParameterMap; import org.opennms.core.utils.TimeoutTracker; @@ -67,9 +67,9 @@ import org.slf4j.LoggerFactory; @Distributable public final class SmtpMonitor extends AbstractServiceMonitor { - + public static final Logger LOG = LoggerFactory.getLogger(SmtpMonitor.class); - + /** * Default SMTP port. @@ -97,15 +97,15 @@ public final class SmtpMonitor extends AbstractServiceMonitor { * the same 3 digit response code, but has a hyphen after the last number * instead of a space. */ - private static final RE MULTILINE; + private static final Pattern MULTILINE; /** * Init MULTILINE */ static { try { - MULTILINE = new RE("^[0-9]{3}-"); - } catch (RESyntaxException ex) { + MULTILINE = Pattern.compile("^[0-9]{3}-"); + } catch (PatternSyntaxException ex) { throw new java.lang.reflect.UndeclaredThrowableException(ex); } } @@ -137,7 +137,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { if (iface.getType() != NetworkInterface.TYPE_INET) { throw new NetworkInterfaceNotSupportedException("Unsupported interface type, only TYPE_INET currently supported"); } - + TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT); int port = ParameterMap.getKeyedInteger(parameters, "port", DEFAULT_PORT); @@ -179,7 +179,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { continue; } - if (MULTILINE.match(banner)) { + if (MULTILINE.matcher(banner).matches()) { // Ok we have a multi-line response...first three // chars of the response line are the return code. // The last line of the response will start with @@ -188,10 +188,10 @@ public final class SmtpMonitor extends AbstractServiceMonitor { // Create new regExp to look for last line // of this multi line response - RE endMultiline = null; + Pattern endMultiline = null; try { - endMultiline = new RE(multiLineRC); - } catch (RESyntaxException ex) { + endMultiline = Pattern.compile(multiLineRC); + } catch (PatternSyntaxException ex) { throw new java.lang.reflect.UndeclaredThrowableException(ex); } @@ -199,7 +199,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { // response do { banner = rdr.readLine(); - } while (banner != null && !endMultiline.match(banner)); + } while (banner != null && !endMultiline.matcher(banner).matches()); if (banner == null) { continue; } @@ -227,7 +227,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { continue; } - if (MULTILINE.match(response)) { + if (MULTILINE.matcher(response).matches()) { // Ok we have a multi-line response...first three // chars of the response line are the return code. // The last line of the response will start with @@ -236,10 +236,10 @@ public final class SmtpMonitor extends AbstractServiceMonitor { // Create new regExp to look for last line // of this multi line response - RE endMultiline = null; + Pattern endMultiline = null; try { - endMultiline = new RE(multiLineRC); - } catch (RESyntaxException ex) { + endMultiline = Pattern.compile(multiLineRC); + } catch (PatternSyntaxException ex) { throw new java.lang.reflect.UndeclaredThrowableException(ex); } @@ -247,7 +247,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { // response do { response = rdr.readLine(); - } while (response != null && !endMultiline.match(response)); + } while (response != null && !endMultiline.matcher(response).matches()); if (response == null) { continue; } @@ -267,7 +267,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { if (response == null) { continue; } - if (MULTILINE.match(response)) { + if (MULTILINE.matcher(response).matches()) { // Ok we have a multi-line response...first three // chars of the response line are the return code. // The last line of the response will start with @@ -276,10 +276,10 @@ public final class SmtpMonitor extends AbstractServiceMonitor { // Create new regExp to look for last line // of this multi line response - RE endMultiline = null; + Pattern endMultiline = null; try { - endMultiline = new RE(multiLineRC); - } catch (RESyntaxException ex) { + endMultiline = Pattern.compile(multiLineRC); + } catch (PatternSyntaxException ex) { throw new java.lang.reflect.UndeclaredThrowableException(ex); } @@ -287,7 +287,7 @@ public final class SmtpMonitor extends AbstractServiceMonitor { // response do { response = rdr.readLine(); - } while (response != null && !endMultiline.match(response)); + } while (response != null && !endMultiline.matcher(response).matches()); if (response == null) { continue; } diff --git a/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SshMonitor.java b/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SshMonitor.java index 8d8cedc..014637a 100644 --- a/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SshMonitor.java +++ b/opennms-services/src/main/java/org/opennms/netmgt/poller/monitors/SshMonitor.java @@ -31,9 +31,9 @@ package org.opennms.netmgt.poller.monitors; import java.net.InetAddress; import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; -import org.apache.regexp.RE; -import org.apache.regexp.RESyntaxException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.opennms.core.utils.ParameterMap; @@ -60,7 +60,7 @@ import org.opennms.netmgt.protocols.ssh.Ssh; */ @Distributable -final public class SshMonitor extends AbstractServiceMonitor { +public final class SshMonitor extends AbstractServiceMonitor { private static final Logger LOG = LoggerFactory.getLogger(SshMonitor.class); private static final int DEFAULT_RETRY = 0; @@ -80,7 +80,7 @@ final public class SshMonitor extends AbstractServiceMonitor { * to Provided that the interface's response is valid we mark the poll status * as available and return. */ - public PollStatus poll(InetAddress address, MapreturnErrorImage
* @@ -160,12 +158,12 @@ public class DefaultRrdGraphService implements RrdGraphService, InitializingBean throw new IllegalArgumentException("graph type \"" + "performance" + "\" is not valid"); } - + OnmsResource r = m_resourceDao.getResourceById(resourceId); Assert.notNull(r, "resource could not be located"); PrefabGraph prefabGraph = m_graphDao.getPrefabGraph(report); - + Graph graph = new Graph(prefabGraph, r, new Date(start), new Date(end)); String command = createPrefabCommand(graph, @@ -174,10 +172,10 @@ public class DefaultRrdGraphService implements RrdGraphService, InitializingBean report, width, height); - + return getInputStreamForCommand(command); } - + /** *createAdHocCommand
* @@ -218,7 +216,7 @@ public class DefaultRrdGraphService implements RrdGraphService, InitializingBean buf.append(commandPrefix); buf.append(" "); buf.append(title); - + String[] rrdFiles = getRrdNames(resource, dsNames); List
Filtering on TCP/IP address uses a very flexible format, allowing you @@ -98,7 +98,7 @@ The following examples are all valid and yield the set of addresses from 192.168.0.0 through 192.168.3.255. - +
|