use of com.sun.jmx.snmp.SnmpVarBindList in project jdk8u_jdk by JetBrains.
the class SnmpAdaptorServer method snmpInformRequest.
private SnmpInformRequest snmpInformRequest(InetAddress addr, int port, String cs, SnmpInformHandler cb, SnmpOid trapOid, SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException {
if (!isActive()) {
throw new IllegalStateException("Start SNMP adaptor server before carrying out this operation");
}
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "snmpInformRequest", "trapOid=" + trapOid);
}
// First, make an SNMP inform pdu:
// We clone varBindList and insert sysUpTime and snmpTrapOid variables.
//
SnmpVarBindList fullVbl;
if (varBindList != null)
fullVbl = 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);
}
use of com.sun.jmx.snmp.SnmpVarBindList in project jdk8u_jdk by JetBrains.
the class SnmpAdaptorServer method snmpV2Trap.
/**
* Sends a trap using SNMP V2 trap format.
* <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
* destination using the specified community string (and the ACL file
* is not used).
* <BR>The variable list included in the outgoing trap is composed of
* the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value</LI>
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by
* <CODE>trapOid</CODE></LI>
* <LI><CODE>all the (oid,values)</CODE> from the specified
* <CODE>varBindList</CODE></LI>
* </UL>
*
* @param addr The <CODE>InetAddress</CODE> destination of the trap.
* @param cs The community string to be used for the trap.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @exception IOException An I/O error occurred while sending the trap.
* @exception SnmpStatusException If the trap exceeds the limit
* defined by <CODE>bufferSize</CODE>.
*/
@Override
public void snmpV2Trap(InetAddress addr, String cs, SnmpOid trapOid, SnmpVarBindList varBindList) throws IOException, SnmpStatusException {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "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 = 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);
//
if (addr != null)
sendTrapPdu(addr, pdu);
else
sendTrapPdu(pdu);
}
use of com.sun.jmx.snmp.SnmpVarBindList in project jdk8u_jdk by JetBrains.
the class SnmpAdaptorServer method snmpInformRequest.
// SENDING SNMP INFORMS STUFF
//---------------------------
/**
* Sends an inform using SNMP V2 inform request format.
* <BR>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.
* <BR>The variable list included in the outgoing inform is composed of
* the following items:
* <UL>
* <LI><CODE>sysUpTime.0</CODE> with its current value</LI>
* <LI><CODE>snmpTrapOid.0</CODE> with the value specified by
* <CODE>trapOid</CODE></LI>
* <LI><CODE>all the (oid,values)</CODE> from the specified
* <CODE>varBindList</CODE></LI>
* </UL>
* To send an inform request, the SNMP adaptor server must be active.
*
* @param cb The callback that is invoked when a request is complete.
* @param trapOid The OID identifying the trap.
* @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
*
* @return A vector of {@link com.sun.jmx.snmp.daemon.SnmpInformRequest}
* objects.
* <P>If there is no destination host for this inform request,
* the returned vector will be empty.
*
* @exception IllegalStateException This method has been invoked while
* the SNMP adaptor server was not active.
* @exception IOException An I/O error occurred while sending the
* inform request.
* @exception SnmpStatusException If the inform request exceeds the
* limit defined by <CODE>bufferSize</CODE>.
*/
@Override
public Vector<SnmpInformRequest> snmpInformRequest(SnmpInformHandler cb, SnmpOid trapOid, SnmpVarBindList varBindList) throws IllegalStateException, IOException, SnmpStatusException {
if (!isActive()) {
throw new IllegalStateException("Start SNMP adaptor server before carrying out this operation");
}
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "snmpInformRequest", "trapOid=" + trapOid);
}
// First, make an SNMP inform pdu:
// We clone varBindList and insert sysUpTime and snmpTrapOid variables.
//
SnmpVarBindList fullVbl;
if (varBindList != null)
fullVbl = 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<SnmpInformRequest> informReqList = new Vector<>();
InetAddress addr;
String cs;
if (ipacl != null) {
Enumeration<InetAddress> ed = ipacl.getInformDestinations();
while (ed.hasMoreElements()) {
addr = ed.nextElement();
Enumeration<String> ec = ipacl.getInformCommunities(addr);
while (ec.hasMoreElements()) {
cs = ec.nextElement();
informReqList.addElement(informSession.makeAsyncRequest(addr, cs, cb, fullVbl, getInformPort()));
}
}
}
return informReqList;
}
use of com.sun.jmx.snmp.SnmpVarBindList in project jdk8u_jdk by JetBrains.
the class SnmpRequestHandler method makeResponsePdu.
/**
* Here we make a response pdu from a request pdu.
* We return null if there is no pdu to reply.
*/
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu, Object userData) {
SnmpAdaptorServer snmpServer = (SnmpAdaptorServer) adaptorServer;
SnmpPduPacket respPdu = null;
snmpServer.updateRequestCounters(reqPdu.type);
if (reqPdu.varBindList != null)
snmpServer.updateVarCounters(reqPdu.type, reqPdu.varBindList.length);
if (checkPduType(reqPdu)) {
respPdu = checkAcl(reqPdu);
if (respPdu == null) {
// reqPdu is accepted by ACLs
if (mibs.size() < 1) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "makeResponsePdu", "Request " + reqPdu.requestId + " received but no MIB registered.");
}
return makeNoMibErrorPdu((SnmpPduRequest) reqPdu, userData);
}
switch(reqPdu.type) {
case SnmpPduPacket.pduGetRequestPdu:
case SnmpPduPacket.pduGetNextRequestPdu:
case SnmpPduPacket.pduSetRequestPdu:
respPdu = makeGetSetResponsePdu((SnmpPduRequest) reqPdu, userData);
break;
case SnmpPduPacket.pduGetBulkRequestPdu:
respPdu = makeGetBulkResponsePdu((SnmpPduBulk) reqPdu, userData);
break;
}
} else {
// We send this response only if authResEnabled is true.
if (!snmpServer.getAuthRespEnabled()) {
// No response should be sent
respPdu = null;
}
if (snmpServer.getAuthTrapEnabled()) {
// A trap must be sent
try {
snmpServer.snmpV1Trap(SnmpPduTrap.trapAuthenticationFailure, 0, new SnmpVarBindList());
} catch (Exception x) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "makeResponsePdu", "Failure when sending authentication trap", x);
}
}
}
}
}
return respPdu;
}
use of com.sun.jmx.snmp.SnmpVarBindList in project jdk8u_jdk by JetBrains.
the class SnmpAdaptorServer method snmpV2Trap.
private void snmpV2Trap(InetAddress addr, int port, String cs, SnmpOid trapOid, SnmpVarBindList varBindList, SnmpTimeticks time) throws IOException, SnmpStatusException {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
final StringBuilder strb = new StringBuilder().append("trapOid=").append(trapOid).append("\ncommunity=").append(cs).append("\naddr=").append(addr).append("\nvarBindList=").append(varBindList).append("\ntime=").append(time).append("\ntrapPort=").append(port);
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "snmpV2Trap", strb.toString());
}
// 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 = varBindList.clone();
else
fullVbl = new SnmpVarBindList(2);
// Only difference with other
SnmpTimeticks sysUpTimeValue;
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);
// Diff start
if (addr != null)
sendTrapPdu(addr, pdu);
else
sendTrapPdu(pdu);
//End diff
}
Aggregations