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 package uk.co.westhawk.snmp.beans;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 import uk.co.westhawk.snmp.stack.*;
52 import uk.co.westhawk.snmp.pdu.*;
53 import java.awt.*;
54 import java.util.*;
55 import java.text.*;
56 import java.lang.*;
57 import java.io.*;
58 import java.beans.*;
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 public class AscendActiveSessionBean extends SNMPRunBean implements Observer {
93 private static final String version_id = "@(#)$Id: AscendActiveSessionBean.java,v 1.13 2006/01/25 18:08:55 birgit Exp $ Copyright Westhawk Ltd";
94
95
96
97
98
99 public final static String ssnActiveCallReferenceNum = "1.3.6.1.4.1.529.12.3.1.1";
100
101
102
103
104 public final static String ssnActiveUserName = "1.3.6.1.4.1.529.12.3.1.4";
105
106
107
108
109 public final static String ssnActiveUserIPAddress = "1.3.6.1.4.1.529.12.3.1.5";
110
111
112
113
114 public final static String ssnActiveUserSubnetMask = "1.3.6.1.4.1.529.12.3.1.6";
115
116
117
118
119 public final static String ssnActiveCurrentService = "1.3.6.1.4.1.529.12.3.1.7";
120
121 private final static int NR_OID = 5;
122
123 private final static int none = 1;
124 private final static int other = 2;
125 private final static int ppp = 3;
126 private final static int slip = 4;
127 private final static int mpp = 5;
128 private final static int x25 = 6;
129 private final static int combinet = 7;
130 private final static int frameRelay = 8;
131 private final static int euraw = 9;
132 private final static int euui = 10;
133 private final static int telnet = 11;
134 private final static int telnetBinary = 12;
135 private final static int rawTcp = 13;
136 private final static int terminalServer = 14;
137 private final static int mp = 15;
138 private final static int virtualConnect = 16;
139 private final static int dchannelX25 = 17;
140 private final static int dtpt = 18;
141
142 private final static String msg_service[] = {
143 "",
144 "none",
145 "other",
146 "ppp",
147 "slip",
148 "mpp",
149 "x25",
150 "combinet",
151 "frameRelay",
152 "euraw",
153 "euui",
154 "telnet",
155 "telnetBinary",
156 "rawTcp",
157 "terminalServer",
158 "mp",
159 "virtualConnect",
160 "dchannelX25",
161 "dtpt"
162 };
163
164 private GetNextPdu_vec pdu;
165
166 private boolean isGetNextInFlight;
167 private Date lastUpdateDate = null;
168
169 private int callReferenceNum = 0;
170 private String userName = "";
171 private String userIPAddress = "0.0.0.0";
172 private String userSubnetMask = "0.0.0.0";
173 private String currentService = "none";
174
175
176
177
178 public AscendActiveSessionBean() {
179 }
180
181
182
183
184
185
186
187
188
189 public AscendActiveSessionBean(String h, int p) {
190 this(h, p, null);
191 }
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206 public AscendActiveSessionBean(String h, int p, String b) {
207 this();
208 setHost(h);
209 setPort(p);
210 setBindAddress(b);
211 }
212
213
214
215
216
217
218
219 public Date getLastUpdateDate() {
220 return lastUpdateDate;
221 }
222
223
224
225
226
227
228 public String getUserName() {
229 return userName;
230 }
231
232
233
234
235
236
237
238 public String getUserIPAddress() {
239 return userIPAddress;
240 }
241
242
243
244
245
246
247
248 public String getUserSubnetMask() {
249 return userSubnetMask;
250 }
251
252
253
254
255
256
257
258 public String getCurrentService() {
259 return currentService;
260 }
261
262
263
264
265
266 public void action() {
267 if (isHostPortReachable()) {
268 lastUpdateDate = new Date();
269 isGetNextInFlight = false;
270 setRunning(true);
271 }
272 }
273
274
275
276
277
278
279
280
281 public void run() {
282 while (context != null && isRunning()) {
283 if (isGetNextInFlight == false) {
284
285 isGetNextInFlight = true;
286 pdu = new GetNextPdu_vec(context, NR_OID);
287 pdu.addObserver(this);
288
289 pdu.addOid(ssnActiveCallReferenceNum);
290 pdu.addOid(ssnActiveUserName);
291 pdu.addOid(ssnActiveUserIPAddress);
292 pdu.addOid(ssnActiveUserSubnetMask);
293 pdu.addOid(ssnActiveCurrentService);
294 try {
295 pdu.send();
296 } catch (PduException exc) {
297 System.out.println("PduException " + exc.getMessage());
298 } catch (IOException exc) {
299 System.out.println("IOException " + exc.getMessage());
300 }
301 }
302
303 try {
304 Thread.sleep(interval);
305 } catch (InterruptedException ix) {
306 ;
307 }
308 }
309 }
310
311
312
313
314
315
316
317
318
319
320 public void update(Observable obs, Object ov) {
321 int service;
322 varbind[] var;
323
324 pdu = (GetNextPdu_vec) obs;
325
326 if (pdu.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR) {
327 var = (varbind[]) ov;
328 callReferenceNum = ((AsnInteger) var[0].getValue()).getValue();
329
330 if (callReferenceNum > 0) {
331 userName = ((AsnOctets) var[1].getValue()).getValue();
332 userIPAddress = ((AsnOctets) var[2].getValue()).getValue();
333 userSubnetMask = ((AsnOctets) var[3].getValue()).getValue();
334
335 service = ((AsnInteger) var[4].getValue()).getValue();
336 currentService = msg_service[service];
337 }
338
339
340 lastUpdateDate = new Date();
341 isGetNextInFlight = false;
342 firePropertyChange("services", null, null);
343 }
344 }
345
346 }