CollCiscoPixWithSNMP.java
6.96 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
/*
* Created on 2006-8-8
*
*
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.sitech.ismp.coll;
/**
* PIX平台 () 系统 OID
*
* PIX 506 .1.3.6.1.4.1.9.1.389
*
* PIX 515 .1.3.6.1.4.1.9.1.390
*
* PIX 520 .1.3.6.1.4.1.9.1.391
*
* PIX 525 .1.3.6.1.4.1.9.1.392
*
* PIX 535 .1.3.6.1.4.1.9.1.393
*
* 其它 .1.3.6.1.4.1.9.1.227 (初始PIX 防火墙OID)
*/
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
import org.apache.log4j.Logger;
import com.adventnet.snmp.beans.SnmpTarget;
import com.adventnet.snmp.snmp2.SnmpOID;
import com.sitech.ismp.app.coll.RPCTarget;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
/**
* @author Administrator
*
*
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CollCiscoPixWithSNMP implements CollCiscoPixMBean {
SnmpTarget target = null;
String ObjectIP = null;
private boolean DEBUG = false;
RPCTarget rpctarget = null;
static Logger logger = Logger.getLogger("LOGER");
String hostname = "";
String community = null;
String ip = null;
int port = 0;
String servicename = null;
private Vector result = new Vector();
public Vector coll(HashMap params) {
String hostname = (String) params.get("HOSTNAME"); // 局域网内对应采集的主机名
String ip = (String) params.get("IP"); // 要采集的weblogic7.0 IP
int port = Integer.parseInt((String) params.get("PORT")); // SNMP端口
this.hostname = hostname;
this.ip = ip;
this.port = port;
logger.info(ip); // 记录日志
coll();
return result;
}
private void coll() {
try {
pix506();
pix515();
pix520();
pix525();
pix535();
pixOther();
String unitID = "10-12-11-10-10:" + hostname + "-total";
// FM-00-04-003-03 主机状态 true 连接正常 false 连接失败可能宕机
setResult("true", unitID, "FM-00-04-003-03");
} catch (Exception e) {
String unitID = "10-12-11-10-10:" + hostname + "-total";
// FM-00-04-003-03 主机状态 true 连接正常 false 连接失败可能宕机
setResult("false", unitID, "FM-00-04-003-03");
logger.error(e);
}
}
// pix506
private void pix506() {
System.out.println("Begin pix506()");
boolean bool = true;
Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.9.1.389", bool);
if (vc_active.size() > 0) {
String count = (String) vc_active.elementAt(0);
setResult(count, "pix506", "CM-00-02-001-10");
// setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11");
}
System.out.println("End pix506()");
}
// pix515
private void pix515() {
System.out.println("Begin pix515()");
boolean bool = true;
Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.9.1.390", bool);
if (vc_active.size() > 0) {
String count = (String) vc_active.elementAt(0);
setResult(count, "pix515", "CM-00-02-001-11");
// setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11");
}
System.out.println("End pix515()");
}
// pix515
private void pix520() {
System.out.println("Begin pix515()");
boolean bool = true;
Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.9.1.391", bool);
if (vc_active.size() > 0) {
String count = (String) vc_active.elementAt(0);
setResult(count, "pix520", "CM-00-02-001-12");
// setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11");
}
System.out.println("End pix520()");
}
// pix525
private void pix525() {
System.out.println("Begin pix525()");
boolean bool = true;
Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.9.1.392", bool);
if (vc_active.size() > 0) {
String count = (String) vc_active.elementAt(0);
setResult(count, "pix525", "CM-00-02-001-13");
// setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11");
}
System.out.println("End pix525()");
}
// pix535
private void pix535() {
System.out.println("Begin pix535()");
boolean bool = true;
Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.9.1.393", bool);
if (vc_active.size() > 0) {
String count = (String) vc_active.elementAt(0);
setResult(count, "pix535", "CM-00-02-001-14");
// setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11");
}
System.out.println("End pix535()");
}
// 其它 (初始PIX 防火墙OID)
private void pixOther() {
System.out.println("Begin pixOther()");
boolean bool = true;
Vector vc_active = walkKPIInfo(".1.3.6.1.4.1.9.1.227", bool);
if (vc_active.size() > 0) {
String count = (String) vc_active.elementAt(0);
setResult(count, "pixOther", "CM-00-02-001-15");
// setResult((String)params.get("WEBLOGIC.server")+"@"+(String)params.get("WEBLOGIC.IP"),"serverListenAddress","CM-10-13-10-11");
}
System.out.println("End pixOther()");
}
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);
}
}
//
public Vector walkKPIInfo(String oid, boolean bool) {
Vector tmp_result = new Vector();
try {
Vector tmp_oid = new Vector();
target.setObjectID(oid);
target.oidList[0] = new com.adventnet.snmp.snmp2.SnmpOID(oid);
// Each
// entry
// contains
// objects
// for a
// particular
// file
// system.(HP)
int maxtry = 0;
com.adventnet.snmp.snmp2.SnmpOID[] oidList = target
.getSnmpOIDList();
// System.out.println("oidList.length="+oidList.length);
if (oidList == null) {
System.out.println("oidList is null");
return null;
} else {
SnmpOID rootoid = oidList[0];
SnmpOID curroid = null;
while (maxtry++ < 3000) { // limit the max getnexts to 5000
String result1[] = target.snmpGetNextList();
if (result1 == null) {
target.oidList[0] = curroid;
continue;
// break;
}
if (!SnmpTarget.isInSubTree(rootoid, target.getSnmpOID()))
break; // check first column
// System.out.println("result1.length=" +result1.length);
for (int i = 0; i < result1.length; i++) { // print the
// values
// System.out.println(target.getObjectID(i) + ": "
// + result1[i]);
tmp_result.add(result1[i]);
tmp_oid.add(target.getObjectID(i));
}
if (result1[0].compareTo("NULL") == 0)
break;
}
if (maxtry == 1) { // we did not get a valid row
System.err
.println("Request failed, timed out or no available data("
+ oid + "). \n " + target.getErrorString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return tmp_result;
}
}