CollWindows.java
9.81 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package com.sitech.ismp.coll.centercoll;
import com.sitech.ismp.check.downtime.CheckConnectionState;
import com.sitech.ismp.check.downtime.ParamterBean;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
public class CollWindows implements CollWindowsMBean {
private static Logger log= Logger.getLogger(CollWindows.class);
String kbpClass="10-10-23-10"; // Windows 主机的标识
CheckConnectionState server=new CheckConnectionState();
/**
* 获取主机ping状态。
* 当3个ping周期都ping不通的时候,才能视不能ping通。
* @param params
* @return
*/
public Vector<TblATO_KPIDETAIL> getPingState(HashMap<String, String> params){
Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>();
String ip=params.get("IP");
if(!StringUtils.isEmpty(ip)){
String kpiId="FM-00-10-001-999"; // Windows 主机连接状态
String hostName=params.get("HOST_NAME");
String unitId = kbpClass+":" + hostName + "-total";
ParamterBean bean =new ParamterBean();
bean.setDEVICE_IP(ip);
bean.setType("windows");
log.info("*** execute getPingState ** ip=["+ip+"]** unitId=["+unitId+"]*********");
/**
* getPingState 方法执行后会将状态插入到表中,然后取当前时间
* 根基IP查询失败的次数,如果失败次数为3次,则确定为宕机,发送告警。
*/
CheckConnectionState server=new CheckConnectionState();
server.getPingState(bean);
// 根据IP获取ping的错误次数。如果是 DOWN 的话,发送告警信息。
String state=server.getPingErrorState(ip);
TblATO_KPIDETAIL kpidetail= new TblATO_KPIDETAIL();
log.info("***** unitId**"+unitId+"** state **"+state+"*******");
try {
kpidetail.setKPI_ID(kpiId);
kpidetail.setUNIT_ID(unitId);
kpidetail.setKPI_VALUE(state);
kpidetail.setCLL_TIME(new Date());
} catch (ParseException e) {
e.printStackTrace();
}
v.add(kpidetail);
}
return v;
}
/**
* 获取连接状态,在进行连接之前,检查该设备是否能ping通,如果为down就不执行操作了。
* @param params
* @return
*/
@Override
public Vector<TblATO_KPIDETAIL> getSnmpState(HashMap<String, String> params){
Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>();
String ip=params.get("IP");
if(!StringUtils.isEmpty(ip)){
String result=server.getPingResultByIp(ip);
log.info("@@@@@###### getSnmpState ping result="+ result +"###$$$$$$$$$$%%%%%%%%%%");
if(!StringUtils.isEmpty(result) && "UP".equals(result)){
String kpiId="FM-00-10-001-998"; // Windows 设备登录状态
ParamterBean bean =new ParamterBean();
String tempPort=params.get("PORT");
String community=params.get("COMMUNITY");
int port=Integer.parseInt(tempPort);
String hostName=params.get("HOST_NAME");
log.info("******ip "+ip+"**port "+tempPort+"****hostName "+hostName+"*****");
bean.setDEVICE_IP(ip);
bean.setPROTOCOL_PORT(port);
bean.setCOMMUNITY(community);
String state=server.getConnectionState4Snmp(bean);
String unitId = kbpClass+":" + hostName + "-total";
TblATO_KPIDETAIL kpidetail=new TblATO_KPIDETAIL();
try {
kpidetail.setKPI_ID(kpiId);
kpidetail.setUNIT_ID(unitId);
kpidetail.setKPI_VALUE(state);
kpidetail.setCLL_TIME(new Date());
} catch (ParseException e) {
e.printStackTrace();
}
v.add(kpidetail);
}
}
return v;
}
public Vector<TblATO_KPIDETAIL> coll(HashMap params) {
CollWindowsWithSNMP windows = new CollWindowsWithSNMP(params);
return windows.coll(params);
}
public Vector<TblATO_KPIDETAIL> collSpecProcess(HashMap params) {
CollWindowsWithSNMP windows = new CollWindowsWithSNMP(params);
return windows.collSpecProcess(params);
}
/**
* 新关键进程采集
* @param params
* @return
*/
@Override
public Vector collSpecProcessList(HashMap<String, String> params) {
CollWindowsWithSNMP windows = new CollWindowsWithSNMP(params);
return windows.collSpecProcessList(params);
}
/**
* 采集Hyper-v的CPU相关指标
* @param params
* @return
*/
public Vector<TblATO_KPIDETAIL> getCpu(HashMap<String, String> params) {
CollWindowsWithHyperv windows = new CollWindowsWithHyperv(params);
return windows.getCpu(params);};
/**
* 采集Hyper-v的内存相关指标
* @param params
* @return
*/
public Vector<TblATO_KPIDETAIL> getMemory(HashMap<String, String> params) {
CollWindowsWithHyperv windows = new CollWindowsWithHyperv(params);
return windows.getMemory(params);};
/**
* 采集Hyper-v的磁盘相关指标
* @param params
* @return
*/
public Vector<TblATO_KPIDETAIL> getFileSystem(HashMap<String, String> params) {
CollWindowsWithHyperv windows = new CollWindowsWithHyperv(params);
return windows.getFileSystem(params);};
public Vector<TblATO_KPIDETAIL> getConfig(HashMap<String, String> params) {
CollWindowsWithHyperv windows = new CollWindowsWithHyperv(params);
return windows.getConfig(params);};
public static void main(String args[]) {
System.out.println("***************Windows Collect Test Begin*********************");
HashMap<String, String> params = new HashMap<String, String>();
// String ipAddr = read("HOSTIP(Windows host ip):");
// String port = read("SNMPPORT(161):");
// String community = read("COMMUNITY(public):");
// String deviceName = read("HOST_NAME:");
// String processName = read("PROCESS_NAME:");
// String processDesc = read("PROCESS_DESC:");
// String maxCount = read("MAX_COUNT:");
// String minCount = read("MIN_COUNT:");
// String methodStr = read("METHOD(0:getAll, 1:coll, 2:collSpecProcess, 3:collSpecProcessList, 4:getCpu, 5:getMemory, 6:getDisk):");
// String ipAddr = "172.21.3.23";
// String port = "161";
// String community = "public";
// String deviceName = "WIN-KLA4OB2ZEUO";
// String processName = "vpxd.exe,svchost.exe,liush";
// String processDesc = "VirtualCenter Server";
// String maxCount = "2";
// String minCount = "1";
// params.put("IP", ipAddr);
// params.put("PORT", port);
// params.put("COMMUNITY", community);
// params.put("HOST_NAME", deviceName);
// params.put("PROCESS_NAME", processName);
// params.put("PROCESS_DESC", processDesc);
// params.put("MAX_COUNT", maxCount);
// params.put("MIN_COUNT", minCount);
String hypervHttpUrl = "http://172.21.0.16:8888/?command=E:/monitor-ps1/";
String username = "Administrator";
String password = "Abcd1234";
String deviceName = "WIN-KLA4OB2ZEUO";
params.put("HYPERV_URL", hypervHttpUrl);
params.put("HOST_NAME", deviceName);
params.put("USERNAME", username);
params.put("PASSWORD", DES3.encrypt(password));
String methodStr = "8";
int method = Integer.parseInt(methodStr);
Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
CollWindows collector = new CollWindows();
switch (method) {
case 0:
result.addAll(collector.coll(params));
result.addAll(collector.collSpecProcess(params));
result.addAll(collector.collSpecProcessList(params));
result.addAll(collector.getCpu(params));
result.addAll(collector.getMemory(params));
result.addAll(collector.getFileSystem(params));
result.addAll(collector.getConfig(params));
break;
case 1:
result.addAll(collector.coll(params));
break;
case 2:
result.addAll(collector.collSpecProcess(params));
break;
case 3:
result.addAll(collector.collSpecProcessList(params));
break;
case 4:
result.addAll(collector.getCpu(params));
result.addAll(collector.getMemory(params));
result.addAll(collector.getFileSystem(params));
result.addAll(collector.getConfig(params));
break;
case 5:
result.addAll(collector.getCpu(params));
break;
case 6:
result.addAll(collector.getMemory(params));
break;
case 7:
result.addAll(collector.getFileSystem(params));
break;
case 8:
result.addAll(collector.getConfig(params));
break;
default:
break;
}
System.out.println("***************Windows Collect Test End*********************");
for (int i = 0; i < result.size(); i++) {
TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) result.get(i);
System.out.println(record.UNIT_ID + "\t" + record.KPI_ID + "\t" + record.KPI_VALUE + "\t" + record.CLL_TIME);
}
}
}