Java Code Examples for com.sun.jmx.snmp.SnmpStatusException

The following are top voted examples for showing how to use com.sun.jmx.snmp.SnmpStatusException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: JvmOSMeta.java   Source Code and License 6 votes vote down vote up
/**
 * Get the value of a scalar variable
 */
public SnmpValue get(long var, Object data)
    throws SnmpStatusException {
    switch((int)var) {
        case 4:
            return new SnmpInt(node.getJvmOSProcessorCount());

        case 3:
            return new SnmpString(node.getJvmOSVersion());

        case 2:
            return new SnmpString(node.getJvmOSArch());

        case 1:
            return new SnmpString(node.getJvmOSName());

        default:
            break;
    }
    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
 
Example 2
Project: OpenJSharp   File: SnmpRequestTree.java   Source Code and License 6 votes vote down vote up
public static int mapSetException(int errorStatus, int version)
    throws SnmpStatusException {

    final int errorCode = errorStatus;

    if (version == SnmpDefinitions.snmpVersionOne)
        return errorCode;

    int mappedErrorCode = errorCode;

    // Now take care of V2 errorCodes that can be stored
    // in the varbind itself:
    if (errorCode == SnmpStatusException.noSuchObject)
        // noSuchObject => notWritable
        mappedErrorCode = SnmpStatusException.snmpRspNotWritable;

    else if (errorCode == SnmpStatusException.noSuchInstance)
        // noSuchInstance => notWritable
        mappedErrorCode = SnmpStatusException.snmpRspNotWritable;

    return mappedErrorCode;
}
 
Example 3
Project: jdk8u-jdk   File: SnmpRequestTree.java   Source Code and License 6 votes vote down vote up
public static int mapSetException(int errorStatus, int version)
    throws SnmpStatusException {

    final int errorCode = errorStatus;

    if (version == SnmpDefinitions.snmpVersionOne)
        return errorCode;

    int mappedErrorCode = errorCode;

    // Now take care of V2 errorCodes that can be stored
    // in the varbind itself:
    if (errorCode == SnmpStatusException.noSuchObject)
        // noSuchObject => notWritable
        mappedErrorCode = SnmpStatusException.snmpRspNotWritable;

    else if (errorCode == SnmpStatusException.noSuchInstance)
        // noSuchInstance => notWritable
        mappedErrorCode = SnmpStatusException.snmpRspNotWritable;

    return mappedErrorCode;
}
 
Example 4
Project: jdk8u-jdk   File: SnmpLoadedClassData.java   Source Code and License 6 votes vote down vote up
public final SnmpOid getNext(SnmpOid index) {
    int pos = 0;
    if (index == null) {
        if( (datas!= null) && (datas.length >= 1) )
            return new SnmpOid(0);
    }
    try {
        pos = (int) index.getOidArc(0);
    }catch(SnmpStatusException e) {
        return null;
    }

    if(pos < (datas.length - 1))
        return new SnmpOid(pos+1);
    else
        return null;
}
 
Example 5
Project: OpenJSharp   File: SnmpMibTable.java   Source Code and License 5 votes vote down vote up
/**
 * Generic handling of the <CODE>set</CODE> operation.
 * <p> The default implementation of this method is to
 * call the generated
 * <CODE>set(req,oid,depth+1)</CODE> method.
 * <p>
 * <pre>
 * public void set(SnmpMibSubRequest req, int depth)
 *    throws SnmpStatusException {
 *    final SnmpOid oid = req.getEntryOid();
 *    final int  action = getRowAction(req,oid,depth+1);
 *
 *    set(req,oid,depth+1);
 *    endRowAction(req,oid,depth+1,action);
 * }
 * </pre>
 * <p> You should not need to override this method in any cases, because
 * it will eventually call
 * <CODE>set(SnmpMibSubRequest req, int depth)</CODE> on the generated
 * derivative of <CODE>SnmpMibEntry</CODE>. If you need to implement
 * specific policies for minimizing the accesses made to some remote
 * underlying resources, or if you need to implement some consistency
 * checks between the different values provided in the varbind list,
 * you should then rather override
 * <CODE>set(SnmpMibSubRequest req, int depth)</CODE> on the generated
 * derivative of <CODE>SnmpMibEntry</CODE>.
 * <p>
 *
 */
@Override
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {


    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(),
                "set", "Entering set");
    }

    final SnmpOid     oid    = req.getEntryOid();
    final int         action = getRowAction(req,oid,depth+1);

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(),
                "set", "Calling set for " + req.getSize() + " varbinds");
    }

    set(req,oid,depth+1);

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(),
                "set", "Calling endRowAction");
    }

    endRowAction(req,oid,depth+1,action);

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(),
                "set", "RowAction finished");
    }

}
 
