ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/plugins/SSH__ServiceCheck.java
Revision: 1.2
Committed: Wed Mar 7 13:26:38 2001 UTC (23 years, 2 months ago) by tdb
Branch: MAIN
Changes since 1.1: +4 -4 lines
Log Message:
"Failure" messages (where an exception has been thrown) were being sent with a
0 status, which actually means ok. Opps.

File Contents

# Content
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 SSH service checker.
11 *
12 * @author $Author: tdb1 $
13 * @version $Id: SSH__ServiceCheck.java,v 1.1 2001/03/07 13:04:44 tdb1 Exp $
14 */
15 public class SSH__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 SSH 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, 22);
43 BufferedReader socketIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
44 String response = socketIn.readLine();
45 if(response.startsWith("SSH")) {
46 status = "0";
47 message = "Good Header received: "+response;
48 }
49 else {
50 status = "1";
51 message = "Bad Header received: "+response;
52 }
53 socketIn.close();
54 socket.close();
55 } catch (Exception e) {
56 status = "1";
57 message = "Service check failed to establish connection to host: " + e.getMessage();
58 }
59 // send the results back
60 return "<SSH status=\"" + status + "\" message=\"" + message + "\"></SSH>";
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 }