本文整理汇总了Java中org.snmp4j.PDU.add方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.add方法的具体用法?Java PDU.add怎么用?Java PDU.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.snmp4j.PDU
的用法示例。
在下文中一共展示了PDU.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendPDU
import org.snmp4j.PDU; //导入方法依赖的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 <----");
}
示例2: get
import org.snmp4j.PDU; //导入方法依赖的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");
}
示例3: sendTrapV2
import org.snmp4j.PDU; //导入方法依赖的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();
}
示例4: configure
import org.snmp4j.PDU; //导入方法依赖的package包/类
@Override
public void configure(Context context) {
ImmutableMap<String, String> parameters;
String baseString = "oid";
boolean notFound = true;
int i = 0;
parameters = context.getParameters();
logger.info("parameters: " + parameters);
pdu = new PDU();
do {
i++ ;
if (!parameters.containsKey(baseString + i)) {
notFound = false;
} else {
logger.info("parameter: " + parameters.get(baseString + i));
pdu.add(new VariableBinding(new OID(parameters.get(baseString + i))));
}
} while (notFound);
bindAddress = context.getString("host");
bindPort = context.getInteger("port", DEFAULT_PORT);
delayQuery = context.getInteger("delay", DEFAULT_DELAY);
}
示例5: getPDU
import org.snmp4j.PDU; //导入方法依赖的package包/类
private PDU getPDU(OID oids[]) {
PDU pdu = new PDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
return pdu;
}
示例6: createRequest
import org.snmp4j.PDU; //导入方法依赖的package包/类
protected PDU createRequest(VariableBinding[] varbinds) {
PDU pdu = context.getPduFactory().newPDU();
for (VariableBinding varbind : varbinds) {
pdu.add(varbind);
}
return pdu;
}
示例7: getEvent
import org.snmp4j.PDU; //导入方法依赖的package包/类
public ResponseEvent getEvent(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) {
return event;
}
throw new RuntimeException("GET timed out");
}
示例8: getDiskData
import org.snmp4j.PDU; //导入方法依赖的package包/类
public List<SNMPTriple> getDiskData(String device) throws IOException {
int index = this.getDiskIndex(device);
if(index<0)
{
return new ArrayList<SNMPTriple>();
}
logger.fine("Query disk stats for "+index);
PDU pdu = createPDU();
for ( int i=1; i< DISK_TABLE_ENTRIES.length; i++) {
if(DISK_TABLE_ENTRIES[i].length()==0)continue;
pdu.add(new VariableBinding(new OID("."+DISK_TABLE_OID+"."+i+"."+index)));
}
pdu.setType(PDU.GET);
Map<String, String> res = new HashMap<String, String>(13);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) {
VariableBinding[] binds = event.getResponse().toArray();
for(VariableBinding b: binds)
res.put(b.getOid().toString(), b.getVariable().toString());
//logger.info(res.toString());
}
List<SNMPTriple> resList = new ArrayList<SNMPTriple>(res.size());
for(int i=1;i<DISK_TABLE_ENTRIES.length; i++) {
if(DISK_TABLE_ENTRIES[i].length()==0)continue;
resList.add(new SNMPTriple("."+DISK_TABLE_OID+"."+i+"."+index, DISK_TABLE_ENTRIES[i], res.get(DISK_TABLE_OID+"."+i+"."+index)));
}
return resList;
}
示例9: get
import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* This method is capable of handling multiple OIDs
* @param oids
* @return
* @throws IOException
*/
public ResponseEvent get(OID oids[]) throws IOException {
PDU pdu = new PDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if(event != null) {
return event;
}
throw new RuntimeException("GET timed out");
}
示例10: getPDU
import org.snmp4j.PDU; //导入方法依赖的package包/类
protected PDU getPDU(){
PDU retVal = new PDU();
retVal.add(sysUpTime.getVariableBinding());
for(snmpGetHolder curr :vectorIndecies){
for(OIDHolder currh : curr.channels){
retVal.add(currh.getVariableBinding());
}
}
return retVal;
}
示例11: addVariableBindings
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void addVariableBindings(PDU pdu, List<SNMPGetHolder> vect){
OIDHolder tmp;
// request Sub-if name/desc
if(vect != null){
for(SNMPGetHolder curr :vect){
tmp = curr.ifHolder;
pdu.add(tmp.getVariableBinding());
tmp = tmp.getDescriptionHolder();
if(tmp != null){
pdu.add(tmp.getVariableBinding());
}
}
}
}
示例12: getPDU
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static PDU getPDU(List<SNMPGetHolder> vect){
PDU retVal = new PDU();
for(SNMPGetHolder curr :vect){
for(OIDHolder currh : curr.channels){
retVal.add(currh.getVariableBinding());
}
}
return retVal;
}
示例13: addVariableBindings
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void addVariableBindings(PDU pdu, List<SNMPEntry> vect){
OIDHolder tmp;
for(SNMPEntry curr :vect){
pdu.add(new VariableBinding(curr.getOid()));
}
}
示例14: getIFInfoOIDs
import org.snmp4j.PDU; //导入方法依赖的package包/类
public static PDU getIFInfoOIDs(PDU retVal, int index){
retVal.add(getOIDVar(UPTIME_OID, UPTIME_STRING, index));
retVal.add(getOIDVar(IFINOCT_OID, IFINOCT_STRING, index));
retVal.add(getOIDVar(IFHCINOCT_OID, IFINOCT_STRING, index));
retVal.add(getOIDVar(IFOUTOCT_OID, IFOUTOCT_STRING, index));
retVal.add(getOIDVar(IFHCOUTOCT_OID,IFHCOUTOCT_STRING, index));
retVal.add(getOIDVar(IFERRORS_OID, IFERRORS_STRING, index));
return retVal;
}
示例15: send
import org.snmp4j.PDU; //导入方法依赖的package包/类
public void send() throws IOException {
// Create PDU
PDU trap = new PDU();
trap.setType(PDU.TRAP);
if (this.varBinds.size() == 0) {
addDefaultTrap();
}
// Add the varbinds to the trap
for (VariableBinding vb : this.varBinds) {
trap.add(vb);
}
// Set our target
Address targetaddress = new UdpAddress(getTargetAddress());
CommunityTarget target = new CommunityTarget();
// Set the community read string
target.setCommunity(new OctetString(this.community));
// Set the version of the trap
target.setVersion(version.version);
target.setAddress(targetaddress);
LOG.info("trap: {}",trap);
// Send the trap
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.send(trap, target, null, null);
}