1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.filter.plugins; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.filter.PluginServiceCheck; |
6 |
import java.net.*; |
7 |
import java.io.*; |
8 |
|
9 |
/** |
10 |
* A quick SMTP service checker. |
11 |
* |
12 |
* @author $Author: tdb1 $ |
13 |
* @version $Id: SMTP__ServiceCheck.java,v 1.1 2001/02/13 00:39:17 tdb1 Exp $ |
14 |
*/ |
15 |
public class SMTP__ServiceCheck implements PluginServiceCheck { |
16 |
|
17 |
//---FINAL ATTRIBUTES--- |
18 |
|
19 |
/** |
20 |
* The current CVS revision of this class |
21 |
*/ |
22 |
public final String REVISION = "$Revision: 1.1 $"; |
23 |
|
24 |
public final String DESC = "Checks that an SMTP server is alive."; |
25 |
|
26 |
//---STATIC METHODS--- |
27 |
|
28 |
//---CONSTRUCTORS--- |
29 |
|
30 |
//---PUBLIC METHODS--- |
31 |
|
32 |
/** |
33 |
* Performs the service check on a given host. |
34 |
* |
35 |
* @param hostname the host to check |
36 |
* @return XML data representing the result of the test |
37 |
*/ |
38 |
public String runServiceCheck(String hostname){ |
39 |
String status = ""; |
40 |
String message = ""; |
41 |
try { |
42 |
Socket socket = new Socket(hostname, 25); |
43 |
BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
44 |
String response = socketIn.readLine(); |
45 |
if(response.startsWith("220")) { |
46 |
status = "220"; |
47 |
message = "Header received from server"; |
48 |
} |
49 |
else { |
50 |
status = "0"; |
51 |
message = "Service did not return a 220 response"; |
52 |
} |
53 |
socketIn.close(); |
54 |
socket.close(); |
55 |
} catch (Exception e) { |
56 |
status = "0"; |
57 |
message = "Service check failed to establish connection to host:" + e.getMessage(); |
58 |
} |
59 |
// send the results back |
60 |
return "<SMTP status=\"" + status + "\" message=\"" + message + "\"></SMTP>"; |
61 |
} |
62 |
|
63 |
/** |
64 |
* return the String representation of what the filter does |
65 |
*/ |
66 |
public String getDescription(){ |
67 |
return DESC; |
68 |
} |
69 |
|
70 |
//---PRIVATE METHODS--- |
71 |
|
72 |
//---ACCESSOR/MUTATOR METHODS--- |
73 |
|
74 |
//---ATTRIBUTES--- |
75 |
|
76 |
//---STATIC ATTRIBUTES--- |
77 |
|
78 |
} |