1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
+ |
* Copyright (C) 2000-2002 i-scream |
5 |
+ |
* |
6 |
+ |
* This program is free software; you can redistribute it and/or |
7 |
+ |
* modify it under the terms of the GNU General Public License |
8 |
+ |
* as published by the Free Software Foundation; either version 2 |
9 |
+ |
* of the License, or (at your option) any later version. |
10 |
+ |
* |
11 |
+ |
* This program is distributed in the hope that it will be useful, |
12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
+ |
* GNU General Public License for more details. |
15 |
+ |
* |
16 |
+ |
* You should have received a copy of the GNU General Public License |
17 |
+ |
* along with this program; if not, write to the Free Software |
18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
+ |
*/ |
20 |
+ |
|
21 |
|
//---PACKAGE DECLARATION--- |
22 |
< |
package uk.org.iscream.filter; |
22 |
> |
package uk.org.iscream.cms.server.filter; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.org.iscream.core.*; |
26 |
< |
import uk.org.iscream.filter.*; |
27 |
< |
import uk.org.iscream.componentmanager.*; |
25 |
> |
import uk.org.iscream.cms.server.core.*; |
26 |
> |
import uk.org.iscream.cms.server.filter.*; |
27 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
28 |
|
import java.net.Socket; |
9 |
– |
import java.io.InputStream; |
10 |
– |
import java.io.OutputStream; |
11 |
– |
import java.io.IOException; |
29 |
|
import java.io.*; |
30 |
< |
import uk.org.iscream.util.*; |
30 |
> |
import java.util.Random; |
31 |
> |
import uk.org.iscream.cms.server.util.*; |
32 |
|
|
33 |
|
/** |
34 |
|
* This provides Host heartbeat functionality |
77 |
|
*/ |
78 |
|
public void run() { |
79 |
|
try { |
80 |
< |
//variables |
81 |
< |
String filelist = ""; |
64 |
< |
String lastModified = ""; |
65 |
< |
String inBound = ""; |
80 |
> |
// get an instance of the KeyManager |
81 |
> |
KeyManager keyman = KeyManager.getInstance(); |
82 |
|
|
83 |
+ |
// get some information about the host |
84 |
+ |
String hostname = _socket.getInetAddress().getHostName().toLowerCase(); |
85 |
+ |
String ipadd = _socket.getInetAddress().getHostAddress(); |
86 |
+ |
|
87 |
|
// try for HEARTBEAT |
88 |
|
getInBound("HEARTBEAT"); |
89 |
|
_socketOut.println("OK"); |
90 |
|
|
91 |
< |
// try for CONFIG |
92 |
< |
getInBound("CONFIG"); |
93 |
< |
_socketOut.println("OK"); |
94 |
< |
|
95 |
< |
// try for {filelist} |
96 |
< |
filelist = getInBound(); |
97 |
< |
_socketOut.println("OK"); |
98 |
< |
|
99 |
< |
// try for {lastModified} |
100 |
< |
lastModified = getInBound(); |
101 |
< |
// check to see if a config update has happen |
102 |
< |
boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified)); |
103 |
< |
if(newConfig) { |
104 |
< |
// new config ! |
105 |
< |
_socketOut.println("ERROR"); |
91 |
> |
// look for a command: |
92 |
> |
// CONFIG - to check config |
93 |
> |
// KEY - to get the key |
94 |
> |
// ENDHEARTBEAT - to finish |
95 |
> |
String cmd = getInBound(); |
96 |
> |
while(!cmd.equals("ENDHEARTBEAT")) { |
97 |
> |
if(cmd.equals("CONFIG")) { |
98 |
> |
// respond to CONFIG |
99 |
> |
_socketOut.println("OK"); |
100 |
> |
|
101 |
> |
// try for {filelist} |
102 |
> |
String filelist = getInBound(); |
103 |
> |
_socketOut.println("OK"); |
104 |
> |
|
105 |
> |
// try for {lastModified} |
106 |
> |
String lastModified = getInBound(); |
107 |
> |
// check to see if a config update has happen |
108 |
> |
boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified)); |
109 |
> |
if(newConfig) { |
110 |
> |
// new config ! |
111 |
> |
_socketOut.println("ERROR"); |
112 |
> |
} |
113 |
> |
else { |
114 |
> |
// nothing has changed |
115 |
> |
_socketOut.println("OK"); |
116 |
> |
} |
117 |
> |
} |
118 |
> |
else if(cmd.equals("KEY")) { |
119 |
> |
// repsond to KEY |
120 |
> |
// generate a key |
121 |
> |
String key = keyman.genKey(); |
122 |
> |
// send key to host |
123 |
> |
_socketOut.println(key); |
124 |
> |
// add it to the key manager |
125 |
> |
keyman.addKey(hostname, key); |
126 |
> |
} |
127 |
> |
else { |
128 |
> |
_socketOut.println("ERROR"); |
129 |
> |
} |
130 |
> |
// get the next command |
131 |
> |
cmd = getInBound(); |
132 |
|
} |
87 |
– |
else { |
88 |
– |
// nothing has changed |
89 |
– |
_socketOut.println("OK"); |
90 |
– |
} |
133 |
|
|
134 |
< |
// try for CONFIG |
93 |
< |
getInBound("ENDHEARTBEAT"); |
134 |
> |
// respond to ENDHEARTBEAT |
135 |
|
_socketOut.println("OK"); |
136 |
|
|
137 |
|
// work out some information for our heartbeat packet |
138 |
|
String date = new Long(System.currentTimeMillis()/((long) 1000)).toString(); //seconds |
98 |
– |
String hostname = _socket.getInetAddress().getHostName().toLowerCase(); |
99 |
– |
String ipadd = _socket.getInetAddress().getHostAddress(); |
139 |
|
|
140 |
|
// run the service checks for this host |
141 |
|
_logger.write(toString(), Logger.DEBUG, "Running service checks"); |
166 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
167 |
|
* method to provide clean logging (every class should have this). |
168 |
|
* |
169 |
< |
* This uses the uk.org.iscream.util.NameFormat class |
169 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
170 |
|
* to format the toString() |
171 |
|
* |
172 |
|
* @return the name of this class and its CVS revision |
185 |
|
String inBound = getInBound(); |
186 |
|
// check if it's what we're expecting |
187 |
|
if(!inBound.equals(expected)) { |
188 |
< |
throw new IOException("protocol error - expected:"+expected+" got:" + inBound); |
188 |
> |
throw new IOException("protocol error from "+_socket.getInetAddress().getHostName()+" - expected:"+expected+" got:" + inBound); |
189 |
|
} |
190 |
|
// it should be ok then |
191 |
|
return inBound; |
201 |
|
// it's a valid message it seems |
202 |
|
return inBound; |
203 |
|
} |
204 |
< |
|
204 |
> |
|
205 |
|
//---ACCESSOR/MUTATOR METHODS--- |
206 |
|
|
207 |
|
//---ATTRIBUTES--- |
247 |
|
* A reference to our Queue |
248 |
|
*/ |
249 |
|
Queue _queue; |
250 |
+ |
|
251 |
|
//---STATIC ATTRIBUTES--- |
252 |
|
|
253 |
|
} |