KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > SNMPManager


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

23
24 package net.fenyo.gnetwatch;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import java.net.*;
30 import java.io.*;
31
32 import org.snmp4j.*;
33 import org.snmp4j.smi.*;
34 import org.snmp4j.mp.*;
35 import org.snmp4j.transport.*;
36 import org.snmp4j.event.*;
37 import org.snmp4j.security.*;
38
39 /**
40  * This class maintains general structures to deal with SNMP: transport, security model, ...
41  * This class delivers SNMP queriers.
42  * @author Alexandre Fenyo
43  * @version $Id: SNMPManager.java,v 1.10 2007/03/03 00:38:19 fenyo Exp $
44  */

45
46 public class SNMPManager {
47   private static Log log = LogFactory.getLog(SNMPManager.class);
48   private final Snmp snmp;
49   
50   /**
51    * Constructor.
52    * @param none.
53    * @throws IOException SNMP4J exception.
54    */

55   public SNMPManager() throws IOException {
56     TransportMapping transport = new DefaultUdpTransportMapping();
57     snmp = new Snmp(transport);
58     final USM usm = new USM(SecurityProtocols.getInstance(), 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 }
81
Popular Tags