01: /*
02: * GNetWatch
03: * Copyright 2006, 2007 Alexandre Fenyo
04: * gnetwatch@fenyo.net
05: *
06: * This file is part of GNetWatch.
07: *
08: * GNetWatch is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU General Public License as published by
10: * the Free Software Foundation; either version 2 of the License, or
11: * (at your option) any later version.
12: *
13: * GNetWatch is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with GNetWatch; if not, write to the Free Software
20: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21: */
22:
23: package net.fenyo.gnetwatch;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27:
28: import java.net.*;
29: import java.io.*;
30:
31: import org.snmp4j.*;
32: import org.snmp4j.smi.*;
33: import org.snmp4j.mp.*;
34: import org.snmp4j.transport.*;
35: import org.snmp4j.event.*;
36: import org.snmp4j.security.*;
37:
38: /**
39: * This class maintains general structures to deal with SNMP: transport, security model, ...
40: * This class delivers SNMP queriers.
41: * @author Alexandre Fenyo
42: * @version $Id: SNMPManager.java,v 1.10 2007/03/03 00:38:19 fenyo Exp $
43: */
44:
45: public class SNMPManager {
46: private static Log log = LogFactory.getLog(SNMPManager.class);
47: private final Snmp snmp;
48:
49: /**
50: * Constructor.
51: * @param none.
52: * @throws IOException SNMP4J exception.
53: */
54: public SNMPManager() throws IOException {
55: TransportMapping transport = new DefaultUdpTransportMapping();
56: snmp = new Snmp(transport);
57: final USM usm = new USM(SecurityProtocols.getInstance(),
58: new OctetString(MPv3.createLocalEngineID()), 0);
59: SecurityModels.getInstance().addSecurityModel(usm);
60: transport.listen();
61: }
62:
63: /**
64: * Creates a new querier.
65: * @param address target address.
66: * @return SNMPQuerier new querier.
67: */
68: public SNMPQuerier getQuerier(final InetAddress address) {
69: return new SNMPQuerier(address, this );
70: }
71:
72: /**
73: * Returns the SNMP4J Snmp instance used to perform further SNMP queries.
74: * @param none.
75: * @return Snmp Snmp instance.
76: */
77: protected Snmp getSNMP() {
78: return snmp;
79: }
80: }
|