当前位置: 首页>>代码示例>>Java>>正文


Java CommunityTarget类代码示例

本文整理汇总了Java中org.snmp4j.CommunityTarget的典型用法代码示例。如果您正苦于以下问题:Java CommunityTarget类的具体用法?Java CommunityTarget怎么用?Java CommunityTarget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CommunityTarget类属于org.snmp4j包,在下文中一共展示了CommunityTarget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUpTarget

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
 * Helper method that initializes the snmp target to listening mode. This
 * method is explicitly for V1 and V2 messages. This method will create and
 * set up the TransportMapping and target for SNMP V1 and V2. It creates a
 * TransportMapping and puts it in the listening mode. Also Creates
 * CommunityTarget object and sets SNMP target properties.
 *
 * @param communityName
 *            Community name of the target
 * @param targetIP
 *            IP address of Target machine
 * @param portNumber
 *            Port number
 * @return The Target created
 * @throws IOException
 *             IOException
 */
private Target setUpTarget( final String communityName, final String targetIP, final int portNumber )
        throws IOException
{
    final InetAddress inetAddress = InetAddress.getByName( targetIP );
    final Address address = new UdpAddress( inetAddress, portNumber );
    final OctetString community = new OctetString( communityName );
    final TransportMapping transport = new DefaultUdpTransportMapping();
    snmp = new Snmp( transport );
    snmp.listen();

    // Creating the communityTarget object and setting its properties
    final CommunityTarget communityTarget = new CommunityTarget();
    communityTarget.setCommunity( community );
    // TODO Needs to check also for v2 messages
    communityTarget.setVersion( SnmpConstants.version1 );
    communityTarget.setAddress( address );
    // TODO Need to confirm, whether this value needs to be configures
    communityTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
    // TODO Need to confirm, whether this value needs to be configures
    communityTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
    return communityTarget;
}
 
开发者ID:Comcast,项目名称:cats,代码行数:40,代码来源:SnmpManagerImpl.java

示例2: main

import org.snmp4j.CommunityTarget; //导入依赖的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());
	    }
    }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:40,代码来源:testSNMPGetBulk.java

示例3: sendTrap

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
 * Send next-in-line trap from queue to to SNMP server
 */
public void sendTrap() {
	
	String trapVal = trapQueue.poll();
	if (trapVal == null) {
		return;
	}

	try {
		PDUv1 trapPdu = createTrapPDU(trapVal);	    	
		DefaultUdpTransportMapping tm = new DefaultUdpTransportMapping();
		Snmp snmp = new Snmp(tm);
		tm.listen();
		OctetString community = new OctetString(SNMP_XAP_COMMUNITY);
		Address add = GenericAddress.parse("udp" + ":" + snmpServerIP + "/" + snmpServerPort);
		CommunityTarget target = new CommunityTarget(add, community);
		target.setVersion(SnmpConstants.version1);
		target.setRetries(0);
		target.setTimeout(5000);		
		snmp.send(trapPdu, target);  
	} 
	catch (IOException e) {
		e.printStackTrace();
	} 
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:28,代码来源:SnmpTrapSender.java

示例4: getTarget

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
* This method returns a Target, which contains information about
* where the data should be fetched and how.
* @return
*/
private Target getTarget() {
	if("3".equals(this.version))return getTargetV3();
	Address targetAddress = GenericAddress.parse(address);
	CommunityTarget target = new CommunityTarget();
	//logger.info("snmp version "+this.version+", community: "+this.community);
	if(this.community == null || this.community.isEmpty())
		target.setCommunity(new OctetString("public"));
	else 
		target.setCommunity(new OctetString(this.community));
	target.setAddress(targetAddress);
	target.setRetries(2);
	target.setTimeout(5000);
	target.setVersion(this.getVersionInt());
	return target;
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:21,代码来源:SNMPClient.java

示例5: start

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
@Override
public void start() {
    // Initialize the connection to the external client
    try {
        snmp = new Snmp(new DefaultUdpTransportMapping());
        snmp.listen();

        target = new CommunityTarget();
        target.setCommunity(new OctetString("public"));
        target.setVersion(SnmpConstants.version2c);
        target.setAddress(new UdpAddress(bindAddress + "/" + bindPort));
        target.setTimeout(3000);    //3s
        target.setRetries(1);

        pdu.setType(PDU.GETBULK);
        pdu.setMaxRepetitions(1); 
        pdu.setNonRepeaters(0);

    } catch (IOException ex) {
        //
    }

    super.start();
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:25,代码来源:SNMPQuerySource.java

示例6: sendTrap

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
protected void sendTrap(String message) throws Exception {
    PDU pdu = new PDU();
    pdu.setType(PDU.TRAP);
    add(pdu, alertName, message);
    add(pdu, alertSeverity, Severity.medium);
    add(pdu, alertSource, "rhq.org");

    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);
    }
}
 
开发者ID:genman,项目名称:rhq-plugins,代码行数:21,代码来源:SnmpTrapdComponentTest.java

示例7: sendTrapV2

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
public static void sendTrapV2(String port) throws IOException {
    PDU trap = new PDU();
    trap.setType(PDU.TRAP);

    OID oid = new OID("1.2.3.4.5");
    trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
    trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));

    // Add Payload
    Variable var = new OctetString("some string");
    trap.add(new VariableBinding(oid, var));

    // Specify receiver
    Address targetaddress = new UdpAddress("127.0.0.1/" + port);
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(targetaddress);

    // Send
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.send(trap, target, null, null);

    snmp.close();
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:27,代码来源:SNMPUtils.java

