本文整理汇总了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());
}
示例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());
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}