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


Java VariableBinding类代码示例

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


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

示例1: main

import org.snmp4j.smi.VariableBinding; //导入依赖的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

示例2: querySingleSNMPTableByOID

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
public List<SNMPTriple> querySingleSNMPTableByOID(String oid) throws IOException
{
 if(oid == null || oid.isEmpty())return null;
 if(!oid.startsWith("."))oid = "."+oid;
    TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
    List<TableEvent> events = tUtils.getTable(getTarget(), new OID[]{new OID(oid)}, null, null);

 List<SNMPTriple> snmpList = new ArrayList<SNMPTriple>();
    
    for (TableEvent event : events) {
      if(event.isError()) {
     	 logger.warning("SNMP event error: "+event.getErrorMessage());
     	 continue;
           //throw new RuntimeException(event.getErrorMessage());
      }
      for(VariableBinding vb: event.getColumns()) {
   	   String key = vb.getOid().toString();
   	   String value = vb.getVariable().toString();
   	 snmpList.add(new SNMPTriple(key, "", value));
      }
    }
 return snmpList;
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:24,代码来源:SNMPClient.java

示例3: sendPDU

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
/**
 * 向接收器发送Trap 信息
 * 
 * @throws IOException
 */
public void sendPDU() throws IOException {
	PDU pdu = new PDU();
	pdu.add(new VariableBinding(
			new OID(".1.3.6.1.2.1.1.1.0"),
			new OctetString("SNMP Trap Test.see more:http://www.micmiu.com")));
	pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(
			new UnsignedInteger32(System.currentTimeMillis() / 1000)
					.getValue())));
	pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(
			".1.3.6.1.6.3.1.1.4.3")));

	// 向Agent发送PDU
	pdu.setType(PDU.TRAP);
	snmp.send(pdu, target);
	System.out.println("----> Trap Send END <----");
}
 
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:22,代码来源:SnmpTrapSendDemo.java

示例4: snmpGet

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
/**
 * 获取指定OID的 get
 *
 * @param snmp
 * @param target
 * @param oid
 * @return
 * @throws IOException
 */
