本文整理汇总了Java中org.snmp4j.PDU.getErrorStatus方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.getErrorStatus方法的具体用法?Java PDU.getErrorStatus怎么用?Java PDU.getErrorStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.snmp4j.PDU
的用法示例。
在下文中一共展示了PDU.getErrorStatus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(new UdpAddress("23.23.52.11/161"));
target.setTimeout(3000); //3s
target.setRetries(1);
PDU pdu = new PDU();
pdu.setType(PDU.GETBULK);
pdu.setMaxRepetitions(1);
pdu.setNonRepeaters(0);
VariableBinding[] array = {new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3")),
new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.7")),
new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.10")),
new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.19"))};
pdu.addAll(array);
//pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3")));
ResponseEvent responseEvent = snmp.send(pdu, target);
PDU response = responseEvent.getResponse();
if (response == null) {
System.out.println("TimeOut...");
} else {
if (response.getErrorStatus() == PDU.noError) {
Vector<? extends VariableBinding> vbs = response.getVariableBindings();
for (VariableBinding vb : vbs) {
System.out.println(vb.getVariable().toString());
}
} else {
System.out.println("Error:" + response.getErrorStatusText());
}
}
}
示例2: checkWalkFinished
import org.snmp4j.PDU; //导入方法依赖的package包/类
private static boolean checkWalkFinished(OID targetOID, PDU pdu, VariableBinding vb) {
boolean finished = false;
if (pdu.getErrorStatus() != 0) {
finished = true;
} else if (vb.getOid() == null) {
finished = true;
} else if (vb.getOid().size() < targetOID.size()) {
finished = true;
} else if (targetOID.leftMostCompare(targetOID.size(), vb.getOid()) != 0) {
finished = true;
} else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
finished = true;
} else if (vb.getOid().compareTo(targetOID) <= 0) {
finished = true;
}
return finished;
}
示例3: 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());
}
}
示例4: checkWalkFinished
import org.snmp4j.PDU; //导入方法依赖的package包/类
private static boolean checkWalkFinished(OID targetOID, PDU pdu,
VariableBinding vb) {
boolean finished = false;
if (pdu.getErrorStatus() != 0) {
System.out.println("[true] responsePDU.getErrorStatus() != 0 ");
System.out.println(pdu.getErrorStatusText());
finished = true;
} else if (vb.getOid() == null) {
System.out.println("[true] vb.getOid() == null");
finished = true;
} else if (vb.getOid().size() < targetOID.size()) {
System.out.println("[true] vb.getOid().size() < targetOID.size()");
finished = true;
} else if (targetOID.leftMostCompare(targetOID.size(), vb.getOid()) != 0) {
System.out.println("[true] targetOID.leftMostCompare() != 0");
finished = true;
} else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
System.out
.println("[true] Null.isExceptionSyntax(vb.getVariable().getSyntax())");
finished = true;
} else if (vb.getOid().compareTo(targetOID) <= 0) {
System.out.println("[true] Variable received is not "
+ "lexicographic successor of requested " + "one:");
System.out.println(vb.toString() + " <= " + targetOID);
finished = true;
}
return finished;
}
示例5: checkWalkFinished
import org.snmp4j.PDU; //导入方法依赖的package包/类
private static boolean checkWalkFinished(OID walkOID, PDU pdu,
VariableBinding vb) {
boolean finished = false;
if (pdu.getErrorStatus() != 0) {
System.out.println("[true] pdu.getErrorStatus() != 0 ");
System.out.println(pdu.getErrorStatusText());
finished = true;
} else if (vb.getOid() == null) {
System.out.println("[true] vb.getOid() == null");
finished = true;
} else if (vb.getOid().size() < walkOID.size()) {
System.out.println("[true] vb.getOid().size() < targetOID.size()");
finished = true;
} else if (walkOID.leftMostCompare(walkOID.size(), vb.getOid()) != 0) {
System.out.println("[true] targetOID.leftMostCompare() != 0");
finished = true;
} else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
System.out
.println("[true] Null.isExceptionSyntax(vb.getVariable().getSyntax())");
finished = true;
} else if (vb.getOid().compareTo(walkOID) <= 0) {
System.out.println("[true] vb.getOid().compareTo(walkOID) <= 0 ");
finished = true;
}
return finished;
}
示例6: checkWalkFinished
import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* 1)responsePDU == null<br>
* 2)responsePDU.getErrorStatus() != 0<br>
* 3)responsePDU.get(0).getOid() == null<br>
* 4)responsePDU.get(0).getOid().size() < targetOID.size()<br>
* 5)targetOID.leftMostCompare(targetOID.size(),responsePDU.get(0).getOid())
* !=0<br>
* 6)Null.isExceptionSyntax(responsePDU.get(0).getVariable().getSyntax())<br>
* 7)responsePDU.get(0).getOid().compareTo(targetOID) <= 0<br>
*
* @param targetOID
* @param pdu
* @param vb
* @return
*/
private static boolean checkWalkFinished(OID targetOID, PDU pdu,
VariableBinding vb) {
boolean finished = false;
if (pdu.getErrorStatus() != 0) {
System.out.println("[true] responsePDU.getErrorStatus() != 0 ");
System.out.println(pdu.getErrorStatusText());
finished = true;
} else if (vb.getOid() == null) {
System.out.println("[true] vb.getOid() == null");
finished = true;
} else if (vb.getOid().size() < targetOID.size()) {
System.out.println("[true] vb.getOid().size() < targetOID.size()");
finished = true;
} else if (targetOID.leftMostCompare(targetOID.size(), vb.getOid()) != 0) {
System.out.println("[true] targetOID.leftMostCompare() != 0");
finished = true;
} else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
System.out
.println("[true] Null.isExceptionSyntax(vb.getVariable().getSyntax())");
finished = true;
} else if (vb.getOid().compareTo(targetOID) <= 0) {
System.out.println("[true] Variable received is not "
+ "lexicographic successor of requested " + "one:");
System.out.println(vb.toString() + " <= " + targetOID);
finished = true;
}
return finished;
}
示例7: 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;
}
示例8: walk
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static List<VariableBinding> walk(Target target, OID oid) {
List<VariableBinding> ret = new ArrayList<VariableBinding>();
PDU requestPDU = new PDU();
requestPDU.add(new VariableBinding(oid));
requestPDU.setType(PDU.GETNEXT);
boolean finished = false;
try{
while (!finished) {
VariableBinding vb = null;
ResponseEvent respEvt = snmp.send(requestPDU, target);
PDU responsePDU = respEvt.getResponse();
if (responsePDU != null) {
vb = responsePDU.get(0);
}
if (responsePDU == null) {
finished = true;
} else if (responsePDU.getErrorStatus() != 0) {
finished = true;
} else if (vb.getOid() == null) {
finished = true;
} else if (vb.getOid().size() < oid.size()) {
finished = true;
} else if (oid.leftMostCompare(oid.size(), vb.getOid()) != 0) {
finished = true;
} else if (Null.isExceptionSyntax(vb.getVariable().getSyntax())) {
finished = true;
} else if (vb.getOid().compareTo(oid) <= 0) {
finished = true;
} else {
ret.add(vb);
// Set up the variable binding for the next entry.
requestPDU.setRequestID(new Integer32(0));
requestPDU.set(0, vb);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return ret;
}
示例9: process
import org.snmp4j.PDU; //导入方法依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
Status status = null;
counterGroup = new CounterGroup();
try {
// This try clause includes whatever Channel operations you want to do
Event event = new SimpleEvent();
Map <String, String> headers = new HashMap<String, String>();
StringBuilder stringBuilder = new StringBuilder();
ResponseEvent responseEvent = snmp.send(pdu, target);
PDU response = responseEvent.getResponse();
DateFormat dateFormat = new SimpleDateFormat("MM dd HH:mm:ss yyyy");
Date date = new Date();
stringBuilder.append(date + ",");
stringBuilder.append(bindAddress + ",");
if (response == null) {
logger.info("TimeOut...");
} else {
if (response.getErrorStatus() == PDU.noError) {
Vector<? extends VariableBinding> vbs = response.getVariableBindings();
for (VariableBinding vb : vbs) {
//System.out.println(vb.getVariable().toString());
stringBuilder.append(vb.getVariable().toString() + ",");
}
} else {
logger.info("Error:" + response.getErrorStatusText());
}
}
String messageString = stringBuilder.toString();
// trick: remove the last comma
messageString = messageString.replaceAll(",$", "");
byte[] message = messageString.getBytes();
headers.put("timestamp", String.valueOf(System.currentTimeMillis()));
logger.info("Message: {}", messageString);
event.setBody(message);
event.setHeaders(headers);
// Store the Event into this Source's associated Channel(s)
getChannelProcessor().processEvent(event);
counterGroup.incrementAndGet("events.success");
Thread.sleep(delayQuery*1000);
status = Status.READY;
} catch (ChannelException|IOException|InterruptedException ex) {
counterGroup.incrementAndGet("events.dropped");
logger.error("Error writting to channel", ex);
// Log exception, handle individual exceptions as needed
status = Status.BACKOFF;
// re-throw all Errors
//if (t instanceof Error) {
// throw (Error);
//}
}
return status;
}
示例10: 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();
}