1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.alert.agent;
21 import java.net.URL;
22
23 import org.backsource.alert.PropertyConstants;
24 import org.backsource.alert.AlertError;
25 /***
26 * Agent that test a certain url and check the content returned.
27 *
28 * <p>Is for example used to check JBoss servers by accessing the HTML
29 * adapter of the JMX server. It uses two properties {@link org.backsource.alert.PropertyConstants#SERVER_ALIVE_URL} and {@link org.backsource.alert.PropertyConstants#SERVER_ALIVE_FIND}.Se {@link UrlCase} for properties partaining to authentication.</p>
30 *
31 *
32 * @author <a href="mailto:pra@tim.se">Peter Antman</a>
33 * @version $Revision: 1.1.1.1 $
34 */
35
36 public class ServerAliveTest extends UrlCase{
37 URL url = null;
38 String find = null;
39 public ServerAliveTest (String name){
40 super(name);
41 }
42
43 protected void setUp() throws Exception{
44 super.setUp();
45 String t = prop.getProperty(PropertyConstants.SERVER_ALIVE_URL);
46 url = new URL(t);
47 find = prop.getProperty(PropertyConstants.SERVER_ALIVE_FIND);
48 }
49
50 /***
51 * The agent/test method.
52 *
53 * <p>Checks that the given url returns 200 and contains the string given in {@link org.backsource.alert.PropertyConstants#SERVER_ALIVE_FIND}.</p>
54 */
55 public void testServerAlive() {
56 try {
57 checkUrl(url,find);
58 } catch ( AlertError e) {
59 throw new AlertError("Server probably dead: " + e);
60 }
61
62
63 }
64
65 public static void main(String[] args){
66 try {
67 ServerAliveTest t = new ServerAliveTest("main");
68 t.url = new URL("http://10.72.9.11:8082/ViewObjectRes//Amsterdam%3Aservice%3DServiceFactory");
69 t.find="<TITLE>MBean View of Amsterdam:service=ServiceFactory</TITLE>";
70 t.testServerAlive();
71 } catch (Exception e) {
72 e.printStackTrace();
73 }
74
75 }
76 }