/** * 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); }
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; }
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; }
/** * 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"); } }
/** * 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); } }
/** * 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; }
/** * 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); }
/** * 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); } }
/** * 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); }
/** * 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(); }
/** * 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); }
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; }
/** * 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; }
/** * 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); }
/** * Getter for the "JvmMemPoolThreshdSupport" variable. */ public EnumJvmMemPoolCollectThreshdSupport getJvmMemPoolCollectThreshdSupport() throws SnmpStatusException { if (pool.isCollectionUsageThresholdSupported()) return EnumJvmMemPoolCollectThreshdSupported; else return EnumJvmMemPoolCollectThreshdUnsupported; }
/** * 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); }
static void setRowStatusFail(SnmpMibSubRequest req, int errorStatus) throws SnmpStatusException { final SnmpVarBind statusvb = req.getRowStatusVarBind(); final SnmpStatusException x = new SnmpStatusException(errorStatus); req.registerSetException(statusvb,x); }
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; } }
/** * 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); }
/** * 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) ; }
public void set(SnmpMibSubRequest req, int depth) throws SnmpStatusException { objectserver.set(this,req,depth); }
/** * Getter for the "JvmJITCompilerName" variable. */ public String getJvmJITCompilerName() throws SnmpStatusException { return JVM_MANAGEMENT_MIB_IMPL. validJavaObjectNameTC(getCompilationMXBean().getName()); }
/** * Getter for the "JvmRTInputArgsIndex" variable. */ public Integer getJvmRTInputArgsIndex() throws SnmpStatusException { return new Integer(index); }
/** * Getter for the "JvmRTProcessorCount" variable. */ public Integer getJvmOSProcessorCount() throws SnmpStatusException { return new Integer(getOSMBean().getAvailableProcessors()); }
/** * 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()); } }
/** * Getter for the "JvmRTName" variable. */ public String getJvmRTName() throws SnmpStatusException { return validDisplayStringTC(getRuntimeMXBean().getName()); }
/** * 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; }
/** * 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; }
/** * Getter for the "JvmMemPoolType" variable. */ public EnumJvmMemPoolType getJvmMemPoolType() throws SnmpStatusException { return jvmMemPoolType(pool.getType()); }
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 }
/** * Checker for the "JvmThreadPeakCountReset" variable. */ public void checkJvmThreadPeakCountReset(Long x) throws SnmpStatusException { }
/** * Returns true if "var" identifies a readable scalar object. */ public boolean isReadableEntryId( SnmpOid rowOid, long var, Object data ) throws SnmpStatusException { return node.isReadable(var); }
/** * Getter for the "JvmThreadInstId" variable. */ public Long getJvmThreadInstId() throws SnmpStatusException { return new Long(info.getThreadId()); }
/** * 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); }
/** * 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); } } }