CollWebActivityWithHttp.java
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.sitech.ismp.coll.centercoll;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
public class CollWebActivityWithHttp implements CollWebActivityMBean {
private Logger logger = Logger.getLogger("COLL");
private Vector result = new Vector();
private String KBP_CLASS = "11-10-17-12";
public CollWebActivityWithHttp() {
// TODO Auto-generated constructor stub
}
public Vector collWebActive(HashMap params) {
String url = (String) params.get("URL");
String device_id = (String) params.get("DEVICE_ID");
String unit_id = this.KBP_CLASS + ":" + device_id;
try {
result.clear();
HttpMethod method = null;
HttpClient client = new HttpClient();
method = new GetMethod(url);
method.setQueryString(url);
client.executeMethod(method);
int status = method.getStatusCode();
if (status != 200) {
// System.out.println("FM-00-21-001-01=" + status);
// PM-00-21-001-02=UP
this.setResult("DOWN", unit_id, "FM-00-21-001-01");
} else {
// PM-00-21-001-02=DOWN
this.setResult("UP", unit_id, "FM-00-21-001-01");
// System.out.println("FM-00-21-001-01=" + status);
}
// FM-00-21-001-01
// this.setResult(String.valueOf(status), unit_id, "FM-00-21-001-01");
// CM-00-21-001-01
this.setResult(url, unit_id, "CM-00-21-001-01");
logger.info("COLLWEB status=" + status);
} catch (Exception e) {
this.setResult("DOWN", unit_id, "FM-00-21-001-01");
e.printStackTrace();
logger.info("COLLWEB error=" + e);
}
return result;
}
private void setResult(String value, String unitID, String kpiID) {
try {
TblATO_KPIDETAIL record;
record = new TblATO_KPIDETAIL();
record.setCLL_TIME(new java.util.Date()); // 采集所消耗的时间
record.setKPI_ID(kpiID); // kpi编号
record.setKPI_VALUE(value); // 具体采集得到的值信息
record.setUNIT_ID(unitID); // unit
record.setCLL_TIME(new Date()); // 日期
result.add(record);
} catch (Exception e) {
logger.error(e);
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
CollWebActivityWithHttp act = new CollWebActivityWithHttp();
HashMap map = new HashMap();
map.put("DEVICE_ID", "sohu");
// map.put("URL", "http://www.sohu.com");
map.put("URL", "http://192.168.111.10:8080");
act.collWebActive(map);
}
}