Package org.snmp4j.smi

Examples of org.snmp4j.smi.OctetString


    return OctetString.fromString(buf.toString(), 2).toByteArray();
  }

  public Object transformToNative(Object transformedValue,
                                  Object oldNativeValue, ObjectName objectName) {
    OctetString os = new OctetString((byte[])transformedValue);
    String s = os.toString(2);
    int pos = s.indexOf("1");
    if (pos < 0) {
      return null;
    }
    pos -= offset;
View Full Code Here


    return OctetString.fromString(buf.toString(), 2).toByteArray();
  }

  public Object transformToNative(Object transformedValue,
                                  Object oldNativeValue, ObjectName objectName) {
    OctetString os = new OctetString((byte[])transformedValue);
    String s = os.toString(2);
    if (s.length() <= offset) {
      return false;
    }
    return (s.charAt(offset) == '1');
  }
View Full Code Here

      /* Assigned Later */
      boolean send_separate_queries = false;
      final HashMap<String,String> oids  = new HashMap<String,String>();
      Target target;
      HashMap<String, ArrayList<oid_data>> oid_hashmap = new HashMap<String, ArrayList<oid_data>>();
      OctetString localEngineID = new OctetString(MPv3.createLocalEngineID());

      if (port == null) {
        port = "161";
      }
      if (version == null) {
        version = "2c";
      }
      if (community == null) {
        community = "public";
      }
      if ((separate_queries != null) && ((separate_queries.equals("on")) || separate_queries.equals("true"))) {
        send_separate_queries = true;
      }

      Address targetAddress = GenericAddress.parse("udp:"+host+"/"+port);

      for (Map.Entry<String, String> entry : config.entrySet())
      {
        String type = entry.getKey();
        if (type.length() > 4) {
          if (type.substring(0, 3).equals("oid")) {
            String type_string;
            String metric_type;
            oid_data data = new oid_data();
            data.name = type.substring(4);
            data.oid = entry.getValue();
            type_string = "type_" + data.name;
            data.metric_type = config.get(type_string);
            oids.put(data.name, data.oid);
            if (oid_hashmap.containsKey(data.oid.substring(1))) {
              ArrayList<oid_data> list = oid_hashmap.remove(data.oid.substring(1));
              list.add(data);
              oid_hashmap.put(data.oid.substring(1), list);
            }
            else {
              ArrayList<oid_data> list = new ArrayList<oid_data>();
              list.add(data);
              oid_hashmap.put(data.oid.substring(1), list);
            }
          }
        }
      }

      UdpAddress udpAddr = new UdpAddress(UdpAddress.ANY_IPADDRESS, 0);
      Snmp snmp = new Snmp(new DefaultUdpTransportMapping(udpAddr));
      /* the snmp connection is open... add a seprate try/catch so we can make sure we close it */
      try {
        if ((version.equals("1")) || (version.equals("2c"))) {
          target = getCommunityTarget(targetAddress, Integer.parseInt(timeout), community, version);
        }
        else {
            OID auth = null;
            OID priv = null;

            if (auth_protocol != null) {
              if (auth_protocol.equals("MD5")) {
                auth = AuthMD5.ID;
              }
              else if (auth_protocol.equals("SHA")) {
                auth = AuthSHA.ID;
              }
            }

            if (privacy_protocol != null) {
              if (privacy_protocol.equals("AES128")) {
                priv = PrivAES128.ID;
              }
              else if (privacy_protocol.equals("AES192")) {
                priv = PrivAES192.ID;
              }
              else if (privacy_protocol.equals("AES256")) {
                priv = PrivAES256.ID;
              }
              else if (privacy_protocol.equals("DES")) {
                priv = PrivDES.ID;
              }
            }

            SecurityProtocols sec = SecurityProtocols.getInstance();
            ((MPv3)snmp.getMessageProcessingModel(MPv3.ID)).setLocalEngineID(localEngineID.getValue());
            USM usm = new USM(sec, localEngineID, 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            UsmUser user = new UsmUser(new OctetString(security_name),
                                           auth,
                                           new OctetString(auth_passphrase),
                                           priv,
                                           new OctetString(privacy_passphrase));
            snmp.getUSM().addUser(user);
            SecurityModels.getInstance().addSecurityModel(new TSM(localEngineID, false));
            target = getUserTarget(targetAddress, Integer.parseInt(timeout), security_level, security_name, security_engine);
        }
        snmp.listen();
View Full Code Here

    }
    return null;
  }
  private Target getCommunityTarget (Address address, int timeout, String community, String version) {
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString(community));
    target.setAddress(address);
    target.setRetries(0);
    target.setTimeout(timeout/2);
    if (version.equals("1")) {
      target.setVersion(SnmpConstants.version1);
View Full Code Here

      target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
    }
    else {
      target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
    }
    target.setSecurityName(new OctetString(securityName));
    if (securityEngine != null) {
      target.setAuthoritativeEngineID(OctetString.fromHexStringPairs(securityEngine).getValue());
    }

    target.setVersion(SnmpConstants.version3);
View Full Code Here

      ScopedPDU scopedPDU = (ScopedPDU)request;
      if (contextEngine != null) {
        scopedPDU.setContextEngineID(OctetString.fromHexStringPairs(contextEngine));
      }
      if (contextName != null) {
        scopedPDU.setContextName(new OctetString(contextName));
      }
    }
    else {
      request = new PDU();
    }
View Full Code Here

   * @param o2 the second object to be compared.
   * @return a negative integer, zero, or a positive integer as the first
   *   argument is less than, equal to, or greater than the second.
   */
  public int compare(Object o1, Object o2) {
    OctetString os1 = (OctetString) o1;
    OctetString os2 = (OctetString) o2;

    int result = 0;
    if (!impliedLength) {
      result = os1.length() - os2.length();
    }
    if (result == 0) {
      result = os1.compareTo(os2);
    }
    return result;
View Full Code Here

    private Snmp _snmp;
    private CommunityTarget _target;

    public SnmpHelper(String address, String community) {
        _target = new CommunityTarget();
        _target.setCommunity(new OctetString(community));
        _target.setVersion(SnmpConstants.version2c);
        _target.setAddress(new UdpAddress(address));
        try {
            _snmp = new Snmp(new DefaultUdpTransportMapping());
        } catch (IOException e) {
View Full Code Here

                trap.add(new VariableBinding(getOID(CsSnmpConstants.CLUSTER_ID), new UnsignedInteger32(snmpTrapInfo
                    .getClusterId())));
            }

            if (snmpTrapInfo.getMessage() != null) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage
                    ())));
            } else {
                throw new CloudRuntimeException(" What is the use of alert without message ");
            }

            if (snmpTrapInfo.getGenerationTime() != null) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME),
                    new OctetString(snmpTrapInfo.getGenerationTime().toString())));
            } else {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
            }
        } else {
            throw new CloudRuntimeException(" Invalid alert Type ");
View Full Code Here

        // Could save some CPU cycles:
        // transport.setAsyncMsgProcessingSupported(false);
        Snmp snmp = new Snmp(transport);

        if (version == SnmpConstants.version3) {
            USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            addUsmUser(snmp);
        }

        return snmp;
View Full Code Here

TOP

Related Classes of org.snmp4j.smi.OctetString

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.