本文整理了Java中org.snmp4j.PDU.get()
方法的一些代码示例,展示了PDU.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PDU.get()
方法的具体详情如下:
包路径:org.snmp4j.PDU
类名称:PDU
方法名:get
[英]Gets the variable binding at the specified position.
[中]获取指定位置的变量绑定。
代码示例来源:origin: OpenNMS/opennms
protected VariableBinding getVarBindAt(int index) {
return getPdu().get(index);
}
代码示例来源:origin: OpenNMS/opennms
private static SnmpValue[] convertResponseToValues(ResponseEvent responseEvent) {
SnmpValue[] retvalues = new Snmp4JValue[responseEvent.getResponse().getVariableBindings().size()];
for (int i = 0; i < retvalues.length; i++) {
retvalues[i] = new Snmp4JValue(responseEvent.getResponse().get(i).getVariable());
}
return retvalues;
}
代码示例来源:origin: OpenNMS/opennms
/**
* TODO: Merge this logic with {@link Snmp4JWalker.Snmp4JResponseListener} #processResponse(PDU response)
*/
private static SnmpValue[] processResponse(Snmp4JAgentConfig agentConfig, ResponseEvent responseEvent) throws IOException {
SnmpValue[] retvalues = { null };
if (responseEvent.getResponse() == null) {
LOG.warn("processResponse: Timeout. Agent: {}, requestID={}", agentConfig, responseEvent.getRequest().getRequestID());
} else if (responseEvent.getError() != null) {
LOG.warn("processResponse: Error during get operation. Error: {}, requestID={}", responseEvent.getError().getLocalizedMessage(), responseEvent.getError(), responseEvent.getRequest().getRequestID());
} else if (responseEvent.getResponse().getType() == PDU.REPORT) {
LOG.warn("processResponse: Error during get operation. Report returned with varbinds: {}, requestID={}", responseEvent.getResponse().getVariableBindings(), responseEvent.getRequest().getRequestID());
} else if (responseEvent.getResponse().getVariableBindings().size() < 1) {
LOG.warn("processResponse: Received PDU with 0 varbinds. Agent: {}, requestID={}", agentConfig, responseEvent.getRequest().getRequestID());
} else if (responseEvent.getResponse().get(0).getSyntax() == SMIConstants.SYNTAX_NULL) {
LOG.info("processResponse: Null value returned in varbind: {}. Agent: {}, requestID={}", responseEvent.getResponse().get(0), agentConfig, responseEvent.getRequest().getRequestID());
} else {
retvalues = convertResponseToValues(responseEvent);
LOG.debug("processResponse: SNMP operation successful, value: {}", (Object)retvalues);
}
return retvalues;
}
代码示例来源:origin: org.kaazing/snmp4j-agent
protected synchronized void setupSubRequests() {
int capacity = requestEvent.getPDU().size();
int totalRepetitions = (requestEvent.getPDU() instanceof PDUv1) ? 0 :
repeaterRowSize*requestEvent.getPDU().getMaxRepetitions();
subrequests = new ArrayList(capacity + totalRepetitions);
if (response == null) {
response = createResponse();
}
for (int i=0; i<requestEvent.getPDU().size(); i++) {
SnmpSubRequest subReq =
new SnmpSubRequest(requestEvent.getPDU().get(i), i);
addSubRequest(subReq);
}
if (logger.isDebugEnabled()) {
logger.debug("SnmpSubRequests initialized: "+subrequests);
}
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
private SnmpValue[] convertResponseToValues(ResponseEvent responseEvent) {
SnmpValue[] retvalues = new Snmp4JValue[responseEvent.getResponse().getVariableBindings().size()];
for (int i = 0; i < retvalues.length; i++) {
retvalues[i] = new Snmp4JValue(responseEvent.getResponse().get(i).getVariable());
}
return retvalues;
}
代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j
protected VariableBinding getVarBindAt(int index) {
return getPdu().get(index);
}
代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j
private static SnmpValue[] convertResponseToValues(ResponseEvent responseEvent) {
SnmpValue[] retvalues = new Snmp4JValue[responseEvent.getResponse().getVariableBindings().size()];
for (int i = 0; i < retvalues.length; i++) {
retvalues[i] = new Snmp4JValue(responseEvent.getResponse().get(i).getVariable());
}
return retvalues;
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
protected VariableBinding getVarBindAt(int index) {
return getPdu().get(index);
}
代码示例来源:origin: org.kaazing/snmp4j
protected static void printVariableBindings(PDU response) {
for (int i=0; i<response.size(); i++) {
VariableBinding vb = response.get(i);
System.out.println(vb.toString());
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j
protected static void printVariableBindings(PDU response) {
for (int i=0; i<response.size(); i++) {
VariableBinding vb = response.get(i);
System.out.println(vb.toString());
}
}
代码示例来源:origin: org.snmp4j/snmp4j
protected static void printVariableBindings(PDU response) {
for (int i = 0; i < response.size(); i++) {
VariableBinding vb = response.get(i);
out.println(vb.toString());
}
}
代码示例来源:origin: fbacchella/jrds
public void join(PDU data) {
for(int i = 0; i < data.size(); i++) {
VariableBinding vb = data.get(i);
addVariable(vb);
}
}
代码示例来源:origin: org.openscada.atlantis/org.openscada.da.server.snmp
private void read () throws Exception
{
final ResponseEvent response = this.node.getConnection ().sendGET ( this.oid );
if ( response == null )
{
throw new Exception ( "No response" );
}
final PDU reply = response.getResponse ();
if ( reply == null )
{
throw new Exception ( "No reply" );
}
readComplete ( reply.get ( 0 ) );
}
代码示例来源:origin: griddynamics/jagger
public int getAsInt(OID oid) throws IOException {
ResponseEvent event = get(Arrays.asList(oid));
return event.getResponse().get(0).getVariable().toInt();
}
代码示例来源:origin: griddynamics/jagger
public long getAsLong(OID oid) throws IOException {
ResponseEvent event = get(Arrays.asList(oid));
return event.getResponse().get(0).getVariable().toLong();
}
代码示例来源:origin: griddynamics/jagger
public String getAsString(OID oid) throws IOException {
ResponseEvent event = get(Arrays.asList(oid));
return event.getResponse().get(0).getVariable().toString();
}
代码示例来源:origin: jrask/snmp-blog
public static String extractSingleString(ResponseEvent event) {
return event.getResponse().get(0).getVariable().toString();
}
}
代码示例来源:origin: jrask/snmp-blog
public String getAsString(OID oid) throws IOException {
ResponseEvent event = get(new OID[]{oid});
return event.getResponse().get(0).getVariable().toString();
}
代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit
private VariableBinding getSingleVariable(OID oid) throws IOException {
PDU pdu = this.pduFactory.createPDU(getTarget());
pdu.setType(PDU.GETNEXT);
pdu.add(new VariableBinding(oid));
ResponseEvent responseEvent = snmp.send(pdu, getTarget());
PDU responsePDU = null;
if (responseEvent != null) responsePDU = responseEvent.getResponse();
VariableBinding vb = null;
if (responsePDU != null) vb = responsePDU.get(0);
return vb;
}
代码示例来源:origin: OpenNMS/opennms
public void testGetSysName() throws IOException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
//Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
Target target = new CommunityTarget(addr, new OctetString("public"));
target.setVersion(SnmpConstants.version1);
target.setTimeout(3000);
target.setRetries(3);
PDUv1 getRequest = new PDUv1();
getRequest.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
ResponseEvent e = snmp.get(getRequest, target);
PDU response = e.getResponse();
assertEquals(new OctetString("mockhost"), response.get(0).getVariable());
}
内容来源于网络,如有侵权,请联系作者删除!