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 public class OneNTServiceBean extends SNMPRunBean implements Observer {
90 private static final String version_id = "@(#)$Id: OneNTServiceBean.java,v 1.13 2006/01/25 18:08:56 birgit Exp $ Copyright Westhawk Ltd";
91
92 private GetPdu_vec pdu;
93
94 private boolean isPduInFlight;
95 private Date lastUpdateDate = null;
96
97 private String index = "";
98 private String name = "";
99 private String instState = "";
100 private String operState = "";
101 private boolean canUninst = false;
102 private boolean canPause = false;
103
104 private final static int NR_OID = 5;
105 private final static String svSvcName = "1.3.6.1.4.1.77.1.2.3.1.1";
106 private final static String svSvcInstalledState = "1.3.6.1.4.1.77.1.2.3.1.2";
107 private final static String svSvcOperatingState = "1.3.6.1.4.1.77.1.2.3.1.3";
108 private final static String svSvcCanBeUninstalled = "1.3.6.1.4.1.77.1.2.3.1.4";
109 private final static String svSvcCanBePaused = "1.3.6.1.4.1.77.1.2.3.1.5";
110
111 public final static String msg_inst_state[] = {
112 "unknown",
113 "uninstalled",
114 "install pending",
115 "uninstall pending",
116 "installed"
117 };
118
119 public final static String msg_oper_state[] = {
120 "unknown",
121 "active",
122 "continue pending",
123 "pause pending",
124 "paused"
125 };
126
127 public final static int cannot_be_uninstalled = 1;
128 public final static int can_be_uninstalled = 2;
129
130 public final static int cannot_be_paused = 1;
131 public final static int can_be_paused = 2;
132
133
134
135
136 public OneNTServiceBean() {
137 }
138
139
140
141
142
143
144
145
146
147 public OneNTServiceBean(String h, int p) {
148 this(h, p, null);
149 }
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 public OneNTServiceBean(String h, int p, String b) {
165 this();
166 setHost(h);
167 setPort(p);
168 setBindAddress(b);
169 }
170
171
172
173
174
175
176
177
178 public void setIndex(String ind) {
179 if (ind != null && ind.length() > 0) {
180 index = ind;
181 }
182 }
183
184
185
186
187
188
189
190 public String getIndex() {
191 return index;
192 }
193
194
195
196
197
198
199 public String getName() {
200 return name;
201 }
202
203
204
205
206
207
208
209 public String getInstalledState() {
210 return instState;
211 }
212
213
214
215
216
217
218
219 public String getOperatingState() {
220 return operState;
221 }
222
223
224
225
226
227
228
229
230 public boolean getCanBeUninstalled() {
231 return canUninst;
232 }
233
234
235
236
237
238
239
240
241 public boolean getCanBePaused() {
242 return canPause;
243 }
244
245
246
247
248
249
250
251 public Date getLastUpdateDate() {
252 return lastUpdateDate;
253 }
254
255
256
257
258
259
260
261
262
263 public void action() {
264 if (isHostPortReachable()) {
265 lastUpdateDate = new Date();
266 isPduInFlight = false;
267 setRunning(true);
268 }
269 }
270
271
272
273
274
275
276
277
278 public void run() {
279 while (context != null && isRunning()) {
280 String ind = getIndex();
281 if (isPduInFlight == false && ind != null && ind.length() > 0) {
282 isPduInFlight = true;
283 pdu = new GetPdu_vec(context, NR_OID);
284 pdu.addObserver(this);
285 pdu.addOid(svSvcName + "." + ind);
286 pdu.addOid(svSvcInstalledState + "." + ind);
287 pdu.addOid(svSvcOperatingState + "." + ind);
288 pdu.addOid(svSvcCanBeUninstalled + "." + ind);
289 pdu.addOid(svSvcCanBePaused + "." + ind);
290 try {
291 pdu.send();
292 } catch (PduException exc) {
293 System.out.println("PduException " + exc.getMessage());
294 } catch (IOException exc) {
295 System.out.println("IOException " + exc.getMessage());
296 }
297 }
298
299 try {
300 Thread.sleep(interval);
301 } catch (InterruptedException ix) {
302 ;
303 }
304 }
305 }
306
307
308
309
310
311
312
313
314 public void update(Observable obs, Object ov) {
315 int nr;
316 pdu = (GetPdu_vec) obs;
317 varbind[] varbinds = (varbind[]) ov;
318
319 if (pdu.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR) {
320 name = ((AsnOctets) varbinds[0].getValue()).getValue();
321
322 nr = ((AsnInteger) varbinds[1].getValue()).getValue();
323 instState = msg_inst_state[nr];
324
325 nr = ((AsnInteger) varbinds[2].getValue()).getValue();
326 operState = msg_oper_state[nr];
327
328 nr = ((AsnInteger) varbinds[3].getValue()).getValue();
329 canUninst = (nr == can_be_uninstalled);
330
331 nr = ((AsnInteger) varbinds[4].getValue()).getValue();
332 canPause = (nr == can_be_paused);
333
334 lastUpdateDate = new Date();
335 isPduInFlight = false;
336 firePropertyChange("NTService", null, null);
337 }
338 }
339
340 }