| 2 |
|
package uk.ac.ukc.iscream.filter.plugins; |
| 3 |
|
|
| 4 |
|
//---IMPORTS--- |
| 5 |
< |
import uk.ac.ukc.iscream.filter.PluginServiceCheck; |
| 5 |
> |
import uk.ac.ukc.iscream.filter.ServiceCheckSkeleton; |
| 6 |
|
import java.net.*; |
| 7 |
|
import java.io.*; |
| 8 |
|
|
| 12 |
|
* @author $Author$ |
| 13 |
|
* @version $Id$ |
| 14 |
|
*/ |
| 15 |
< |
public class SMTP__ServiceCheck implements PluginServiceCheck { |
| 15 |
> |
public class SMTP__ServiceCheck extends ServiceCheckSkeleton { |
| 16 |
|
|
| 17 |
|
//---FINAL ATTRIBUTES--- |
| 18 |
|
|
| 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 "<HTTP status=\"" + status + "\" message=\"" + message + "\"></HTTP>"; |
| 61 |
< |
} |
| 62 |
< |
|
| 63 |
< |
/** |
| 64 |
< |
* return the String representation of what the filter does |
| 65 |
< |
*/ |
| 66 |
< |
public String getDescription(){ |
| 67 |
< |
return DESC; |
| 39 |
> |
return checkService(hostname, 25, "220", "SMTP"); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
//---PRIVATE METHODS--- |