示例8: getTarget

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
private Target getTarget() {
    Address targetAddress = GenericAddress.parse("udp:" + snmpHost + "/" + snmpPort);
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString(community));
    target.setAddress(targetAddress);
    target.setRetries(2);
    target.setTimeout(1500);
    target.setVersion("1".equals(version) ? SnmpConstants.version1 : SnmpConstants.version2c);
    return target;
}
 
开发者ID:globocom,项目名称:groot,代码行数:11,代码来源:SimpleSnmpClient.java

示例9: createDevice

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
private void createDevice(String ipAddress, int port) throws IOException {
    Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port);
    TransportMapping transport = new DefaultUdpTransportMapping();
    transport.listen();
    snmp = new Snmp(transport);

    // setting up target
    target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(targetAddress);
    target.setRetries(3);
    target.setTimeout(1000 * 3);
    target.setVersion(SnmpConstants.version2c);
    target.setMaxSizeRequestPDU(MAX_SIZE_RESPONSE_PDU);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:LumentumSnmpDevice.java

示例10: newTarget

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
@Override
public Target newTarget(SnmpTarget target) {
  if (!(target instanceof SnmpV2cTarget)) return null;
  CommunityTarget communityTarget = new CommunityTarget();
  communityTarget.setVersion(SnmpConstants.version2c);
  String community = ((SnmpV2cTarget) target).getCommunity();
  communityTarget.setCommunity(new OctetString(community));
  return communityTarget;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:10,代码来源:CommunityTargetStrategy.java

示例11: createDefault

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
 * 创建对象communityTarget,用于返回target
 *
 * @param targetAddress
 * @param community
 * @param version
 * @param timeOut
 * @param retry
 * @return CommunityTarget
 */
public static CommunityTarget createDefault(String ip, String community) {
  Address address = GenericAddress.parse(DEFAULT_PROTOCOL + ":" + ip
      + "/" + DEFAULT_PORT);
  CommunityTarget target = new CommunityTarget();
  target.setCommunity(new OctetString(community));
  target.setAddress(address);
  target.setVersion(DEFAULT_VERSION);
  target.setTimeout(DEFAULT_TIMEOUT); // milliseconds
  target.setRetries(DEFAULT_RETRY);
  return target;
}
 
开发者ID:waylau,项目名称:snmp4j-demos,代码行数:22,代码来源:SnmpData.java

示例12: sendPDU

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
private void sendPDU(CommunityTarget target, PDU pdu) {
	try {
		snmp.send(pdu, target, null, this);
	} catch (IOException e) {
		logger.error("Error sending PDU", e);
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:8,代码来源:SnmpBinding.java

示例13: createDefault

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
 * Create communityTarget.
 *
 * @param ip
 * @param community
 * @return CommunityTarget
 */
private static CommunityTarget createDefault(String ip, String community) {
    Address address = GenericAddress.parse(DEFAULT_PROTOCOL + ":" + ip
            + "/" + DEFAULT_PORT);
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString(community));
    target.setAddress(address);
    target.setVersion(DEFAULT_VERSION);
    target.setTimeout(DEFAULT_TIMEOUT); // milliseconds
    target.setRetries(DEFAULT_RETRY);
    return target;
}
 
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:19,代码来源:SnmpSimpleGet.java

示例14: createDefault

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
 * Create communityTarget.
 *
 * @param ip
 * @param community
 * @return CommunityTarget
 */
private static CommunityTarget createDefault(String ip, String community) {

    Address address = GenericAddress.parse(DEFAULT_PROTOCOL + ":" + ip + "/" + DEFAULT_PORT);
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString(community));
    target.setAddress(address);
    target.setVersion(DEFAULT_VERSION);
    target.setRetries(DEFAULT_RETRY);
    target.setTimeout(DEFAULT_TIMEOUT); // milliseconds
    return target;
}
 
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:19,代码来源:SnmpSimpleSet.java

示例15: getTarget

import org.snmp4j.CommunityTarget; //导入依赖的package包/类
/**
* This method returns a Target, which contains information about
* where the data should be fetched and how.
* @return
*/
private Target getTarget() {
Address targetAddress = GenericAddress.parse(address);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
return target;
}
 
开发者ID:rhamnett,项目名称:dazzl,代码行数:16,代码来源:SnmpTest.java


注:本文中的org.snmp4j.CommunityTarget类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。