View Javadoc
1   /*
2    * Copyright 2010 Capgemini
3    * Licensed under the Apache License, Version 2.0 (the "License"); 
4    * you may not use this file except in compliance with the License. 
5    * You may obtain a copy of the License at 
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0 
8    * 
9    * Unless required by applicable law or agreed to in writing, software 
10   * distributed under the License is distributed on an "AS IS" BASIS, 
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
12   * See the License for the specific language governing permissions and 
13   * limitations under the License. 
14   * 
15   */
16  package net.sf.appstatus.demo.check;
17  
18  import java.net.InetAddress;
19  
20  import net.sf.appstatus.core.check.AbstractCheck;
21  import net.sf.appstatus.core.check.ICheckResult;
22  
23  public class GooglePingStatusChecker extends AbstractCheck {
24  
25  	public ICheckResult checkStatus() {
26  		ICheckResult result = null;
27  
28  		try {
29  			InetAddress address = InetAddress.getByName("www.google.com");
30  
31  			if (address.isReachable(2000)) {
32  				result = createResult(OK);
33  				result.setDescription("Google Access ok");
34  
35  			} else {
36  				throw new Exception("Ping timeout (2000ms)");
37  			}
38  
39  		} catch (Exception e) {
40  			result = createResult(WARN);
41  			result.setDescription("Google ping failed");
42  			result.setResolutionSteps("Ping failed. This means that ICMP messages are blocked by this host. (This may not be an issue) "
43  					+ e.getMessage());
44  
45  		}
46  
47  		return result;
48  	}
49  
50  	public String getGroup() {
51  		return "google";
52  	}
53  
54  	public String getName() {
55  		return "Google Ping check";
56  	}
57  
58  }