Example 6
Project: jdk8u-jdk   File: JvmRTClassPathEntryMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Check the value of a scalar variable
 */
public void check(SnmpValue x, long var, Object data)
    throws SnmpStatusException {
    switch((int) var) {
        case 2:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);

        case 1:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);

        default:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
    }
}
 
Example 7
Project: jdk8u-jdk   File: JvmRTLibraryPathTableMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the arc of the next columnar object following "var".
 */
public long getNextVarEntryId( SnmpOid rowOid, long var, Object data )
    throws SnmpStatusException {
    long nextvar = node.getNextVarId(var, data);
    while (!isReadableEntryId(rowOid, nextvar, data))
        nextvar = node.getNextVarId(nextvar, data);
    return nextvar;
}
 
Example 8
Project: jdk8u-jdk   File: JvmRTClassPathEntryMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Get the value of a scalar variable
 */
public SnmpValue get(long var, Object data)
    throws SnmpStatusException {
    switch((int)var) {
        case 2:
            return new SnmpString(node.getJvmRTClassPathItem());

        case 1:
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
        default:
            break;
    }
    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
 
Example 9
Project: jdk8u-jdk   File: JvmMemGCEntryMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Check the value of a scalar variable
 */
public void check(SnmpValue x, long var, Object data)
    throws SnmpStatusException {
    switch((int) var) {
        case 3:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);

        case 2:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);

        default:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
    }
}
 
Example 10
Project: OpenJSharp   File: JvmThreadingMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Return the name of the attribute corresponding to the SNMP variable identified by "id".
 */
