当前位置: 首页>>代码示例>>Java>>正文


Java Variable.toString方法代码示例

本文整理汇总了Java中org.snmp4j.smi.Variable.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Variable.toString方法的具体用法?Java Variable.toString怎么用?Java Variable.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.snmp4j.smi.Variable的用法示例。


在下文中一共展示了Variable.toString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStringVar

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
public String getStringVar(Variable var){
	String retVal = null;
	if(!(var instanceof Null)){
		retVal = var.toString();
	}
	return retVal;
}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:8,代码来源:SNMPSensor.java

示例2: getChannelInfo

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
protected Channel getChannelInfo(OIDHolder oidh, Map<OID, Variable> vars){
		Channel retVal = null;
		Variable var = vars.get(oidh.oid);
		String name = oidh.getName();
		long value = -1;
		if(var instanceof Null){
			String tmp = var.toString();
			retVal = new LongChannel(name, Unit.BANDWIDTH, -1);
			String logString = "OID["+oidh.oidString+"] "+name+" returned: "+tmp;
//			System.out.println(logString);
            Logger.log(logString );
//			retVal.
		} else {
			value = var.toLong();
		}
//			public enum SNMPDataResponseType {STRING,INT,LONG,FLOAT,TICKS,OCTIN,OCTOUT,COUNT};
			switch(oidh.dataType){
			case INT:
			case LONG:
			case OCTIN:
			case OCTOUT:
				retVal = new LongChannel(name, Unit.BANDWIDTH, value, Channel.Mode.COUNTER);
				break;
			case TICKS:
				retVal = new LongChannel(name, Unit.TIME_SECONDS, (value < 0 ? value : (long)(value/100)));
				break;
			case COUNT:
				retVal = new LongChannel(name, Unit.COUNT, value);
				break;
//			case STRING:
//				retVal = new LongChannel(name, "BytesBandwidth", var.toLong());
//				break;
//		lchannel  = new LongChannel("Packet Loss", "Percent", stats.loss);
			
		}
		return retVal;
	}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:38,代码来源:SNMPSensorSubInterface.java

示例3: getChannel

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
public Channel getChannel(Variable var){
		Channel retVal = null;
		long value = -1;
		if(var instanceof Null){
			String tmp = var.toString();
			retVal = new LongChannel(getName(), Unit.BANDWIDTH, -1);
			String logString = "OID["+getObject()+"] "+getName()+" returned: "+tmp;
			retVal.setMessage(logString);
			retVal.setWarning(1);
            Logger.log(logString );
		} else {
			SNMPDataType type = getDataType();
			String valueStr = var.toString();
//			var.
			switch(type){
				case FLOAT:
					{
						float valueFloat = Float.parseFloat(valueStr);
						retVal = super.getChannel(valueFloat);
					}
					break;
				case OTHER:
					setDataType(SNMPUtil.getDataType(var));
				case LONG:
				case INT:
				default:
					retVal = super.getChannel(var.toLong());
			}
		}
		if(retVal != null && retVal.getUnit() == Unit.CUSTOM){
			retVal.setCustomunit(getCustomUnit());
		}
		return retVal;
	}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:35,代码来源:SNMPEntry.java

示例4: getStringVar

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
public static String getStringVar(Variable var){
	String retVal = null;
	if(!(var instanceof Null)){
		retVal = var.toString();
	}
	return retVal;
}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:8,代码来源:SNMPUtil.java

示例5: getVariableValue

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
public static String getVariableValue(PDU pdu, OID varoid){
	String retVal = null;
	Variable var = getVariableBinding(pdu, varoid);
	if(var != null){
		retVal = var.toString(); 
	}
	return retVal;
}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:9,代码来源:SNMPUtil.java

示例6: asMeasurement

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
/**
 * Converts an SNMP variable into an RHQ measurement value.
 * This includes mapping integer values into string constants,
 * converting strings to doubles, etc.
 *
 * @param request measurement request
 * @param variable SNMP variable
 * @return data as a trait or numeric (or complex)
 */
