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


Java VariableBinding.setVariable方法代码示例

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


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

示例1: testTimeTickVariable

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
@Test
public void testTimeTickVariable() throws InterruptedException {
	String expectedOid = "1.3.6.1.2.1.1.3.0";
	Number expectedValue = 2929358;
	String expectedSource = "www.myweb.com";
	String expectedMetricId = "MY_FAVORITE_METRIC";
	
	VariableBinding vb = new VariableBinding();
	TimeTicks v = new TimeTicks();
	v.setValue(expectedValue.longValue());
	
	vb.setOid(new OID(expectedOid));
	vb.setVariable(v);

	SnmpPollerConfiguration config = getSnmpPollerConfiguration(
			expectedSource,expectedMetricId,expectedOid);
	out.expectedMessageCount(1);
	in.sendBodyAndHeaders(vb,setScriptHeaders(SNMP_TO_MEASURE_SCRIPT,config));
	out.assertIsSatisfied();
	
	Measurement m = getMeasurement(out);
	assertNotNull("check event for null",m);
	assertEquals("check source",expectedSource,m.getSource());
	assertEquals("check metric",expectedMetricId,m.getMetric());
	assertEquals("check measure",v.getValue(),m.getMeasure().intValue());
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:27,代码来源:SnmpToMeasureTest.java

示例2: testCounter32Variable

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
@Test
public void testCounter32Variable() throws InterruptedException {
	String expectedOid = "1.3.6.1.2.1.4.3.0";
	Number expectedValue = 1588007;
	String expectedSource = "www.myweb.com";
	String expectedMetricId = "MY_FAVORITE_METRIC";
	
	VariableBinding vb = new VariableBinding();
	Counter32 v = new Counter32();
	v.setValue(expectedValue.longValue());
	
	vb.setOid(new OID(expectedOid));
	vb.setVariable(v);

	SnmpPollerConfiguration config = getSnmpPollerConfiguration(
			expectedSource,expectedMetricId,expectedOid);
	out.expectedMessageCount(1);
	in.sendBodyAndHeaders(vb,setScriptHeaders(SNMP_TO_MEASURE_SCRIPT,config));
	out.assertIsSatisfied();
	
	Measurement m = getMeasurement(out);
	assertNotNull("check event for null",m);
	assertEquals("check source",expectedSource,m.getSource());
	assertEquals("check metric",expectedMetricId,m.getMetric());
	assertEquals("check measure",v.getValue(),m.getMeasure().intValue());
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:27,代码来源:SnmpToMeasureTest.java

示例3: createTrapPDU

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
private static PDUv1 createTrapPDU(String trapData) throws UnknownHostException{
	PDUv1 trapPdu = (PDUv1)DefaultPDUFactory.createPDU(SnmpConstants.version1);
	trapPdu.setType(PDU.V1TRAP);    	

	VariableBinding vbm = new VariableBinding();
	vbm.setOid(new OID(SNMP_XAP_ALERT_MSG_OID));
	vbm.setVariable(new OctetString(trapData));
	trapPdu.add(vbm);

	trapPdu.setAgentAddress(getLocalAddress());    	    	
	return trapPdu;
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:13,代码来源:SnmpTrapSender.java

示例4: newVarbind

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Varbind newVarbind(String oid, Object value) {
  VariableBinding varbind = resolveOid(oid);
  int syntax = mib.syntaxForObject(varbind.getOid().toString());
  Variable variable = AbstractVariable.createFromSyntax(syntax);
  if (variable instanceof Integer32) {
    ((Integer32) variable).setValue(((Number) value).intValue());
  }
  else if (variable instanceof UnsignedInteger32) {
    ((UnsignedInteger32) variable).setValue(Math.abs(((Number) value).longValue()));
  }
  else if (variable instanceof Counter64) {
    ((Counter64) variable).setValue(((Number) value).longValue());      
  }
  else if (variable instanceof OctetString) {
    if (value instanceof String) {
      ((OctetString) variable).setValue((String) value);
    }
    else {
      ((OctetString) variable).setValue((byte[]) value);
    }
  }
  else if (variable instanceof OID) {
    if (value instanceof String) {
      ((OID) variable).setValue((String) value);
    }
    else {
      ((OID) variable).setValue((int[]) value);
    }
  }
  else {
    throw new IllegalStateException("unrecognized type");
  }

  varbind.setVariable(variable);
  return varbindFactory.newVarbind(varbind);
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:41,代码来源:Snmp4jContext.java

示例5: getVariable

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
private void getVariable(final SubRequest request, final OID oid) {
    Variable value = findValueForOID(oid);
    VariableBinding vb = request.getVariableBinding();
    vb.setOid(oid);
    vb.setVariable(value == null ? Null.noSuchObject : value);
    request.completed();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:8,代码来源:PropertiesBackedManagedObject.java

示例6: processGet

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
/**
 * @param request
 * @return
 */
@SuppressWarnings("unchecked")
private PDU processGet(PDU request) {
    PDU response = request;
    response.setErrorIndex(0);
    response.setErrorStatus(0);
    response.setType(PDU.RESPONSE);
    
    Vector<VariableBinding> varBinds = response.getVariableBindings();
    for(int i = 0; i < varBinds.size(); i++) {
        VariableBinding varBind = varBinds.get(i);
        VariableBinding nextVarBind = m_agent.get(varBind.getOid());
        if (nextVarBind == null) {
            if (response instanceof PDUv1) {
                if (response.getErrorIndex() == 0) {
                    response.setErrorIndex(i+1);
                    response.setErrorStatus(PDU.noSuchName);
                } 
            } else {
                varBind.setVariable(Null.endOfMibView);
            }
        } else {
            response.set(i, nextVarBind);
        }
    }
    
    return response;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:32,代码来源:MockProxy.java

示例7: processGetNext

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
/**
 * @param request
 * @return
 */
@SuppressWarnings("unchecked")
private PDU processGetNext(PDU request) {
    PDU response = request;
    response.setErrorIndex(0);
    response.setErrorStatus(0);
    response.setType(PDU.RESPONSE);
    
    Vector<VariableBinding> varBinds = response.getVariableBindings();
    for(int i = 0; i < varBinds.size(); i++) {
        VariableBinding varBind = varBinds.get(i);
        VariableBinding nextVarBind = m_agent.getNext(varBind.getOid());
        if (nextVarBind == null) {
            if (response instanceof PDUv1) {
                if (response.getErrorIndex() == 0) {
                    response.setErrorIndex(i+1);
                    response.setErrorStatus(PDU.noSuchName);
                } 
            } else {
                varBind.setVariable(Null.endOfMibView);
            }
        } else {
            response.set(i, nextVarBind);
        }
    }
    
    return response;

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:33,代码来源:MockProxy.java

示例8: resolveVarbind

import org.snmp4j.smi.VariableBinding; //导入方法依赖的package包/类
private VariableBinding resolveVarbind(Varbind varbind) {
  VariableBinding vb = resolveOid(varbind.getOid());
  vb.setVariable(Snmp4jVarbind.newVariable(varbind.getSyntax(), varbind.toObject()));
  return vb;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:6,代码来源:Snmp4jContext.java


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