public String getAttributeName(long id)
    throws SnmpStatusException {
    switch((int)id) {
        case 6:
            return "JvmThreadCpuTimeMonitoring";

        case 5:
            return "JvmThreadContentionMonitoring";

        case 4:
            return "JvmThreadTotalStartedCount";

        case 3:
            return "JvmThreadPeakCount";

        case 2:
            return "JvmThreadDaemonCount";

        case 1:
            return "JvmThreadCount";

        case 10: {
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
            }

        case 7:
            return "JvmThreadPeakCountReset";

        default:
            break;
    }
    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
 
Example 11
Project: jdk8u-jdk   File: JvmThreadInstanceEntryImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstLockedOwnerId" variable.
 */
public String getJvmThreadInstLockOwnerPtr() throws SnmpStatusException {
   long id = info.getLockOwnerId();

   if(id == -1)
       return new String("0.0");

   SnmpOid oid = JvmThreadInstanceTableMetaImpl.makeOid(id);

   return getJvmThreadInstIndexOid() + "." + oid.toString();
}
 
Example 12
Project: jdk8u-jdk   File: JvmMemoryImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Setter for the "JvmMemoryGCVerboseLevel" variable.
 */
public void setJvmMemoryGCVerboseLevel(EnumJvmMemoryGCVerboseLevel x)
    throws SnmpStatusException {
    if (JvmMemoryGCVerboseLevelVerbose.intValue() == x.intValue())
        ManagementFactory.getMemoryMXBean().setVerbose(true);
    else
        ManagementFactory.getMemoryMXBean().setVerbose(false);
}
 
Example 13
Project: OpenJSharp   File: JvmThreadInstanceEntryImpl.java   Source Code and License 5 votes vote down vote up
public static String getJvmThreadInstIndexOid()
    throws SnmpStatusException {
    if (jvmThreadInstIndexOid == null) {
        final SnmpOidTable  table = new JVM_MANAGEMENT_MIBOidTable();
        final SnmpOidRecord record =
            table.resolveVarName("jvmThreadInstIndex");
        jvmThreadInstIndexOid = record.getOid();
    }
    return jvmThreadInstIndexOid;
}
 
Example 14
Project: jdk8u-jdk   File: JvmMemPoolEntryImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Getter for the "JvmMemPoolCollectThreshold" variable.
 */
public Long getJvmMemPoolCollectThreshold() throws SnmpStatusException {
    if (!pool.isCollectionUsageThresholdSupported())
        return JvmMemoryImpl.Long0;
    final long val = pool.getCollectionUsageThreshold();
    if (val > -1) return  new Long(val);
    else return JvmMemoryImpl.Long0;
}
 
Example 15
Project: jdk8u-jdk   File: JvmRTLibraryPathEntryMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Get the value of a scalar variable
 */
public SnmpValue get(long var, Object data)
    throws SnmpStatusException {
    switch((int)var) {
        case 2:
            return new SnmpString(node.getJvmRTLibraryPathItem());

        case 1:
            throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
        default:
            break;
    }
    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
 
Example 16
Project: OpenJSharp   File: JvmMemPoolEntryImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Getter for the "JvmMemPoolThreshdSupport" variable.
 */
public EnumJvmMemPoolCollectThreshdSupport
    getJvmMemPoolCollectThreshdSupport()
    throws SnmpStatusException {
    if (pool.isCollectionUsageThresholdSupported())
        return EnumJvmMemPoolCollectThreshdSupported;
    else
        return EnumJvmMemPoolCollectThreshdUnsupported;
}
 
Example 17
Project: OpenJSharp   File: JvmThreadingImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Setter for the "JvmThreadCpuTimeMonitoring" variable.
 */
public void setJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring x)
    throws SnmpStatusException {

    ThreadMXBean mbean = getThreadMXBean();

    // We can trust the received value, it has been checked in
    // checkJvmThreadCpuTimeMonitoring
    if(JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue())
        mbean.setThreadCpuTimeEnabled(true);
    else
        mbean.setThreadCpuTimeEnabled(false);
}
 
Example 18
Project: OpenJSharp   File: SnmpMibTable.java   Source Code and License 5 votes vote down vote up
static void setRowStatusFail(SnmpMibSubRequest req, int errorStatus)
    throws SnmpStatusException {

    final SnmpVarBind statusvb  = req.getRowStatusVarBind();
    final SnmpStatusException x = new SnmpStatusException(errorStatus);
    req.registerSetException(statusvb,x);
}
 
Example 19
Project: OpenJSharp   File: JvmRTClassPathTableMeta.java   Source Code and License 5 votes vote down vote up
public boolean skipEntryVariable( SnmpOid rowOid, long var, Object data, int pduVersion) {
    try {
        JvmRTClassPathEntryMBean entry = (JvmRTClassPathEntryMBean) getEntry(rowOid);
        synchronized (this) {
            node.setInstance(entry);
            return node.skipVariable(var, data, pduVersion);
        }
    } catch (SnmpStatusException x) {
        return false;
    }
}
 
Example 20
Project: jdk8u-jdk   File: JvmRTBootClassPathEntryMeta.java   Source Code and License 5 votes vote down vote up
/**
 * Check the value of a scalar variable
 */
public void check(SnmpValue x, long var, Object data)
    throws SnmpStatusException {
    switch((int) var) {
        case 2:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);

        case 1:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);

        default:
            throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
    }
}
 
Example 21
Project: OpenJSharp   File: SnmpAdaptorServer.java   Source Code and License 4 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified parameters (and the ACL file is not
 * used).
 * Note that if the specified <CODE>InetAddress</CODE> destination is null,
 * then the ACL file mechanism is used.
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param cs The community string to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
public void snmpV1Trap(InetAddress addr,
                       SnmpIpAddress agentAddr,
                       String cs,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {
    snmpV1Trap(addr,
               trapPort,
               agentAddr,
               cs,
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example 22
Project: jdk8u-jdk   File: SnmpAdaptorServer.java   Source Code and License 4 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>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.
 *
 * @param generic The generic number of the trap.
 * @param specific The specific number of 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 snmpV1Trap(int generic, int specific,
                       SnmpVarBindList varBindList)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "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) ;
}
 
Example 23
Project: OpenJSharp   File: JvmMemManagerEntryMeta.java   Source Code and License 4 votes vote down vote up
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.set(this,req,depth);
}
 
Example 24
Project: OpenJSharp   File: JvmOSMeta.java   Source Code and License 4 votes vote down vote up
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.set(this,req,depth);
}
 
Example 25
Project: jdk8u-jdk   File: JvmCompilationImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmJITCompilerName" variable.
 */
public String getJvmJITCompilerName() throws SnmpStatusException {
    return JVM_MANAGEMENT_MIB_IMPL.
        validJavaObjectNameTC(getCompilationMXBean().getName());
}
 
