Package org.snmp4j.event

Examples of org.snmp4j.event.ResponseEvent


  @Test
  public void testMultiUserV3() throws IOException {

    /* Test a valid security name */
    ResponseEvent response = this.v3Client.getSync(this.address,
        SnmpConstants.sysDescr);
    Assert.assertNotNull(response);
    Assert.assertTrue(ResponseEvents.extractBindings(response).containsKey(
        SnmpConstants.sysDescr));

View Full Code Here


    for (final SNMP<UdpAddress> client : this.allClients) {

      final VariableBinding binding = new VariableBinding(
          SnmpConstants.sysLocation, new OctetString("SECRET SITE #"
              + Integer.toString(new Random().nextInt(100))));
      final ResponseEvent response = client
          .setSync(this.address, binding);
      Assert.assertNotNull(response);
      Assert.assertTrue(ResponseEvents.extractBindings(response)
          .containsKey(SnmpConstants.sysLocation));
    }
View Full Code Here

    if (address == null || !PortScan.isOpen(address, Settings.getInt("snmp.port", 161))) {
      return null;
    }
    String ipAddress = address.toString();
    HashMap<String, String> oid = new HashMap<String, String>();
    ResponseEvent response = null;
    TransportMapping transport = null;
    String oidValue = "0";
    //int count = 0;
    Properties p = new Properties();
    final File f = new File(IO.userDir, "MIB");
    String descr;
    // read from File MIB the oids to request over SNMP
    Logger.debug("Loading MIB");
    FileInputStream fis = null;
    try {
      fis = new FileInputStream(f);
      p.load(fis);
    } catch (IOException e) {
      Logger.error("Failed to open MIB.", e);
    } finally {
      try {
        fis.close();
      } catch (Exception e) {
      }
    }// end reading

    try {
      transport = new DefaultUdpTransportMapping();
      transport.listen();
    } catch (IOException e) {
    }
    // Create Target Address object
    CommunityTarget comtarget = new CommunityTarget();
    comtarget.setCommunity(new OctetString(Settings.get("snmp.community", "public")));
    comtarget.setVersion(SnmpConstants.version1);
    comtarget.setAddress(new UdpAddress(ipAddress + "/" + Settings.getInt("snmp.port", 161)));
    comtarget.setRetries(2);
    comtarget.setTimeout(1000);
    // Create the PDU object
    // Create Snmp object
    Snmp snmp = new Snmp(transport);
    // Iterating over map
    for (Entry<Object, Object> entry : p.entrySet()) {
      oidValue = entry.getValue().toString();
      descr = entry.getKey().toString();
      PDU pdu = new PDU();
      pdu.add(new VariableBinding(new OID(oidValue)));
      pdu.setRequestID(new Integer32(1));
      pdu.setType(PDU.GET);

      try {
        response = snmp.get(pdu, comtarget);
      } catch (IOException e) {
      }
      // Process Agent Response
      if (response != null) {
        PDU responsePDU = response.getResponse();
        if (responsePDU != null) {
          int errorStatus = responsePDU.getErrorStatus();
          int errorIndex = responsePDU.getErrorIndex();
          String errorStatusText = responsePDU.getErrorStatusText();
View Full Code Here

TOP

Related Classes of org.snmp4j.event.ResponseEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.