本文整理汇总了Java中org.snmp4j.PDU.getErrorIndex方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.getErrorIndex方法的具体用法?Java PDU.getErrorIndex怎么用?Java PDU.getErrorIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.snmp4j.PDU
的用法示例。
在下文中一共展示了PDU.getErrorIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateResponse
import org.snmp4j.PDU; //导入方法依赖的package包/类
protected void validateResponse(ResponseEvent event) {
final Exception error = event.getError();
if (error != null) {
throw new RuntimeException(error);
}
PDU response = event.getResponse();
if (response == null) {
throw new TimeoutException();
}
if (response.getErrorStatus() != 0) {
throw new RuntimeException("response indicates "
+ response.getErrorStatusText()
+ " at index " + response.getErrorIndex());
}
}
示例2: getResponse
import org.snmp4j.PDU; //导入方法依赖的package包/类
private OperationResult getResponse(ResponseEvent event) {
PDU response = event.getResponse();
log.info("set result " + response);
int errorIndex = response.getErrorIndex();
int errorStatus = response.getErrorStatus();
String errorStatusText = response.getErrorStatusText();
OperationResult result = new OperationResult();
Configuration config = result.getComplexResults();
config.setSimpleValue(ERROR_INDEX, valueOf(errorIndex));
config.setSimpleValue(ERROR_STATUS, valueOf(errorStatus));
config.setSimpleValue(ERROR_STATUS_TEXT, valueOf(errorStatusText));
if (errorStatus != SnmpConstants.SNMP_ERROR_SUCCESS)
result.setErrorMessage(response.toString());
return result;
}
示例3: processGet
import org.snmp4j.PDU; //导入方法依赖的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;
}
示例4: processGetNext
import org.snmp4j.PDU; //导入方法依赖的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;
}
示例5: main
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
System.out.println("SNMP GET-NEXT Simple Request");
// Create TransportMapping and Listen
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
// Create Target Address object
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString(community));
comtarget.setVersion(snmpVersion);
comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
comtarget.setRetries(2);
comtarget.setTimeout(1000);
// Create the PDU object
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(oidValue)));
pdu.setRequestID(new Integer32(1));
pdu.setType(PDU.GETNEXT);
// Create Snmp object for sending data to Agent
Snmp snmp = new Snmp(transport);
System.out.println("Sending GetNext Request to Agent ...");
ResponseEvent response = snmp.getNext(pdu, comtarget);
// Process Agent Response
if (response != null)
{
System.out.println("\nResponse:\nGot GetNext Response from Agent...");
PDU responsePDU = response.getResponse();
if (responsePDU != null)
{
int errorStatus = responsePDU.getErrorStatus();
int errorIndex = responsePDU.getErrorIndex();
String errorStatusText = responsePDU.getErrorStatusText();
if (errorStatus == PDU.noError)
{
System.out.println("Snmp GetNext Response for sysObjectID = " + responsePDU.getVariableBindings());
}
else
{
System.out.println("Error: Request Failed");
System.out.println("Error Status = " + errorStatus);
System.out.println("Error Index = " + errorIndex);
System.out.println("Error Status Text = " + errorStatusText);
}
}
else
{
System.out.println("Error: GetNextResponse PDU is null");
}
}
else
{
System.out.println("Error: Agent Timeout... ");
}
snmp.close();
}