Example 26
Project: OpenJSharp   File: JvmRTInputArgsEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmRTInputArgsIndex" variable.
 */
public Integer getJvmRTInputArgsIndex() throws SnmpStatusException {
    return new Integer(index);
}
 
Example 27
Project: jdk8u-jdk   File: JvmOSImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmRTProcessorCount" variable.
 */
public Integer getJvmOSProcessorCount() throws SnmpStatusException {
    return new Integer(getOSMBean().getAvailableProcessors());

}
 
Example 28
Project: OpenJSharp   File: SnmpV3Message.java   Source Code and License 4 votes vote down vote up
/**
 * Decodes the specified bytes and initializes this message.
 * For internal use only.
 *
 * @param inputBytes The bytes to be decoded.
 *
 * @exception SnmpStatusException If the specified bytes are not a valid encoding.
 */
public void decodeMessage(byte[] inputBytes, int byteCount)
    throws SnmpStatusException {

    try {
        BerDecoder bdec = new BerDecoder(inputBytes);
        bdec.openSequence();
        version = bdec.fetchInteger();
        bdec.openSequence();
        msgId = bdec.fetchInteger();
        msgMaxSize = bdec.fetchInteger();
        msgFlags = bdec.fetchOctetString()[0];
        msgSecurityModel =bdec.fetchInteger();
        bdec.closeSequence();
        msgSecurityParameters = bdec.fetchOctetString();
        if( (msgFlags & SnmpDefinitions.privMask) == 0 ) {
            bdec.openSequence();
            contextEngineId = bdec.fetchOctetString();
            contextName = bdec.fetchOctetString();
            data = bdec.fetchAny();
            dataLength = data.length;
            bdec.closeSequence();
        }
        else {
            encryptedPdu = bdec.fetchOctetString();
        }
        bdec.closeSequence() ;
    }
    catch(BerException x) {
        x.printStackTrace();
        throw new SnmpStatusException("Invalid encoding") ;
    }

    if (SNMP_LOGGER.isLoggable(Level.FINER)) {
        final StringBuilder strb = new StringBuilder()
        .append("Unmarshalled message : \n")
        .append("version : ").append(version)
        .append("\n")
        .append("msgId : ").append(msgId)
        .append("\n")
        .append("msgMaxSize : ").append(msgMaxSize)
        .append("\n")
        .append("msgFlags : ").append(msgFlags)
        .append("\n")
        .append("msgSecurityModel : ").append(msgSecurityModel)
        .append("\n")
        .append("contextEngineId : ").append(contextEngineId == null ? null :
            SnmpEngineId.createEngineId(contextEngineId))
        .append("\n")
        .append("contextName : ").append(contextName)
        .append("\n")
        .append("data : ").append(data)
        .append("\n")
        .append("dat len : ").append((data == null) ? 0 : data.length)
        .append("\n")
        .append("encryptedPdu : ").append(encryptedPdu)
        .append("\n");
        SNMP_LOGGER.logp(Level.FINER, SnmpV3Message.class.getName(),
                "decodeMessage", strb.toString());
    }
}
 
Example 29
Project: jdk8u-jdk   File: JvmRuntimeImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmRTName" variable.
 */
public String getJvmRTName() throws SnmpStatusException {
    return validDisplayStringTC(getRuntimeMXBean().getName());
}
 
Example 30
Project: OpenJSharp   File: JvmMemPoolEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmMemPoolCollectUsed" variable.
 */
public Long getJvmMemPoolCollectUsed() throws SnmpStatusException {
    final long val = getCollectMemoryUsage().getUsed();
    if (val > -1) return  new Long(val);
    else return JvmMemoryImpl.Long0;
}
 
Example 31
Project: OpenJSharp   File: JvmMemPoolEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmMemPoolPeakUsed" variable.
 */
public Long getJvmMemPoolPeakUsed() throws SnmpStatusException {
    final long val = getPeakMemoryUsage().getUsed();
    if (val > -1) return  new Long(val);
    else return JvmMemoryImpl.Long0;
}
 
Example 32
Project: jdk8u-jdk   File: JvmMemMgrPoolRelEntryMeta.java   Source Code and License 4 votes vote down vote up
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.set(this,req,depth);
}
 
Example 33
Project: OpenJSharp   File: JvmMemPoolEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmMemPoolType" variable.
 */
public EnumJvmMemPoolType getJvmMemPoolType() throws SnmpStatusException {
    return jvmMemPoolType(pool.getType());
}
 