public static PDU snmpGet(Snmp snmp, Target target, String oid) throws IOException {
    ScopedPDU pdu = new ScopedPDU();
    pdu.setType(PDU.GET);
    pdu.add(new VariableBinding(new OID(oid)));

    ResponseEvent responseEvent = snmp.send(pdu, target);
    PDU response = responseEvent.getResponse();
    if(response == null){
        log.warn("response null - error:{} peerAddress:{} source:{} request:{}",
                responseEvent.getError(),
                responseEvent.getPeerAddress(),
                responseEvent.getSource(),
                responseEvent.getRequest());
    }
    return response;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:26,代码来源:SNMPHelper.java

示例5: snmpWalk

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
/**
 * walk方式获取指定的oid value
 *
 * @param snmp
 * @param target
 * @param oid
 * @return
 * @throws IOException
 */
public static List<PDU> snmpWalk(Snmp snmp, Target target, String oid) throws IOException {
    List<PDU> pduList = new ArrayList<>();

    ScopedPDU pdu = new ScopedPDU();
    OID targetOID = new OID(oid);
    pdu.add(new VariableBinding(targetOID));

    boolean finished = false;
    while (!finished) {
        VariableBinding vb = null;
        ResponseEvent respEvent = snmp.getNext(pdu, target);

        PDU response = respEvent.getResponse();

        if (null == response) {
            break;
        } else {
            vb = response.get(0);
        }
        // check finish
        finished = checkWalkFinished(targetOID, pdu, vb);
        if (!finished) {
            pduList.add(response);

            // Set up the variable binding for the next entry.
            pdu.setRequestID(new Integer32(0));
            pdu.set(0, vb);
        }
    }

    return pduList;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:42,代码来源:SNMPHelper.java

示例6: checkWalkFinished

import org.snmp4j.smi.VariableBinding; //导入依赖的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;

}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:19,代码来源:SNMPHelper.java

示例7: getAddDropPort

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
private PortNumber getAddDropPort(int channel, boolean isAddPort) {
    OID oid = new OID(CTRL_CHANNEL_ADD_DROP_PORT_INDEX + (isAddPort ? "1" : "2"));

    for (TreeEvent event : snmp.get(oid)) {
        if (event == null) {
            return null;
        }

        VariableBinding[] varBindings = event.getVariableBindings();

        for (VariableBinding varBinding : varBindings) {
            if (varBinding.getOid().last() == channel) {
                int port = varBinding.getVariable().toInt();
                if (!isAddPort) {
                    port += DROP_PORT_OFFSET;
                }
                return PortNumber.portNumber(port);

            }
        }

    }

    return null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:LumentumFlowRuleProgrammable.java

示例8: poll

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
@Override
protected int poll() throws Exception {
    this.pdu.clear();
    
    int type = this.getPduType(this.endpoint.getType());
    
    this.pdu.setType(type);

    // prepare the request items
    for (OID oid : this.endpoint.getOids()) {
        this.pdu.add(new VariableBinding(oid));
    }

    // send the request
    snmp.send(pdu, target, null, this);

    return 1;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:SnmpOIDPoller.java

示例9: getIndexes

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
@Override
public Varbind[] getIndexes() {
  if (indexExtractor == null) {
    return new Varbind[0];
  }
  IndexDescriptor[] descriptors = indexExtractor.extractIndexes(getOid());
  Varbind[] varbinds = new Varbind[descriptors.length];
  for (int i = 0; i < descriptors.length; i++) {
    IndexDescriptor descriptor = descriptors[i];
    Variable variable = AbstractVariable.createFromSyntax(
        descriptor.getSyntax());
    variable.fromSubIndex(new OID(descriptor.getEncoded()), 
        descriptor.isImplied());
    VariableBinding vb = new VariableBinding(new OID(descriptor.getOid()), 
        variable);
    varbinds[i] = varbindFactory.newVarbind(vb);
  }
  return varbinds;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:20,代码来源:Snmp4jVarbind.java

示例10: get

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
/**
 * This method is capable of handling multiple OIDs
 * @param oids
 * @return
 * @throws IOException
 */
public Map<OID, String> get(OID oids[]) throws IOException 
{
	PDU pdu = createPDU();
	for (OID oid : oids) {
		pdu.add(new VariableBinding(oid));
	}
	pdu.setType(PDU.GET);
	ResponseEvent event = snmp.send(pdu, getTarget(), null);
	if(event != null) {
		PDU pdu2 = event.getResponse();
		VariableBinding[] binds = pdu2!=null?event.getResponse().toArray():null;
		if(binds!=null)
		{
			Map<OID, String> res = new LinkedHashMap<OID, String>(binds.length);
			for(VariableBinding b: binds)
				res.put(b.getOid(), b.getVariable().toString());
			return res;
		}else return null;
	}
	throw new RuntimeException("GET timed out");
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:28,代码来源:SNMPClient.java

示例11: snmpWalk

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
/**
 * Triggers snmpwalk command.
 * 
 * @param oid oid
 * @param target {@link org.snmp4j.Target}
 * @return response from SNMP server
 * @throws IllegalStateException
 */
public List<String> snmpWalk(OID oid, Target target) {
	validateSnmpClient();
	
	final List<TreeEvent> events = prepareTreeUtils().getSubtree(target, oid);
	if (events == null || events.size() == 0) {
		throw new IllegalStateException("Wrapper Error: Response is null");
	}
	
	List<String> response = new ArrayList<String>();
	for(TreeEvent event : events) {
		if (event.isError()) {
			throw new IllegalStateException(prepareErrorExceptionForWalk(oid, event));
		}
		
		final VariableBinding[] varBindings = event.getVariableBindings();
		if (varBindings == null || varBindings.length == 0) {
				throw new IllegalStateException("SNMPWrapper Error: Response is null");
			}
		for (VariableBinding varBinding : varBindings) {
				response.add(varBinding.toString());
		}
	}
	return response;
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:33,代码来源:SNMPWrapper.java

示例12: testTimeTickVariable

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
@Test
public void testTimeTickVariable() throws InterruptedException {
	String expectedOid = "1.3.6.1.2.1.1.3.0";
	Number expectedValue = 2929358;
	String expectedSource = "www.myweb.com";
	String expectedMetricId = "MY_FAVORITE_METRIC";
	
	VariableBinding vb = new VariableBinding();
	TimeTicks v = new TimeTicks();
	v.setValue(expectedValue.longValue());
	
	vb.setOid(new OID(expectedOid));
	vb.setVariable(v);

	SnmpPollerConfiguration config = getSnmpPollerConfiguration(
			expectedSource,expectedMetricId,expectedOid);
	out.expectedMessageCount(1);
	in.sendBodyAndHeaders(vb,setScriptHeaders(SNMP_TO_MEASURE_SCRIPT,config));
	out.assertIsSatisfied();
	
	Measurement m = getMeasurement(out);
	assertNotNull("check event for null",m);
	assertEquals("check source",expectedSource,m.getSource());
	assertEquals("check metric",expectedMetricId,m.getMetric());
	assertEquals("check measure",v.getValue(),m.getMeasure().intValue());
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:27,代码来源:SnmpToMeasureTest.java

示例13: testCounter32Variable

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
@Test
public void testCounter32Variable() throws InterruptedException {
	String expectedOid = "1.3.6.1.2.1.4.3.0";
	Number expectedValue = 1588007;
	String expectedSource = "www.myweb.com";
	String expectedMetricId = "MY_FAVORITE_METRIC";
	
	VariableBinding vb = new VariableBinding();
	Counter32 v = new Counter32();
	v.setValue(expectedValue.longValue());
	
	vb.setOid(new OID(expectedOid));
	vb.setVariable(v);

	SnmpPollerConfiguration config = getSnmpPollerConfiguration(
			expectedSource,expectedMetricId,expectedOid);
	out.expectedMessageCount(1);
	in.sendBodyAndHeaders(vb,setScriptHeaders(SNMP_TO_MEASURE_SCRIPT,config));
	out.assertIsSatisfied();
	
	Measurement m = getMeasurement(out);
	assertNotNull("check event for null",m);
	assertEquals("check source",expectedSource,m.getSource());
	assertEquals("check metric",expectedMetricId,m.getMetric());
	assertEquals("check measure",v.getValue(),m.getMeasure().intValue());
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:27,代码来源:SnmpToMeasureTest.java

示例14: TestRisingAlarm

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
@Ignore("Broken Test, lookup fails in RMON-MIB")
@Test
public void TestRisingAlarm() throws InterruptedException {
	out.expectedMessageCount(1);
	
	SmiObject notification = smiManager.findSmiObject("RMON-MIB","rmon.rmonEventsV2.risingAlarm");
	assertNotNull("check for null SmiObject",notification);
	OID oid = notification.getOID();
	SendTrap sendTrap = SendTrapDefault();
	sendTrap.addVariableBinding(new VariableBinding(oid,new OctetString("Rising Alarm")));
	
	out.assertIsSatisfied();
	
	SnmpTrap trap = getTrap();
	assertNotNull(trap);
	assertEquals("check trap name","risingAlarm",trap.getTrapName()); 
	
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:19,代码来源:SnmpSendTrapRouteTest.java

示例15: testSnmpGet

import org.snmp4j.smi.VariableBinding; //导入依赖的package包/类
@Ignore ("Need Mock SSH Server")
@Test
public void testSnmpGet() throws InterruptedException {
	out.setMinimumExpectedMessageCount(1);
	out.await(10,TimeUnit.SECONDS);
	out.assertIsSatisfied();
	
	CamelContext context = context();
	
	List<Exchange> exchanges = out.getExchanges();
	for (Exchange exchange : exchanges) {
		Message message = exchange.getOut();
		SnmpMessage snmpMessage = message.getBody(SnmpMessage.class);
		LOG.info("body: ",snmpMessage);
		assertNotNull("Body is null",snmpMessage);
		PDU pdu = snmpMessage.getSnmpMessage();
		for (Object o :  pdu.getVariableBindings()) {
			VariableBinding b = (VariableBinding)o;
			LOG.info("oid: {}, value: {}",b.getOid().toString(),b.getVariable().toString());
		}
	}
}
 
开发者ID:boundary,项目名称:boundary-event-sdk,代码行数:23,代码来源:SNMPSpringTest.java


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