Package org.snmp4j

Examples of org.snmp4j.CommunityTarget


      return "Unknown Context";
    }
    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);
    }
    else {
      target.setVersion(SnmpConstants.version2c);
    }
    return target;
  }
View Full Code Here


public class SnmpHelper {
    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());
View Full Code Here

            }

            target.setSecurityName(securityName);
            return target;
        } else {
            CommunityTarget target = new CommunityTarget();
            target.setCommunity(community);
            return target;
        }
    }
View Full Code Here

        PDU pdu = new PDU();
        pdu.setType(PDU.TRAP);
        add(pdu, alertName, message);
        add(pdu, alertSeverity, Severity.medium);

        CommunityTarget target = new CommunityTarget();
        target.setCommunity(community);
        target.setVersion(SnmpConstants.version2c);
        target.setAddress(new UdpAddress(address, port));
        target.setTimeout(1000);
        target.setRetries(2);

        try {
            snmp.send(pdu, target);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
View Full Code Here

        if (session == null) {
            session = initSession();
        }

        Address address = GenericAddress.parse("udp:" + host + "/" + port);
        this.target = new CommunityTarget();
        this.target.setAddress(address);
        this.target.setCommunity(new OctetString(community));
        this.target.setVersion(this.version);
        this.target.setRetries(retries);
        this.target.setTimeout(timeout);
View Full Code Here

        this.snmp = new Snmp(this.transport);
        this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);

        // setting up target
        target = new CommunityTarget();
        target.setCommunity(new OctetString(this.endpoint.getSnmpCommunity()));
        target.setAddress(targetAddress);
        target.setRetries(this.endpoint.getRetries());
        target.setTimeout(this.endpoint.getTimeout());
        target.setVersion(this.endpoint.getSnmpVersion());
View Full Code Here

        createOctetString((String)
                          ArgumentParser.getValue(settings, oCommunity, 0),
                          "public");
    Target t;
    if ("1".equals(version)) {
      t = new CommunityTarget();
      t.setVersion(SnmpConstants.version1);
      ((CommunityTarget)t).setCommunity(community);
    }
    else if ("2c".equals(version)) {
      t = new CommunityTarget();
      t.setVersion(SnmpConstants.version2c);
      ((CommunityTarget)t).setCommunity(community);
    }
    else {
      UserTarget ut = new UserTarget();
View Full Code Here

            OctetString community1 = new OctetString(community);
            String host = ipAddress + "/" + port;
            Address tHost = new UdpAddress(host);
            TransportMapping transport = new DefaultUdpTransportMapping();
            transport.listen();
            CommunityTarget comtarget = new CommunityTarget();
            comtarget.setCommunity(community1);
            comtarget.setVersion(SnmpConstants.version1);
            comtarget.setAddress(tHost);
            comtarget.setRetries(2);
            comtarget.setTimeout(5000);
            PDU pdu = new PDU();
            pdu.add(new VariableBinding(new OID(strOID)));
            pdu.setType(PDU.GET);
            snmp = new Snmp(transport);
            response = snmp.get(pdu, comtarget);
View Full Code Here

        Snmp snmp;
        try {
            TransportMapping transport = new DefaultUdpTransportMapping();
            snmp = new Snmp(transport);
            transport.listen();
            CommunityTarget target = new CommunityTarget();
            target.setCommunity(new OctetString(community));
            target.setAddress(tHost);
            target.setRetries(2);
            target.setTimeout(5000);
            target.setVersion(SnmpConstants.version1); //Set the correct SNMP version here
            PDU pdu = new PDU();
            //Depending on the MIB attribute type, appropriate casting can be done here
            pdu.add(new VariableBinding(new OID(strOID), new Integer32(Integer.valueOf(value))));
            pdu.setType(PDU.SET);
            ResponseListener listener = new ResponseListener() {
View Full Code Here

            OctetString community1 = new OctetString(community);
            String host = ipAddress + "/" + port;
            Address tHost = new UdpAddress(host);
            TransportMapping transport = new DefaultUdpTransportMapping();
            transport.listen();
            CommunityTarget comtarget = new CommunityTarget();
            comtarget.setCommunity(community1);
            comtarget.setVersion(SnmpConstants.version1);
            comtarget.setAddress(tHost);
            comtarget.setRetries(2);
            comtarget.setTimeout(5000);
            PDU pdu = new PDU();
            pdu.add(new VariableBinding(new OID(strOID)));
            pdu.setType(PDU.GET);
            snmp = new Snmp(transport);
            response = snmp.get(pdu, comtarget);
View Full Code Here

TOP

Related Classes of org.snmp4j.CommunityTarget

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.