Example 34
Project: OpenJSharp   File: JvmRuntimeMeta.java   Source Code and License 4 votes vote down vote up
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.set(this,req,depth);
}
 
Example 35
Project: jdk8u-jdk   File: SnmpAdaptorServer.java   Source Code and License 4 votes vote down vote up
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "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
}
 
Example 36
Project: jdk8u-jdk   File: JvmThreadingImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Checker for the "JvmThreadPeakCountReset" variable.
 */
public void checkJvmThreadPeakCountReset(Long x)
    throws SnmpStatusException {
}
 
Example 37
Project: OpenJSharp   File: JvmMemMgrPoolRelTableMeta.java   Source Code and License 4 votes vote down vote up
/**
 * Returns true if "var" identifies a readable scalar object.
 */
public boolean isReadableEntryId( SnmpOid rowOid, long var, Object data )
    throws SnmpStatusException {
    return node.isReadable(var);
}
 
Example 38
Project: OpenJSharp   File: JvmThreadInstanceEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmThreadInstId" variable.
 */
public Long getJvmThreadInstId() throws SnmpStatusException {
    return new Long(info.getThreadId());
}
 
Example 39
Project: OpenJSharp   File: JvmMemPoolEntryMeta.java   Source Code and License 4 votes vote down vote up
/**
 * Return the name of the attribute corresponding to the SNMP variable identified by "id".
 */
public String getAttributeName(long id)
    throws SnmpStatusException {
    switch((int)id) {
        case 33:
            return "JvmMemPoolCollectMaxSize";

        case 32:
            return "JvmMemPoolCollectCommitted";

        case 31:
            return "JvmMemPoolCollectUsed";

        case 133:
            return "JvmMemPoolCollectThreshdSupport";

        case 132:
            return "JvmMemPoolCollectThreshdCount";

        case 131:
            return "JvmMemPoolCollectThreshold";

        case 13:
            return "JvmMemPoolMaxSize";

        case 12:
            return "JvmMemPoolCommitted";

        case 11:
            return "JvmMemPoolUsed";

        case 10:
            return "JvmMemPoolInitSize";

        case 112:
            return "JvmMemPoolThreshdSupport";

        case 111:
            return "JvmMemPoolThreshdCount";

        case 110:
            return "JvmMemPoolThreshold";

        case 5:
            return "JvmMemPoolPeakReset";

        case 4:
            return "JvmMemPoolState";

        case 3:
            return "JvmMemPoolType";

        case 2:
            return "JvmMemPoolName";

        case 23:
            return "JvmMemPoolPeakMaxSize";

        case 1:
            return "JvmMemPoolIndex";

        case 22:
            return "JvmMemPoolPeakCommitted";

        case 21:
            return "JvmMemPoolPeakUsed";

        default:
            break;
    }
    throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
 
Example 40
Project: OpenJSharp   File: SnmpMibAgent.java   Source Code and License 4 votes vote down vote up
/**
 * Processes a <CODE>getBulk</CODE> operation using call to
 * <CODE>getNext</CODE>.
 * The method implements the <CODE>getBulk</CODE> operation by calling
 * appropriately the <CODE>getNext</CODE> method.
 *
 * @param req The SnmpMibRequest containing the variable list to be
 *        retrieved.
 *
 * @param nonRepeat The number of variables, starting with the first
 *    variable in the variable-bindings, for which a single lexicographic
 *    successor is requested.
 *
 * @param maxRepeat The number of lexicographic successors
 *    requested for each of the last R variables. R is the number of
 *    variables following the first nonRepeat variables for which
 *    multiple lexicographic successors are requested.
 *
 * @return The variable list containing returned values.
 *
 * @exception SnmpStatusException An error occurred during the operation.
 */
void getBulkWithGetNext(SnmpMibRequest req, int nonRepeat, int maxRepeat)
    throws SnmpStatusException {
    final Vector<SnmpVarBind> list = req.getSubList();

    // RFC 1905, Section 4.2.3, p14
    final int L = list.size() ;
    final int N = Math.max(Math.min(nonRepeat, L), 0) ;
    final int M = Math.max(maxRepeat, 0) ;
    final int R = L - N ;

    // Let's build the varBindList for the response pdu
    //
    // int errorStatus = SnmpDefinitions.snmpRspNoError ;
    // int errorIndex = 0 ;
    if (L != 0) {

        // Non-repeaters and first row of repeaters
        //
        getNext(req);

        // Now the remaining repeaters
        //
        Vector<SnmpVarBind> repeaters= splitFrom(list, N);
        SnmpMibRequestImpl repeatedReq =
            new SnmpMibRequestImpl(req.getEngine(),
                                   req.getPdu(),
                                   repeaters,
                                   SnmpDefinitions.snmpVersionTwo,
                                   req.getUserData(),
                                   req.getPrincipal(),
                                   req.getSecurityLevel(),
                                   req.getSecurityModel(),
                                   req.getContextName(),
                                   req.getAccessContextName());
        for (int i = 2 ; i <= M ; i++) {
            getNext(repeatedReq);
            concatVector(req, repeaters);
        }
    }
}
 
Example 41
Project: jdk8u-jdk   File: JvmThreadInstanceEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmThreadInstBlockCount" variable.
 */
public Long getJvmThreadInstBlockCount() throws SnmpStatusException {
    return new Long(info.getBlockedCount());
}
 
Example 42
Project: jdk8u-jdk   File: JvmMemManagerTableMeta.java   Source Code and License 4 votes vote down vote up
/**
 * check that the given "var" identifies a columnar object.
 */
public void validateVarEntryId( SnmpOid rowOid, long var, Object data )
    throws SnmpStatusException {
    node.validateVarId(var, data);
}
 
Example 43
Project: jdk8u-jdk   File: JvmRTLibraryPathEntryMeta.java   Source Code and License 4 votes vote down vote up
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.set(this,req,depth);
}
 
