⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smtpmonitor.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                //                long sentTime = System.currentTimeMillis();                socket = new Socket();                socket.connect(new InetSocketAddress(ipv4Addr, port), timeout);                socket.setSoTimeout(timeout);                log.debug("SmtpMonitor: connected to host: " + ipv4Addr + " on port: " + port);                // We're connected, so upgrade status to unresponsive                serviceStatus = SERVICE_UNRESPONSIVE;                BufferedReader rdr = new BufferedReader(new InputStreamReader(socket.getInputStream()));                //                // Tokenize the Banner Line, and check the first                // line for a valid return.                //                String banner = rdr.readLine();                if (banner == null)                    continue;                if (MULTILINE.match(banner)) {                    // 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                    // return code followed by a space.                    String multiLineRC = new String(banner.getBytes(), 0, 3) + " ";                    // Create new regExp to look for last line                    // of this mutli line response                    try {                        ENDMULTILINE = new RE(multiLineRC);                    } catch (RESyntaxException ex) {                        throw new java.lang.reflect.UndeclaredThrowableException(ex);                    }                    // read until we hit the last line of the multi-line                    // response                    do {                        banner = rdr.readLine();                    } while (banner != null && !ENDMULTILINE.match(banner));                    if (banner == null)                        continue;                }                if (log.isDebugEnabled())                    log.debug("poll: banner = " + banner);                StringTokenizer t = new StringTokenizer(banner);                int rc = Integer.parseInt(t.nextToken());                if (rc == 220) {                    //                    // Send the HELO command                    //                    String cmd = "HELO " + LOCALHOST_NAME + "\r\n";                    socket.getOutputStream().write(cmd.getBytes());                    //                    // get the returned string, tokenize, and                    // verify the correct output.                    //                    String response = rdr.readLine();                    responseTime = System.currentTimeMillis() - sentTime;                    if (response == null)                        continue;                    if (MULTILINE.match(response)) {                        // 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                        // return code followed by a space.                        String multiLineRC = new String(response.getBytes(), 0, 3) + " ";                        // Create new regExp to look for last line                        // of this mutli line response                        try {                            ENDMULTILINE = new RE(multiLineRC);                        } catch (RESyntaxException ex) {                            throw new java.lang.reflect.UndeclaredThrowableException(ex);                        }                        // read until we hit the last line of the multi-line                        // response                        do {                            response = rdr.readLine();                        } while (response != null && !ENDMULTILINE.match(response));                        if (response == null)                            continue;                    }                    t = new StringTokenizer(response);                    rc = Integer.parseInt(t.nextToken());                    if (rc == 250) {                        cmd = "QUIT\r\n";                        socket.getOutputStream().write(cmd.getBytes());                        //                        // get the returned string, tokenize, and                        // verify the correct output.                        //                        response = rdr.readLine();                        if (response == null)                            continue;                        if (MULTILINE.match(response)) {                            // 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                            // return code followed by a space.                            String multiLineRC = new String(response.getBytes(), 0, 3) + " ";                            // Create new regExp to look for last line                            // of this mutli line response                            try {                                ENDMULTILINE = new RE(multiLineRC);                            } catch (RESyntaxException ex) {                                throw new java.lang.reflect.UndeclaredThrowableException(ex);                            }                            // read until we hit the last line of the multi-line                            // response                            do {                                response = rdr.readLine();                            } while (response != null && !ENDMULTILINE.match(response));                            if (response == null)                                continue;                        }                        t = new StringTokenizer(response);                        rc = Integer.parseInt(t.nextToken());                        if (rc == 221) {                            serviceStatus = ServiceMonitor.SERVICE_AVAILABLE;                            // Store response time in RRD                            if (responseTime >= 0 && rrdPath != null) {                                try {                                    this.updateRRD(rrdPath, ipv4Addr, dsName, responseTime, pkg);                                } catch (RuntimeException rex) {                                    log.debug("There was a problem writing the RRD:" + rex);                                }                            }                        }                    }                }                // If we get this far and the status has not been set                // to available, then something didn't verify during                // the banner checking or HELO/QUIT comand process.                if (serviceStatus != ServiceMonitor.SERVICE_AVAILABLE) {                    serviceStatus = ServiceMonitor.SERVICE_UNAVAILABLE;                }            } catch (NumberFormatException e) {                // Ignore                e.fillInStackTrace();                if (log.isDebugEnabled())                    log.debug("poll: NumberFormatException while polling address " + ipv4Addr.getHostAddress(), e);            } catch (NoRouteToHostException e) {                e.fillInStackTrace();                if (log.isEnabledFor(Priority.WARN))                    log.warn("poll: No route to host exception for address " + ipv4Addr.getHostAddress(), e);                break; // Break out of for(;;)            } catch (InterruptedIOException e) {                log.debug("SmtpMonitor: did not connect to host within timeout: " + timeout + " attempt: " + attempts);            } catch (ConnectException e) {                // Connection refused. Continue to retry.                //                e.fillInStackTrace();                if (log.isDebugEnabled())                    log.debug("poll: Connection exception for address " + ipv4Addr.getHostAddress(), e);            } catch (IOException e) {                // Ignore                e.fillInStackTrace();                if (log.isDebugEnabled())                    log.debug("poll: IOException while polling address " + ipv4Addr.getHostAddress(), e);            } finally {                try {                    // Close the socket                    if (socket != null)                        socket.close();                } catch (IOException e) {                    e.fillInStackTrace();                    if (log.isDebugEnabled())                        log.debug("poll: Error closing socket.", e);                }            }        }        //        // return the status of the service        //        return serviceStatus;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -