Methods Summary |
---|
public com.sun.jmx.snmp.agent.SnmpMibHandler | addMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib)Adds a new MIB in the SNMP MIB handler.
if (mib == null) {
throw new IllegalArgumentException() ;
}
if(!mibs.contains(mib))
mibs.addElement(mib);
root.register(mib);
return this;
|
public com.sun.jmx.snmp.agent.SnmpMibHandler | addMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, com.sun.jmx.snmp.SnmpOid[] oids)Adds a new MIB in the SNMP MIB handler.
This method is to be called to set a specific agent to a specific OID.
This can be useful when dealing with MIB overlapping.
Some OID can be implemented in more than one MIB. In this case,
the OID nearer agent will be used on SNMP operations.
if (mib == null) {
throw new IllegalArgumentException() ;
}
//If null oid array, just add it to the mib.
if(oids == null)
return addMib(mib);
if(!mibs.contains(mib))
mibs.addElement(mib);
for (int i = 0; i < oids.length; i++) {
root.register(mib, oids[i].longValue());
}
return this;
|
public com.sun.jmx.snmp.agent.SnmpMibHandler | addMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName)Adds a new MIB in the SNMP MIB handler. In SNMP V1 and V2 the
contextName is useless and this method
is equivalent to addMib(SnmpMibAgent mib) .
return addMib(mib);
|
public com.sun.jmx.snmp.agent.SnmpMibHandler | addMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName, com.sun.jmx.snmp.SnmpOid[] oids)Adds a new MIB in the SNMP MIB handler. In SNMP V1 and V2 the
contextName is useless and this method
is equivalent to addMib(SnmpMibAgent mib, SnmpOid[] oids) .
return addMib(mib, oids);
|
synchronized void | closeInformSocketIfNeeded()Close informSocket if the SNMP protocol adaptor is not ONLINE.
if ((informSession != null) && (state != ONLINE)) {
informSession.destroySession() ;
informSession = null ;
}
|
synchronized void | closeTrapSocketIfNeeded()Close trapSocket if the SNMP protocol adaptor is not ONLINE.
if ((trapSocket != null) && (state != ONLINE)) {
trapSocket.close() ;
trapSocket = null ;
}
|
protected java.lang.Thread | createMainThread()
final Thread t = super.createMainThread();
t.setDaemon(true);
return t;
|
void | createSnmpRequestHandler(com.sun.jmx.snmp.daemon.SnmpAdaptorServer server, int id, java.net.DatagramSocket s, java.net.DatagramPacket p, SnmpMibTree tree, java.util.Vector m, java.lang.Object a, com.sun.jmx.snmp.SnmpPduFactory factory, com.sun.jmx.snmp.agent.SnmpUserDataFactory dataFactory, javax.management.MBeanServer f, javax.management.ObjectName n)
final SnmpRequestHandler handler =
new SnmpRequestHandler(this, id, s, p, tree, m, a, factory,
dataFactory, f, n);
threadService.submitTask(handler);
|
protected void | doBind()Creates the datagram socket.
try {
synchronized (this) {
socket = new DatagramSocket(port, address) ;
}
dbgTag = makeDebugTag();
} catch (SocketException e) {
if (e.getMessage().equals(InterruptSysCallMsg))
throw new InterruptedException(e.toString()) ;
else {
if (isDebugOn()) {
debug("doBind", "cannot bind on port " + port);
}
throw new CommunicationException(e) ;
}
}
|
protected void | doError(java.lang.Exception e)
return;
|
protected void | doProcess()Not used in this context.
|
protected void | doReceive()Reads a packet from the datagram socket and creates a request
handler which decodes and processes the request.
// Let's wait for something to be received.
//
try {
packet = new DatagramPacket(new byte[bufferSize], bufferSize) ;
socket.receive(packet);
int state = getState();
if(state != ONLINE) {
if (isTraceOn()) {
trace("doReceive",
"received a message but state not online, returning.");
}
return;
}
createSnmpRequestHandler(this, servedClientCount, socket,
packet, root, mibs, ipacl, pduFactory,
userDataFactory, topMBS, objectName);
} catch (SocketException e) {
// Let's check if we have been interrupted by stop().
//
if (e.getMessage().equals(InterruptSysCallMsg))
throw new InterruptedException(e.toString()) ;
else
throw new CommunicationException(e) ;
} catch (InterruptedIOException e) {
throw new InterruptedException(e.toString()) ;
} catch (CommunicationException e) {
throw e ;
} catch (Exception e) {
throw new CommunicationException(e) ;
}
if (isTraceOn()) {
trace("doReceive", "received a message");
}
|
protected void | doUnbind()Closes the datagram socket.
if (isTraceOn()) {
trace("doUnbind","Finally close the socket");
}
synchronized (this) {
if (socket != null) {
socket.close() ;
socket = null ;
// Important to inform finalize() that the socket is closed...
}
}
closeTrapSocketIfNeeded() ;
closeInformSocketIfNeeded() ;
|
protected void | finalize()Finalizer of the SNMP protocol adaptor objects.
This method is called by the garbage collector on an object
when garbage collection determines that there are no more
references to the object.
Closes the datagram socket associated to this SNMP protocol adaptor.
try {
if (socket != null) {
socket.close() ;
socket = null ;
}
threadService.terminate();
} catch (Exception e) {
trace("finalize","Exception in finalizer: " +e);
}
|
public int | getActiveClientCount()Gets the number of managers currently being processed by this
SNMP protocol adaptor.
return super.getActiveClientCount();
|
java.net.InetAddress | getAddress()Gets the IP address to bind.
This getter is used to initialize the DatagramSocket in the
SnmpSocket object created for the inform request stuff.
return address;
|
com.sun.jmx.snmp.agent.SnmpMibAgent | getAgentMib(com.sun.jmx.snmp.SnmpOid oid)
return root.getAgentMib(oid);
|
public boolean | getAuthRespEnabled()Returns true if this SNMP protocol adaptor sends a
response in case of authentication failure.
When this feature is enabled, the SNMP protocol adaptor sends a
response with noSuchName or readOnly when
the authentication failed. If the flag is disabled, the
SNMP protocol adaptor trashes the PDU silently.
The default behavior is to send responses.
return authRespEnabled ;
|
public boolean | getAuthTrapEnabled()Returns true if authentication traps are enabled.
When this feature is enabled, the SNMP protocol adaptor sends
an authenticationFailure trap each time an
authentication fails.
The default behaviour is to send authentication traps.
return authTrapEnabled ;
|
protected int | getBindTries()The number of times the communicator server will attempt
to bind before giving up.
We attempt only once...
return 1;
|
public java.lang.Integer | getBufferSize()Returns the buffer size of this SNMP protocol adaptor.
This buffer size is used for both incoming request and outgoing
inform requests.
By default, buffer size 1024 is used.
return new Integer(bufferSize) ;
|
public java.lang.String | getEnterpriseOid()Returns the enterprise OID. It is used by
{@link #snmpV1Trap snmpV1Trap} to fill the 'enterprise' field of the
trap request.
return enterpriseOid.toString() ;
|
public com.sun.jmx.snmp.InetAddressAcl | getInetAddressAcl()Returns the Ip address based ACL used by this SNMP protocol adaptor.
return (InetAddressAcl)ipacl;
|
public int | getInformPort()Returns the port used by this SNMP protocol adaptor for sending
inform requests. By default, port 162 is used.
return informPort;
|
public int | getMaxActiveClientCount()Gets the maximum number of managers that this SNMP protocol adaptor can
process concurrently.
return super.getMaxActiveClientCount();
|
public final int | getMaxTries()Gets the number of times to try sending an inform request before
giving up.
By default, a maximum of 3 tries is used.
return maxTries;
|
public java.lang.String[] | getMibs()Returns the names of the MIBs available in this SNMP protocol adaptor.
String[] result = new String[mibs.size()] ;
int i = 0 ;
for (Enumeration e = mibs.elements() ; e.hasMoreElements() ;) {
SnmpMibAgent mib = (SnmpMibAgent)e.nextElement() ;
result[i++] = mib.getMibName();
}
return result ;
|
public com.sun.jmx.snmp.SnmpPduFactory | getPduFactory()Returns the message factory of this SNMP protocol adaptor.
return pduFactory ;
|
public int | getPort()Return the actual port to which the adaptor is bound.
Can be different from the port given at construction time if
that port number was 0.
synchronized (this) {
if (socket != null) return socket.getLocalPort();
}
return super.getPort();
|
public java.lang.String | getProtocol()Returns the protocol of this SNMP protocol adaptor.
return "snmp";
|
public int | getServedClientCount()Gets the number of managers that have been processed by this
SNMP protocol adaptor since its creation.
return super.getServedClientCount();
|
public java.lang.Long | getSnmpInASNParseErrs()Returns the snmpInASNParseErrs value defined in MIB-II.
return new Long(snmpInASNParseErrs);
|
public java.lang.Long | getSnmpInBadCommunityNames()Returns the snmpInBadCommunityNames value defined in
MIB-II.
return new Long(snmpInBadCommunityNames);
|
public java.lang.Long | getSnmpInBadCommunityUses()Returns the snmpInBadCommunityUses value defined in MIB-II.
return new Long(snmpInBadCommunityUses);
|
public java.lang.Long | getSnmpInBadVersions()Returns the snmpInBadVersions value defined in MIB-II.
return new Long(snmpInBadVersions);
|
public java.lang.Long | getSnmpInGetNexts()Returns the snmpInGetNexts value defined in MIB-II.
return new Long(snmpInGetNexts);
|
public java.lang.Long | getSnmpInGetRequests()Returns the snmpInGetRequests value defined in MIB-II.
return new Long(snmpInGetRequests);
|
public java.lang.Long | getSnmpInPkts()Returns the snmpInPkts value defined in MIB-II.
return new Long(snmpInPkts);
|
public java.lang.Long | getSnmpInSetRequests()Returns the snmpInSetRequests value defined in MIB-II.
return new Long(snmpInSetRequests);
|
public java.lang.Long | getSnmpInTotalReqVars()Returns the snmpInTotalReqVars value defined in MIB-II.
return new Long(snmpInTotalReqVars);
|
public java.lang.Long | getSnmpInTotalSetVars()Returns the snmpInTotalSetVars value defined in MIB-II.
return new Long(snmpInTotalSetVars);
|
public java.lang.Long | getSnmpOutBadValues()Returns the snmpOutBadValues value defined in MIB-II.
return new Long(snmpOutBadValues);
|
public java.lang.Long | getSnmpOutGenErrs()Returns the snmpOutGenErrs value defined in MIB-II.
return new Long(snmpOutGenErrs);
|
public java.lang.Long | getSnmpOutGetResponses()Returns the snmpOutGetResponses value defined in MIB-II.
return new Long(snmpOutGetResponses);
|
public java.lang.Long | getSnmpOutNoSuchNames()Returns the snmpOutNoSuchNames value defined in MIB-II.
return new Long(snmpOutNoSuchNames);
|
public java.lang.Long | getSnmpOutPkts()Returns the snmpOutPkts value defined in MIB-II.
return new Long(snmpOutPkts);
|
public java.lang.Long | getSnmpOutTooBigs()Returns the snmpOutTooBigs value defined in MIB-II.
return new Long(snmpOutTooBigs);
|
public java.lang.Long | getSnmpOutTraps()Returns the snmpOutTraps value defined in MIB-II.
return new Long(snmpOutTraps);
|
public java.lang.Long | getSnmpProxyDrops()Returns the snmpProxyDrops value defined in RFC
1907 NMPv2-MIB .
return new Long(0);
|
public java.lang.Long | getSnmpSilentDrops()Returns the snmpSilentDrops value defined in RFC
1907 NMPv2-MIB .
return new Long(snmpSilentDrops);
|
long | getSysUpTime()Returns the time (in hundreths of second) elapsed since the SNMP
protocol adaptor startup.
return (System.currentTimeMillis() - startUpTime) / 10 ;
|
public final int | getTimeout()Gets the timeout to wait for an inform response from the manager.
By default, a timeout of 3 seconds is used.
return timeout;
|
public java.lang.Integer | getTrapPort()Returns the port used by this SNMP protocol adaptor for sending traps.
By default, port 162 is used.
return new Integer(trapPort) ;
|
public com.sun.jmx.snmp.agent.SnmpUserDataFactory | getUserDataFactory()Get the user-data factory associated with this SNMP protocol adaptor.
return userDataFactory;
|
private com.sun.jmx.snmp.SnmpIpAddress | handleMultipleIpVersion(byte[] address)
if(address.length == 4)
return new SnmpIpAddress(address);
else {
if(isDebugOn())
debug("handleMultipleIPVersion",
"Not an IPv4 address, return null");
return null;
}
|
void | incSnmpInASNParseErrs(int n)
snmpInASNParseErrs += n ;
|
void | incSnmpInBadCommunityNames(int n)
snmpInBadCommunityNames += n ;
|
void | incSnmpInBadCommunityUses(int n)
snmpInBadCommunityUses += n ;
|
void | incSnmpInBadVersions(int n)
snmpInBadVersions += n ;
|
void | incSnmpSilentDrops(int n)
snmpSilentDrops += n ;
|
private void | init(java.lang.Object acl, int p, java.net.InetAddress a)Common initializations.
root= new SnmpMibTree();
// The default Agent is initialized with a SnmpErrorHandlerAgent agent.
root.setDefaultAgent(new SnmpErrorHandlerAgent());
// For the trap time, use the time the agent started ...
//
startUpTime= java.lang.System.currentTimeMillis();
maxActiveClientCount = 10;
// Create the default message factory
pduFactory = new SnmpPduFactoryBER() ;
port = p ;
ipacl = acl ;
address = a ;
if ((ipacl == null) && (useAcl == true))
throw new IllegalArgumentException("ACL object cannot be null") ;
threadService = new ThreadService(threadNumber);
|
java.lang.String | makeDebugTag()Returns the string used in debug traces.
return "SnmpAdaptorServer["+ getProtocol() + ":" + getPort() + "]";
|
public static final int | mapErrorStatus(int errorStatus, int protocolVersion, int reqPduType)Method that maps an SNMP error status in the passed protocolVersion
according to the provided pdu type.
return SnmpSubRequestHandler.mapErrorStatus(errorStatus,
protocolVersion,
reqPduType);
|
synchronized void | openInformSocketIfNeeded()Open informSocket if it's not already done.
if (informSession == null) {
informSession = new SnmpSession(this) ;
if (isTraceOn()) {
trace("openInformSocketIfNeeded",
"to send inform requests and receive inform responses");
}
}
|
synchronized void | openTrapSocketIfNeeded()Open trapSocket if it's not already done.
if (trapSocket == null) {
trapSocket = new DatagramSocket(0, address) ;
if (isTraceOn()) {
trace("openTrapSocketIfNeeded", "using port " +
trapSocket.getLocalPort() + " to send traps");
}
}
|
public void | postDeregister()Not used in this context.
super.postDeregister();
|
public void | postRegister(java.lang.Boolean registrationDone)Not used in this context.
super.postRegister(registrationDone);
|
public void | preDeregister()Not used in this context.
super.preDeregister();
|
public javax.management.ObjectName | preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)Allows the MBean to perform any operations it needs before being
registered in the MBean server.
If the name of the SNMP protocol adaptor MBean is not specified,
it is initialized with the default value:
{@link com.sun.jmx.snmp.ServiceName#DOMAIN
com.sun.jmx.snmp.ServiceName.DOMAIN}:{@link
com.sun.jmx.snmp.ServiceName#SNMP_ADAPTOR_SERVER
com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_SERVER}.
If any exception is raised, the SNMP protocol adaptor MBean will
not be registered in the MBean server.
if (name == null) {
name = new ObjectName(server.getDefaultDomain() + ":" +
com.sun.jmx.snmp.ServiceName.SNMP_ADAPTOR_SERVER);
}
return (super.preRegister(server, name));
|
private void | readObject(java.io.ObjectInputStream stream)Control the way the SnmpAdaptorServer service is deserialized.
// Call the default deserialization of the object.
//
stream.defaultReadObject();
// Call the specific initialization for the SnmpAdaptorServer service.
// This is for transient structures to be initialized to specific
// default values.
//
mibs = new Vector() ;
|
public boolean | removeMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName)Removes the specified MIB from the SNMP protocol adaptor.
In SNMP V1 and V2 the contextName is useless and this
method is equivalent to removeMib(SnmpMibAgent mib) .
return removeMib(mib);
|
public boolean | removeMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib)Removes the specified MIB from the SNMP protocol adaptor.
root.unregister(mib);
return (mibs.removeElement(mib)) ;
|
public boolean | removeMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, com.sun.jmx.snmp.SnmpOid[] oids)Removes the specified MIB from the SNMP protocol adaptor.
root.unregister(mib, oids);
return (mibs.removeElement(mib)) ;
|
public boolean | removeMib(com.sun.jmx.snmp.agent.SnmpMibAgent mib, java.lang.String contextName, com.sun.jmx.snmp.SnmpOid[] oids)Removes the specified MIB from the SNMP protocol adaptor.
return removeMib(mib, oids);
|
private void | sendTrapMessage(com.sun.jmx.snmp.SnmpMessage msg)Send the specified message on trapSocket.
byte[] buffer = new byte[bufferSize] ;
DatagramPacket packet = new DatagramPacket(buffer, buffer.length) ;
int encodingLength = msg.encodeMessage(buffer) ;
packet.setLength(encodingLength) ;
packet.setAddress(msg.address) ;
packet.setPort(msg.port) ;
if (isTraceOn()) {
trace("sendTrapMessage", "sending trap to " + msg.address + ":" +
msg.port);
}
trapSocket.send(packet) ;
if (isTraceOn()) {
trace("sendTrapMessage", "sent to " + msg.address + ":" +
msg.port);
}
snmpOutTraps++;
snmpOutPkts++;
|
private void | sendTrapPdu(com.sun.jmx.snmp.SnmpPduPacket pdu)Send the specified trap PDU to every destinations from the ACL file.
// Make an SNMP message from the pdu
//
SnmpMessage msg = null ;
try {
msg = (SnmpMessage)pduFactory.encodeSnmpPdu(pdu, bufferSize) ;
if (msg == null) {
throw new SnmpStatusException(
SnmpDefinitions.snmpRspAuthorizationError) ;
}
}
catch (SnmpTooBigException x) {
if (isDebugOn()) {
debug("sendTrapPdu", "trap pdu is too big");
debug("sendTrapPdu", "trap hasn't been sent to anyone");
}
throw new SnmpStatusException(SnmpDefinitions.snmpRspTooBig) ;
// FIXME: is the right exception to throw ?
// We could simply forward SnmpTooBigException ?
}
// Now send the SNMP message to each destination
//
int sendingCount = 0 ;
openTrapSocketIfNeeded() ;
if (ipacl != null) {
Enumeration ed = ((InetAddressAcl)ipacl).getTrapDestinations() ;
while (ed.hasMoreElements()) {
msg.address = (InetAddress)ed.nextElement() ;
Enumeration ec = ((InetAddressAcl)ipacl).
getTrapCommunities(msg.address) ;
while (ec.hasMoreElements()) {
msg.community = ((String)ec.nextElement()).getBytes() ;
try {
sendTrapMessage(msg) ;
sendingCount++ ;
}
catch (SnmpTooBigException x) {
if (isDebugOn()) {
debug("sendTrapPdu", "trap pdu is too big");
debug("sendTrapPdu", "trap hasn't been sent to "+
msg.address);
}
}
}
}
}
// If there is no destination defined or if everything has failed
// we tried to send the trap to the local host (as suggested by
// mister Olivier Reisacher).
//
if (sendingCount == 0) {
try {
msg.address = InetAddress.getLocalHost() ;
sendTrapMessage(msg) ;
} catch (SnmpTooBigException x) {
if (isDebugOn()) {
debug("sendTrapPdu", "trap pdu is too big");
debug("sendTrapPdu", "trap hasn't been sent");
}
} catch (UnknownHostException e) {
if (isDebugOn()) {
debug("sendTrapPdu", "cannot get the local host");
debug("sendTrapPdu", "trap hasn't been sent");
}
}
}
closeTrapSocketIfNeeded() ;
|
private void | sendTrapPdu(java.net.InetAddress addr, com.sun.jmx.snmp.SnmpPduPacket pdu)Send the specified trap PDU to the specified destination.
// Make an SNMP message from the pdu
//
SnmpMessage msg = null ;
try {
msg = (SnmpMessage)pduFactory.encodeSnmpPdu(pdu, bufferSize) ;
if (msg == null) {
throw new SnmpStatusException(
SnmpDefinitions.snmpRspAuthorizationError) ;
}
} catch (SnmpTooBigException x) {
if (isDebugOn()) {
debug("sendTrapPdu", "trap pdu is too big");
debug("sendTrapPdu",
"trap hasn't been sent to the specified host");
}
throw new SnmpStatusException(SnmpDefinitions.snmpRspTooBig) ;
// FIXME: is the right exception to throw ?
// We could simply forward SnmpTooBigException ?
}
// Now send the SNMP message to specified destination
//
openTrapSocketIfNeeded() ;
if (addr != null) {
msg.address = addr;
try {
sendTrapMessage(msg) ;
} catch (SnmpTooBigException x) {
if (isDebugOn()) {
debug("sendTrapPdu", "trap pdu is too big");
debug("sendTrapPdu", "trap hasn't been sent to " +
msg.address);
}
}
}
closeTrapSocketIfNeeded() ;
|
public void | setAuthRespEnabled(boolean enabled)Sets the flag indicating if responses need to be sent in case of
authentication failure.
authRespEnabled = enabled ;
|
public void | setAuthTrapEnabled(boolean enabled)Sets the flag indicating if traps need to be sent in case of
authentication failure.
authTrapEnabled = enabled ;
|
public void | setBufferSize(java.lang.Integer s)Sets the buffer size of this SNMP protocol adaptor.
This buffer size is used for both incoming request and outgoing
inform requests.
if ((state == ONLINE) || (state == STARTING)) {
throw new IllegalStateException("Stop server before carrying out"+
" this operation");
}
bufferSize = s.intValue() ;
|
public void | setEnterpriseOid(java.lang.String oid)Sets the enterprise OID.
enterpriseOid = new SnmpOid(oid) ;
|
public void | setInformPort(int port)Sets the port used by this SNMP protocol adaptor for sending
inform requests.
if (port < 0)
throw new IllegalArgumentException("Inform request port "+
"cannot be a negative value");
informPort= port ;
|
public void | setMaxActiveClientCount(int c)Sets the maximum number of managers this SNMP protocol adaptor can
process concurrently.
super.setMaxActiveClientCount(c);
|
public final synchronized void | setMaxTries(int newMaxTries)Changes the maximun number of times to try sending an inform
request before giving up.
if (newMaxTries < 0)
throw new IllegalArgumentException();
maxTries = newMaxTries;
|
public void | setPduFactory(com.sun.jmx.snmp.SnmpPduFactory factory)Sets the message factory of this SNMP protocol adaptor.
if (factory == null)
pduFactory = new SnmpPduFactoryBER() ;
else
pduFactory = factory ;
|
public final synchronized void | setTimeout(int newTimeout)Changes the timeout to wait for an inform response from the manager.
if (newTimeout < 0)
throw new IllegalArgumentException();
timeout= newTimeout;
|
public void | setTrapPort(java.lang.Integer port)Sets the port used by this SNMP protocol adaptor for sending traps.
setTrapPort(port.intValue());
|
public void | setTrapPort(int port)Sets the port used by this SNMP protocol adaptor for sending traps.
int val= port ;
if (val < 0) throw new
IllegalArgumentException("Trap port cannot be a negative value");
trapPort= val ;
|
public void | setUserDataFactory(com.sun.jmx.snmp.agent.SnmpUserDataFactory factory)Set the user-data factory of this SNMP protocol adaptor.
userDataFactory = factory ;
|
private SnmpInformRequest | snmpInformRequest(java.net.InetAddress addr, int port, java.lang.String cs, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)
if (!isActive()) {
throw new IllegalStateException(
"Start SNMP adaptor server before carrying out this operation");
}
if (isTraceOn()) {
trace("snmpInformRequest", "trapOid=" + trapOid);
}
// First, make an SNMP inform pdu:
// We clone varBindList and insert sysUpTime and snmpTrapOid variables.
//
SnmpVarBindList fullVbl ;
if (varBindList != null)
fullVbl = (SnmpVarBindList)varBindList.clone() ;
else
fullVbl = new SnmpVarBindList(2) ;
SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
0);
// Next, send the pdu to the specified destination
//
openInformSocketIfNeeded() ;
return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
|
public java.util.Vector | snmpInformRequest(SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends an inform using SNMP V2 inform request format.
The inform request is sent to each destination defined in the ACL
file (if available).
If no ACL file or no destinations are available, the inform request is
sent to the local host.
The variable list included in the outgoing inform is composed of
the following items:
sysUpTime.0 with its current value
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
To send an inform request, the SNMP adaptor server must be active.
if (!isActive()) {
throw new IllegalStateException(
"Start SNMP adaptor server before carrying out this operation");
}
if (isTraceOn()) {
trace("snmpInformRequest", "trapOid=" + trapOid);
}
// First, make an SNMP inform pdu:
// We clone varBindList and insert sysUpTime and snmpTrapOid variables.
//
SnmpVarBindList fullVbl ;
if (varBindList != null)
fullVbl = (SnmpVarBindList)varBindList.clone() ;
else
fullVbl = new SnmpVarBindList(2) ;
SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
0);
// Next, send the pdu to the specified destination
//
openInformSocketIfNeeded() ;
// Now send the SNMP message to each destination
//
Vector informReqList = new Vector();
InetAddress addr = null;
String cs = null;
if (ipacl != null) {
Enumeration ed = ((InetAddressAcl)ipacl).getInformDestinations() ;
while (ed.hasMoreElements()) {
addr = (InetAddress)ed.nextElement() ;
Enumeration ec = ((InetAddressAcl)ipacl).
getInformCommunities(addr) ;
while (ec.hasMoreElements()) {
cs = (String)ec.nextElement() ;
informReqList.addElement(
informSession.makeAsyncRequest(addr, cs, cb,
fullVbl,getInformPort())) ;
}
}
}
return informReqList ;
|
public SnmpInformRequest | snmpInformRequest(java.net.InetAddress addr, java.lang.String cs, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends an inform using SNMP V2 inform request format.
The inform is sent to the specified InetAddress
destination
using the specified community string.
The variable list included in the outgoing inform is composed
of the following items:
sysUpTime.0 with its current value
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
To send an inform request, the SNMP adaptor server must be active.
return snmpInformRequest(addr,
getInformPort(),
cs,
cb,
trapOid,
varBindList);
|
public SnmpInformRequest | snmpInformRequest(com.sun.jmx.snmp.SnmpPeer peer, SnmpInformHandler cb, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends an inform using SNMP V2 inform request format.
The inform is sent to the specified SnmpPeer
destination.
The community string used is the one located in the
SnmpPeer parameters
(SnmpParameters.getInformCommunity() ).
The variable list included in the outgoing inform is composed
of the following items:
sysUpTime.0 with its current value
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
To send an inform request, the SNMP adaptor server must be active.
SnmpParameters p = (SnmpParameters) peer.getParams();
return snmpInformRequest(peer.getDestAddr(),
peer.getDestPort(),
p.getInformCommunity(),
cb,
trapOid,
varBindList);
|
public void | snmpPduTrap(java.net.InetAddress address, com.sun.jmx.snmp.SnmpPduPacket pdu)Send the specified trap PDU to the passed InetAddress .
if(address != null)
sendTrapPdu(address, pdu);
else
sendTrapPdu(pdu);
|
public void | snmpPduTrap(com.sun.jmx.snmp.SnmpPeer peer, com.sun.jmx.snmp.SnmpPduPacket pdu)Send the specified trap PDU to the passed SnmpPeer .
if(peer != null) {
pdu.port = peer.getDestPort();
sendTrapPdu(peer.getDestAddr(), pdu);
}
else {
pdu.port = getTrapPort().intValue();
sendTrapPdu(pdu);
}
|
public void | snmpV1Trap(int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends a trap using SNMP V1 trap format.
The trap is sent to each destination defined in the ACL file
(if available).
If no ACL file or no destinations are available, the trap is sent
to the local host.
if (isTraceOn()) {
trace("snmpV1Trap", "generic=" + generic +
", specific=" + specific);
}
// First, make an SNMP V1 trap pdu
//
SnmpPduTrap pdu = new SnmpPduTrap() ;
pdu.address = null ;
pdu.port = trapPort ;
pdu.type = pduV1TrapPdu ;
pdu.version = snmpVersionOne ;
pdu.community = null ;
pdu.enterprise = enterpriseOid ;
pdu.genericTrap = generic ;
pdu.specificTrap = specific ;
pdu.timeStamp = getSysUpTime();
if (varBindList != null) {
pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
varBindList.copyInto(pdu.varBindList);
}
else
pdu.varBindList = null ;
// If the local host cannot be determined, we put 0.0.0.0 in agentAddr
try {
if (address != null)
pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
else pdu.agentAddr =
handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
} catch (UnknownHostException e) {
byte[] zeroedAddr = new byte[4];
pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
}
// Next, send the pdu to all destinations defined in ACL
//
sendTrapPdu(pdu) ;
|
public void | snmpV1Trap(java.net.InetAddress addr, java.lang.String cs, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends a trap using SNMP V1 trap format.
The trap is sent to the specified InetAddress
destination using the specified community string (and the ACL file
is not used).
if (isTraceOn()) {
trace("snmpV1Trap", "generic=" + generic + ", specific=" +
specific);
}
// First, make an SNMP V1 trap pdu
//
SnmpPduTrap pdu = new SnmpPduTrap() ;
pdu.address = null ;
pdu.port = trapPort ;
pdu.type = pduV1TrapPdu ;
pdu.version = snmpVersionOne ;
if(cs != null)
pdu.community = cs.getBytes();
else
pdu.community = null ;
pdu.enterprise = enterpriseOid ;
pdu.genericTrap = generic ;
pdu.specificTrap = specific ;
pdu.timeStamp = getSysUpTime();
if (varBindList != null) {
pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
varBindList.copyInto(pdu.varBindList);
}
else
pdu.varBindList = null ;
// If the local host cannot be determined, we put 0.0.0.0 in agentAddr
try {
if (address != null)
pdu.agentAddr = handleMultipleIpVersion(address.getAddress());
else pdu.agentAddr =
handleMultipleIpVersion(InetAddress.getLocalHost().getAddress());
} catch (UnknownHostException e) {
byte[] zeroedAddr = new byte[4];
pdu.agentAddr = handleMultipleIpVersion(zeroedAddr) ;
}
// Next, send the pdu to the specified destination
//
if(addr != null)
sendTrapPdu(addr, pdu) ;
else
sendTrapPdu(pdu);
|
public void | snmpV1Trap(java.net.InetAddress addr, com.sun.jmx.snmp.SnmpIpAddress agentAddr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid enterpOid, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)Sends a trap using SNMP V1 trap format.
The trap is sent to the specified InetAddress
destination using the specified parameters (and the ACL file is not
used).
Note that if the specified InetAddress destination is null,
then the ACL file mechanism is used.
snmpV1Trap(addr,
trapPort,
agentAddr,
cs,
enterpOid,
generic,
specific,
varBindList,
time);
|
public void | snmpV1Trap(com.sun.jmx.snmp.SnmpPeer peer, com.sun.jmx.snmp.SnmpIpAddress agentAddr, com.sun.jmx.snmp.SnmpOid enterpOid, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)Sends a trap using SNMP V1 trap format.
The trap is sent to the specified SnmpPeer destination.
The community string used is the one located in the
SnmpPeer parameters
(SnmpParameters.getRdCommunity() ).
SnmpParameters p = (SnmpParameters) peer.getParams();
snmpV1Trap(peer.getDestAddr(),
peer.getDestPort(),
agentAddr,
p.getRdCommunity(),
enterpOid,
generic,
specific,
varBindList,
time);
|
private void | snmpV1Trap(java.net.InetAddress addr, int port, com.sun.jmx.snmp.SnmpIpAddress agentAddr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid enterpOid, int generic, int specific, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)
if (isTraceOn()) {
trace("snmpV1Trap", "generic=" + generic + ", specific=" +
specific);
}
// First, make an SNMP V1 trap pdu
//
SnmpPduTrap pdu = new SnmpPduTrap() ;
pdu.address = null ;
pdu.port = port ;
pdu.type = pduV1TrapPdu ;
pdu.version = snmpVersionOne ;
//Diff start
if(cs != null)
pdu.community = cs.getBytes();
else
pdu.community = null ;
//Diff end
// Diff start
if(enterpOid != null)
pdu.enterprise = enterpOid;
else
pdu.enterprise = enterpriseOid ;
//Diff end
pdu.genericTrap = generic ;
pdu.specificTrap = specific ;
//Diff start
if(time != null)
pdu.timeStamp = time.longValue();
else
pdu.timeStamp = getSysUpTime();
//Diff end
if (varBindList != null) {
pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
varBindList.copyInto(pdu.varBindList);
}
else
pdu.varBindList = null ;
if (agentAddr == null) {
// If the local host cannot be determined,
// we put 0.0.0.0 in agentAddr
try {
final InetAddress inetAddr =
(address!=null)?address:InetAddress.getLocalHost();
agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
} catch (UnknownHostException e) {
byte[] zeroedAddr = new byte[4];
agentAddr = handleMultipleIpVersion(zeroedAddr);
}
}
pdu.agentAddr = agentAddr;
// Next, send the pdu to the specified destination
//
// Diff start
if(addr != null)
sendTrapPdu(addr, pdu) ;
else
sendTrapPdu(pdu);
//End diff
|
public void | snmpV2Trap(com.sun.jmx.snmp.SnmpPeer peer, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)Sends a trap using SNMP V2 trap format.
The trap is sent to the specified SnmpPeer destination.
The community string used is the one located in the
SnmpPeer parameters
(SnmpParameters.getRdCommunity() ).
The variable list included in the outgoing trap is composed of
the following items:
sysUpTime.0 with the value specified by
time
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
SnmpParameters p = (SnmpParameters) peer.getParams();
snmpV2Trap(peer.getDestAddr(),
peer.getDestPort(),
p.getRdCommunity(),
trapOid,
varBindList,
time);
|
public void | snmpV2Trap(com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends a trap using SNMP V2 trap format.
The trap is sent to each destination defined in the ACL file
(if available). If no ACL file or no destinations are available,
the trap is sent to the local host.
The variable list included in the outgoing trap is composed of
the following items:
sysUpTime.0 with its current value
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
if (isTraceOn()) {
trace("snmpV2Trap", "trapOid=" + trapOid);
}
// First, make an SNMP V2 trap pdu
// We clone varBindList and insert sysUpTime and snmpTrapOid
//
SnmpPduRequest pdu = new SnmpPduRequest() ;
pdu.address = null ;
pdu.port = trapPort ;
pdu.type = pduV2TrapPdu ;
pdu.version = snmpVersionTwo ;
pdu.community = null ;
SnmpVarBindList fullVbl ;
if (varBindList != null)
fullVbl = (SnmpVarBindList)varBindList.clone() ;
else
fullVbl = new SnmpVarBindList(2) ;
SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
0);
pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
fullVbl.copyInto(pdu.varBindList) ;
// Next, send the pdu to all destinations defined in ACL
//
sendTrapPdu(pdu) ;
|
public void | snmpV2Trap(java.net.InetAddress addr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList)Sends a trap using SNMP V2 trap format.
The trap is sent to the specified InetAddress
destination using the specified community string (and the ACL file
is not used).
The variable list included in the outgoing trap is composed of
the following items:
sysUpTime.0 with its current value
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
if (isTraceOn()) {
trace("snmpV2Trap", "trapOid=" + trapOid);
}
// First, make an SNMP V2 trap pdu
// We clone varBindList and insert sysUpTime and snmpTrapOid
//
SnmpPduRequest pdu = new SnmpPduRequest() ;
pdu.address = null ;
pdu.port = trapPort ;
pdu.type = pduV2TrapPdu ;
pdu.version = snmpVersionTwo ;
if(cs != null)
pdu.community = cs.getBytes();
else
pdu.community = null;
SnmpVarBindList fullVbl ;
if (varBindList != null)
fullVbl = (SnmpVarBindList)varBindList.clone() ;
else
fullVbl = new SnmpVarBindList(2) ;
SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
0);
pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
fullVbl.copyInto(pdu.varBindList) ;
// Next, send the pdu to the specified destination
//
if(addr != null)
sendTrapPdu(addr, pdu);
else
sendTrapPdu(pdu);
|
public void | snmpV2Trap(java.net.InetAddress addr, java.lang.String cs, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)Sends a trap using SNMP V2 trap format.
The trap is sent to the specified InetAddress
destination using the specified parameters (and the ACL file is not
used).
Note that if the specified InetAddress destination is null,
then the ACL file mechanism is used.
The variable list included in the outgoing trap is composed of the
following items:
sysUpTime.0 with the value specified by
time
snmpTrapOid.0 with the value specified by
trapOid
all the (oid,values) from the specified
varBindList
snmpV2Trap(addr,
trapPort,
cs,
trapOid,
varBindList,
time);
|
private void | snmpV2Trap(java.net.InetAddress addr, int port, java.lang.String cs, com.sun.jmx.snmp.SnmpOid trapOid, com.sun.jmx.snmp.SnmpVarBindList varBindList, com.sun.jmx.snmp.SnmpTimeticks time)
if (isTraceOn()) {
trace("snmpV2Trap", "trapOid=" + trapOid +
"\ncommunity=" + cs + "\naddr=" + addr +
"\nvarBindList=" + varBindList + "\ntime=" + time +
"\ntrapPort=" + port);
}
// First, make an SNMP V2 trap pdu
// We clone varBindList and insert sysUpTime and snmpTrapOid
//
SnmpPduRequest pdu = new SnmpPduRequest() ;
pdu.address = null ;
pdu.port = port ;
pdu.type = pduV2TrapPdu ;
pdu.version = snmpVersionTwo ;
if(cs != null)
pdu.community = cs.getBytes();
else
pdu.community = null;
SnmpVarBindList fullVbl ;
if (varBindList != null)
fullVbl = (SnmpVarBindList)varBindList.clone() ;
else
fullVbl = new SnmpVarBindList(2) ;
// Only difference with other
SnmpTimeticks sysUpTimeValue = null;
if(time != null)
sysUpTimeValue = time;
else
sysUpTimeValue = new SnmpTimeticks(getSysUpTime()) ;
//End of diff
fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0) ;
fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue),
0);
pdu.varBindList = new SnmpVarBind[fullVbl.size()] ;
fullVbl.copyInto(pdu.varBindList) ;
// Next, send the pdu to the specified destination
//
// Diff start
if(addr != null)
sendTrapPdu(addr, pdu) ;
else
sendTrapPdu(pdu);
//End diff
|
public void | stop()Stops this SNMP protocol adaptor.
Closes the datagram socket.
Has no effect if this SNMP protocol adaptor is OFFLINE or
STOPPING .
final int port = getPort();
if (isTraceOn()) {
trace("stop", "Stopping: using port " + port);
}
if ((state == ONLINE) || (state == STARTING)){
super.stop();
try {
DatagramSocket sn = new DatagramSocket(0);
try {
byte[] ob = new byte[1];
DatagramPacket pk;
if (address != null)
pk = new DatagramPacket(ob , 1, address, port);
else
pk = new DatagramPacket(ob , 1,
java.net.InetAddress.getLocalHost(), port);
if (isTraceOn()) {
trace("stop", "Sending: using port " + port);
}
sn.send(pk);
} finally {
sn.close();
}
} catch (Throwable e){
if (isDebugOn()) {
debug("stop", e);
}
}
}
|
void | updateErrorCounters(int errorStatus)
switch(errorStatus) {
case snmpRspNoError:
snmpOutGetResponses++;
break;
case snmpRspGenErr:
snmpOutGenErrs++;
break;
case snmpRspBadValue:
snmpOutBadValues++;
break;
case snmpRspNoSuchName:
snmpOutNoSuchNames++;
break;
case snmpRspTooBig:
snmpOutTooBigs++;
break;
default:
break;
}
snmpOutPkts++ ;
|
void | updateRequestCounters(int pduType)
switch(pduType) {
case pduGetRequestPdu:
snmpInGetRequests++;
break;
case pduGetNextRequestPdu:
snmpInGetNexts++;
break;
case pduSetRequestPdu:
snmpInSetRequests++;
break;
default:
break;
}
snmpInPkts++ ;
|
void | updateVarCounters(int pduType, int n)
switch(pduType) {
case pduGetRequestPdu:
case pduGetNextRequestPdu:
case pduGetBulkRequestPdu:
snmpInTotalReqVars += n ;
break ;
case pduSetRequestPdu:
snmpInTotalSetVars += n ;
break ;
}
|