Example 44
Project: OpenJSharp   File: SnmpMib.java   Source Code and License 4 votes vote down vote up
/**
 * Checks if a <CODE>set</CODE> operation can be performed.
 * If the operation cannot be performed, the method will raise a
 * <CODE>SnmpStatusException</CODE>.
 *
 */
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent
// for java-doc
//
@Override
public void check(SnmpMibRequest req) throws SnmpStatusException {

    final int reqType = SnmpDefinitions.pduWalkRequest;
    // Builds the request tree: creation is allowed, operation
    // is atomic.
    SnmpRequestTree handlers = getHandlers(req,true,true,reqType);

    SnmpRequestTree.Handler h;
    SnmpMibNode meta;

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(),
                "check", "Processing handlers for CHECK... ");
    }

    // For each sub-request stored in the request-tree, invoke the
    // check() method.
    for (Enumeration<SnmpRequestTree.Handler> eh=handlers.getHandlers();eh.hasMoreElements();) {
        h = eh.nextElement();

        // Gets the Meta node. It can be either a Group Meta or a
        // Table Meta.
        //
        meta = handlers.getMetaNode(h);

        // Gets the depth of the Meta node in the OID tree
        final int depth = handlers.getOidDepth(h);

        for (Enumeration<SnmpMibSubRequest> rqs=handlers.getSubRequests(h);
             rqs.hasMoreElements();) {

            // Invoke the check() operation
            meta.check(rqs.nextElement(),depth);
        }
    }

    // Optimization: we're going to pass the whole SnmpRequestTree
    // to the "set" method, so that we don't have to rebuild it there.
    //
    if (req instanceof SnmpMibRequestImpl) {
        ((SnmpMibRequestImpl)req).setRequestTree(handlers);
    }

}
 
Example 45
Project: jdk8u-jdk   File: JvmThreadingMeta.java   Source Code and License 4 votes vote down vote up
public void get(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.get(this,req,depth);
}
 
Example 46
Project: jdk8u-jdk   File: SnmpGenericObjectServer.java   Source Code and License 4 votes vote down vote up
/**
 * Checks whether an SNMP SET request can be successfully performed.
 *
 * <p>
 * For each variable in the subrequest, this method calls
 * checkSetAccess() on the meta object, and then tries to invoke the
 * check<i>AttributeName</i>() method on the MBean. If this method
 * is not defined then it is assumed that the SET won't fail.
 * </p>
 *
 * <p><b><i>
 * This method is called internally by <code>mibgen</code> generated
 * objects and you should never need to call it directly.
 * </i></b></p>
 *
 * @param meta  The metadata object impacted by the subrequest
 * @param name  The ObjectName of the MBean impacted by this subrequest
 * @param req   The SNMP subrequest to execute on the MBean
 * @param depth The depth of the SNMP object in the OID tree.
 *
 * @exception SnmpStatusException if the requested SET operation must
 *      be rejected. Raising an exception will abort the request. <br>
 *      Exceptions should never be raised directly, but only by means of
 * <code>
 * req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
 * </code>
 *
 **/
public void check(SnmpGenericMetaServer meta, ObjectName name,
                  SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {

    final Object data = req.getUserData();

    for (Enumeration<SnmpVarBind> e=req.getElements(); e.hasMoreElements();) {
        final SnmpVarBind var= e.nextElement();
        try {
            final long id = var.oid.getOidArc(depth);
            // call meta.check() here, and meta.check will call check()
            check(meta,name,var.value,id,data);
        } catch(SnmpStatusException x) {
            req.registerCheckException(var,x);
        }
    }
}
 
Example 47
Project: OpenJSharp   File: JvmRuntimeImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmRTName" variable.
 */
public String getJvmRTName() throws SnmpStatusException {
    return validDisplayStringTC(getRuntimeMXBean().getName());
}
 
Example 48
Project: jdk8u-jdk   File: JvmMemMgrPoolRelEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmMemMgrRelPoolName" variable.
 */
public String getJvmMemMgrRelPoolName() throws SnmpStatusException {
    return JVM_MANAGEMENT_MIB_IMPL.validJavaObjectNameTC(mpmName);
}
 
Example 49
Project: jdk8u-jdk   File: JvmOSMeta.java   Source Code and License 4 votes vote down vote up
public void get(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.get(this,req,depth);
}
 
Example 50
Project: jdk8u-jdk   File: JvmMemMgrPoolRelTableMeta.java   Source Code and License 4 votes vote down vote up
/**
 * Returns true if "var" identifies a readable scalar object.
 */
public boolean isReadableEntryId( SnmpOid rowOid, long var, Object data )
    throws SnmpStatusException {
    return node.isReadable(var);
}
 
Example 51
Project: OpenJSharp   File: JvmRTInputArgsEntryMeta.java   Source Code and License 4 votes vote down vote up
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.set(this,req,depth);
}
 
Example 52
Project: jdk8u-jdk   File: JvmThreadInstanceEntryImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmThreadInstLockName" variable.
 */
public String getJvmThreadInstLockName() throws SnmpStatusException {
    return validJavaObjectNameTC(info.getLockName());
}
 
Example 53
Project: jdk8u-jdk   File: JvmMemPoolEntryMeta.java   Source Code and License 4 votes vote down vote up
public void check(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    objectserver.check(this,req,depth);
}
 
Example 54
Project: jdk8u-jdk   File: JvmRuntimeImpl.java   Source Code and License 4 votes vote down vote up
/**
 * Getter for the "JvmRTSpecName" variable.
 */
public String getJvmRTSpecName() throws SnmpStatusException {
    return validDisplayStringTC(getRuntimeMXBean().getSpecName());
}
 
Example 55
Project: OpenJSharp   File: SnmpMibTable.java   Source Code and License 3 votes vote down vote up
/**
 * Remove the specified entry from the table.
 * Also triggers the removeEntryCB() callback of the
 * {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface
 * if this node is bound to a factory.
 *
 * <p>
 * @param rowOid The <CODE>SnmpOid</CODE> identifying the table
 *               row to remove.
 *
 * @param entry The entry to be removed. This parameter is not used
 *              internally, it is simply passed along to the
 *              removeEntryCB() callback.
 *
 * @exception SnmpStatusException if the specified entry couldn't
 *            be removed (if the given <code>rowOid</code> is not
 *            valid for instance).
 */
public synchronized void removeEntry(SnmpOid rowOid, Object entry)
    throws SnmpStatusException {
    int pos = findObject(rowOid);
    if (pos == -1)
        return;
    removeEntry(pos,entry);
}
 
Example 56
Project: OpenJSharp   File: SnmpSecuritySubSystem.java   Source Code and License 3 votes vote down vote up
/**
 * Called when a request is to be sent to the network. It must be securized. This call is routed to the dedicated model according to the model ID.
 * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
 * @param cache The cache that has been created by calling <CODE>createSecurityCache</CODE> on this model.
 * @param version The SNMP protocol version.
 * @param msgID The current request id.
 * @param msgMaxSize The message max size.
 * @param msgFlags The message flags (reportable, Auth and Priv).
 * @param msgSecurityModel This current security model.
 * @param params The security parameters that contain the model dependant parameters.
 * @param contextEngineID The context engine ID.
 * @param contextName The context name.
 * @param data The marshalled varbind list
 * @param dataLength The marshalled varbind list length.
 * @param outputBytes The buffer to fill with securized request. This is a representation independant marshalled format. This buffer will be sent to the network.
 * @return The marshalled byte number.
 */