private MeasurementData asMeasurement(MeasurementScheduleRequest request, Variable variable) {
    if (variable == null)
        throw new NullPointerException("variable");
    if (request == null)
        throw new NullPointerException("request");
    DataType dataType = request.getDataType();
    String name = request.getName();
    if (variable instanceof Integer32) {
        int i = ((Integer32)variable).toInt();
        Map<Integer, String> mapping = index.getMapping(name);
        if (mapping != null && !mapping.isEmpty()) {
            return new MeasurementDataTrait(request, mapping.get(i));
        }
    }
    if (dataType == DataType.TRAIT) {
        return new MeasurementDataTrait(request, variable.toString());
    }
    if (variable instanceof OctetString && dataType == DataType.MEASUREMENT) {
        // interpret as String
        return new MeasurementDataNumeric(request, new Double(variable.toString()));
    }
    if (variable instanceof TimeTicks) {
        long ms = ((TimeTicks)variable).toMilliseconds();
        return new MeasurementDataNumeric(request, (double)ms);
    }
    return new MeasurementDataNumeric(request, (double)variable.toLong());
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:37,代码来源:MibComponent.java

示例7: format

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
/**
 * Returns a textual representation of the supplied variable against the
 * optionally supplied instance OID.
 *
 * @param instanceOID the instance OID <code>variable</code> is associated
 *   with. If <code>null</code> the formatting cannot take any MIB
 *   specification of the variable into account and has to format it based
 *   on its type only.
 * @param variable
 *    the variable to format.
 * @param withOID
 *    if <code>true</code> the <code>instanceOID</code> should be included
 *    in the textual representation to form a {@link VariableBinding}
 *    representation.
 * @return the textual representation.
 */
public String format(OID instanceOID, Variable variable, boolean withOID) {
  String valueString;
  String typeString = variable.getSyntaxString();

  switch (variable.getSyntax()) {
    case SMIConstants.SYNTAX_TIMETICKS :
      valueString = String.valueOf(((TimeTicks) variable).getValue());
      break;
    case SMIConstants.SYNTAX_OCTET_STRING :
      if (!is_PrintableOneLine(((OctetString)variable))) {
        typeString = TYPE_NAME_4_OCTETSTRING_IN_HEX;
        valueString = ((OctetString)variable).toHexString();
      }
      else {
        valueString = variable.toString();
      }
      break;
    case BER.BITSTRING:
      valueString = ((BitString)variable).toHexString();
      break;
    default :
      valueString = variable.toString();
      break;
  }

  if (withOID) {
    return oidFormat.format(instanceOID.getValue())
             + SEPARATOR + typeString + SEPARATOR + valueString;
  }
  else {
    return valueString;
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:50,代码来源:ColonSeparatedOidTypeValueVariableTextFormat.java

示例8: dispatchPdu

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
private void dispatchPdu(Address address, PDU pdu) {
	if (pdu != null & address != null) {
		logger.debug("Received PDU from '{}' '{}'", address, pdu);
		for (SnmpBindingProvider provider : providers) {
			for (String itemName : provider.getItemNames()) {
				// Check the IP address
				if (!provider.getAddress(itemName).equals(address)) {
					continue;
				}

				// Check the OID
				OID oid = provider.getOID(itemName);
				Variable variable = pdu.getVariable(oid);
				if (variable != null) {
					Class<? extends Item> itemType = provider.getItemType(itemName);

					// Do any transformations
					String value = variable.toString();
					try {
						value = provider.doTransformation(itemName, value);
					} catch (TransformationException e) {
						logger.error("Transformation error with item {}: {}", itemName, e);
					}

					// Change to a state
					State state = null;
					if (itemType.isAssignableFrom(StringItem.class)) {
						state = StringType.valueOf(value);
					} else if (itemType.isAssignableFrom(NumberItem.class)) {
						state = DecimalType.valueOf(value);
					} else if (itemType.isAssignableFrom(SwitchItem.class)) {
						state = OnOffType.valueOf(value);
					}

					if (state != null) {
						eventPublisher.postUpdate(itemName, state);
					} else {
						logger.debug(
								"'{}' couldn't be parsed to a State. Valid State-Types are String and Number",
								variable.toString());
					}
				} else {
					logger.trace("PDU doesn't contain a variable with OID ‘{}‘", oid.toString());
				}
			}
		}
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:49,代码来源:SnmpBinding.java

示例9: dispatchPdu

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
private void dispatchPdu(Address address, PDU pdu) {
    if (pdu != null & address != null) {
        logger.debug("Received PDU from '{}' '{}'", address, pdu);
        for (SnmpBindingProvider provider : providers) {
            for (String itemName : provider.getItemNames()) {
                // Check the IP address
                if (!provider.getAddress(itemName).equals(address)) {
                    continue;
                }

                // Check the OID
                OID oid = provider.getOID(itemName);
                Variable variable = pdu.getVariable(oid);
                if (variable != null) {
                    Class<? extends Item> itemType = provider.getItemType(itemName);

                    // Do any transformations
                    String value = variable.toString();
                    try {
                        value = provider.doTransformation(itemName, value);
                    } catch (TransformationException e) {
                        logger.error("Transformation error with item {}: {}", itemName, e);
                    }

                    // Change to a state
                    State state = null;
                    if (itemType.isAssignableFrom(StringItem.class)) {
                        state = StringType.valueOf(value);
                    } else if (itemType.isAssignableFrom(NumberItem.class)) {
                        state = DecimalType.valueOf(value);
                    } else if (itemType.isAssignableFrom(SwitchItem.class)) {
                        state = OnOffType.valueOf(value);
                    }

                    if (state != null) {
                        eventPublisher.postUpdate(itemName, state);
                    } else {
                        logger.debug("'{}' couldn't be parsed to a State. Valid State-Types are String and Number",
                                variable.toString());
                    }
                } else {
                    logger.trace("PDU doesn't contain a variable with OID '{}'", oid.toString());
                }
            }
        }
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:48,代码来源:SnmpBinding.java

示例10: castToString

import org.snmp4j.smi.Variable; //导入方法依赖的package包/类
public static String castToString(Variable variable) {
	return variable.toString();
}
 
开发者ID:ccascone,项目名称:JNetMan,代码行数:4,代码来源:SnmpHelper.java


注:本文中的org.snmp4j.smi.Variable.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。