public int generateRequestMsg(SnmpSecurityCache cache,
                              int version,
                              int msgID,
                              int msgMaxSize,
                              byte msgFlags,
                              int msgSecurityModel,
                              SnmpSecurityParameters params,
                              byte[] contextEngineID,
                              byte[] contextName,
                              byte[] data,
                              int dataLength,
                              byte[] outputBytes)
    throws SnmpTooBigException, SnmpStatusException, SnmpSecurityException, SnmpUnknownSecModelException;
 
Example 57
Project: jdk8u-jdk   File: SnmpAdaptorServer.java   Source Code and License 3 votes vote down vote up
/**
 * Send the specified trap PDU to the passed <CODE>InetAddress</CODE>.
 * @param address The destination address.
 * @param pdu The pdu to send.
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpPduTrap(InetAddress address, SnmpPduPacket pdu)
        throws IOException, SnmpStatusException {

    if(address != null)
        sendTrapPdu(address, pdu);
    else
        sendTrapPdu(pdu);
}
 
Example 58
Project: OpenJSharp   File: SnmpMibEntry.java   Source Code and License 3 votes vote down vote up
/**
 * Checks whether the given OID arc identifies a variable (columnar
 * object).
 *
 * @param userData A contextual object containing user-data.
 *        This object is allocated through the <code>
 *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
 *        for each incoming SNMP request.
 *
 * @exception If the given `arc' does not identify any variable in this
 *    group, throws an SnmpStatusException.
 */
public void validateVarId(long arc, Object userData)
    throws SnmpStatusException {
    if (isVariable(arc) == false) {
        throw new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName);
    }
}
 
Example 59
Project: OpenJSharp   File: SnmpSecuritySubSystem.java   Source Code and License 3 votes vote down vote up
/**
 * Called when a response is to be sent to the network. It must be securized. This call is routed to the dedicated model according to the model ID.
 * <BR>The specified parameters are defined in RFC 2572 (see also the {@link com.sun.jmx.snmp.SnmpV3Message} class).
 * @param cache The cache that has been created by calling <CODE>createSecurityCache</CODE> on this model.
 * @param version The SNMP protocol version.
 * @param msgID The current request id.
 * @param msgMaxSize The message max size.
 * @param msgFlags The message flags (reportable, Auth and Priv).
 * @param msgSecurityModel This current security model.
 * @param params The security parameters that contain the model dependant parameters.
 * @param contextEngineID The context engine ID.
 * @param contextName The context name.
 * @param data The marshalled varbind list
 * @param dataLength The marshalled varbind list length.
 * @param outputBytes The buffer to fill with securized request. This is a representation independant marshalled format. This buffer will be sent to the network.
 * @return The marshalled byte number.
 */
public int generateResponseMsg(SnmpSecurityCache cache,
                               int version,
                               int msgID,
                               int msgMaxSize,
                               byte msgFlags,
                               int msgSecurityModel,
                               SnmpSecurityParameters params,
                               byte[] contextEngineID,
                               byte[] contextName,
                               byte[] data,
                               int dataLength,
                               byte[] outputBytes)
    throws SnmpTooBigException, SnmpStatusException,
           SnmpSecurityException, SnmpUnknownSecModelException;
 
Example 60
Project: jdk8u-jdk   File: SnmpMibOid.java   Source Code and License 3 votes vote down vote up
/**
 * Generic handling of the <CODE>set</CODE> operation.
 *
 * <p> This method should be overridden in subclasses.
 * <p>
 *
 * @param req   The sub-request that must be handled by this node.
 *
 * @param depth The depth reached in the OID tree.
 *
 * @exception SnmpStatusException The default implementation (if not
 *            overridden) is to generate a SnmpStatusException.
 */
@Override
public void set(SnmpMibSubRequest req, int depth)
    throws SnmpStatusException {
    for (Enumeration<SnmpVarBind> e= req.getElements(); e.hasMoreElements();) {
        SnmpVarBind var= e.nextElement();
        SnmpStatusException x =
            new SnmpStatusException(SnmpStatusException.noAccess);
        req.registerSetException(var,x);
    }
}