本文整理了Java中org.snmp4j.PDU.add()
方法的一些代码示例,展示了PDU.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PDU.add()
方法的具体详情如下:
包路径:org.snmp4j.PDU
类名称:PDU
方法名:add
[英]Adds a variable binding to this PDU. A NullPointerException
is thrown if VariableBinding
or its Variable
is null
.
[中]将变量绑定添加到此PDU。如果VariableBinding
或其Variable
为null
,则会抛出NullPointerException
。
代码示例来源:origin: apache/nifi
pdu.add(varBind);
result = true;
代码示例来源:origin: apache/nifi
/**
* Construct the PDU to perform the SNMP Get request and returns
* the result in order to create the flow file.
* @return {@link ResponseEvent}
*/
public ResponseEvent get() {
try {
PDU pdu = null;
if(this.target.getVersion() == SnmpConstants.version3) {
pdu = new ScopedPDU();
} else {
pdu = new PDU();
}
pdu.add(new VariableBinding(this.oid));
pdu.setType(PDU.GET);
return this.snmp.get(pdu, this.target);
} catch (IOException e) {
logger.error("Failed to get information from SNMP agent; " + this, e);
throw new ProcessException(e);
}
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws Exception {
// Create PDU
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))); // put your uptime here
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("10.101.21.32/162");
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);
}
代码示例来源:origin: apache/cloudstack
if (alertType > 0) {
long sysUpTimeTicks = ManagementFactory.getRuntimeMXBean().getUptime() / 10;
trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(sysUpTimeTicks)));
trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, getOID(CsSnmpConstants.TRAPS_PREFIX + alertType)));
if (snmpTrapInfo.getDataCenterId() != 0) {
trap.add(new VariableBinding(getOID(CsSnmpConstants.DATA_CENTER_ID), new UnsignedInteger32(snmpTrapInfo.getDataCenterId())));
trap.add(new VariableBinding(getOID(CsSnmpConstants.POD_ID), new UnsignedInteger32(snmpTrapInfo.getPodId())));
trap.add(new VariableBinding(getOID(CsSnmpConstants.CLUSTER_ID), new UnsignedInteger32(snmpTrapInfo.getClusterId())));
trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage())));
} else {
throw new CloudRuntimeException(" What is the use of alert without message ");
trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME), new OctetString(snmpTrapInfo.getGenerationTime().toString())));
} else {
trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
代码示例来源:origin: com.rogueai/snmp2bean
private PDU buildCreatePDU(Object entry) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchMethodException, InstantiationException, InvocationTargetException, SnmpAnnotationException {
PDU pdu = buildSetPDU(entry);
pdu.add(buildCreateVariableBinding(entry));
return pdu;
}
代码示例来源:origin: com.rogueai/snmp2bean
private PDU buildDeletPDU(Object entry) throws IllegalArgumentException, IllegalAccessException, SnmpAnnotationException {
PDU pdu = new PDU();
pdu.setType(PDU.SET);
pdu.add(buildDeleteVariableBinding(entry));
return pdu;
}
}
代码示例来源:origin: org.snmp4j/snmp4j
public SnmpUriResponse updateByValue(URI url, List<Variable> values) throws UnknownHostException {
SnmpUriResponse response;
Request request = createSnmpRequest(url);
PDU pdu = request.getPdu();
pdu.setType(PDU.SET);
OID[] oids = request.getOIDs();
for (int i=0; i<oids.length && i<values.size(); i++) {
pdu.add(new VariableBinding(oids[i], values.get(i)));
}
response = sendSnmpRequest(request, pdu);
return response;
}
代码示例来源:origin: com.rogueai/snmp2bean
public PDU buildGetPDU(Class scalarClass, String[] fields) throws SecurityException, NoSuchFieldException {
PDU pdu = new PDU();
pdu.setType(PDU.GET);
for (String fn : fields) {
Field field = scalarClass.getDeclaredField(fn);
MibObjectType mib = field.getAnnotation(MibObjectType.class);
pdu.add(new VariableBinding(new OID(mib.oid())));
}
return pdu;
}
代码示例来源:origin: OpenNMS/opennms
@Override
public void addVarBind(SnmpObjId name, SnmpValue value) {
OID oid = new OID(name.getIds());
Variable val = ((Snmp4JValue) value).getVariable();
m_pdu.add(new VariableBinding(oid, val));
}
代码示例来源:origin: OpenNMS/opennms
@Override
public void addOid(SnmpObjId snmpObjId) {
VariableBinding varBind = new VariableBinding(new OID(snmpObjId.getIds()));
m_nextPdu.add(varBind);
}
代码示例来源:origin: OpenNMS/opennms
@Override
public void addOid(SnmpObjId snmpObjId) {
VariableBinding varBind = new VariableBinding(new OID(snmpObjId.getIds()));
m_bulkPdu.add(varBind);
}
代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j
@Override
public void addOid(SnmpObjId snmpObjId) {
VariableBinding varBind = new VariableBinding(new OID(snmpObjId.getIds()));
m_bulkPdu.add(varBind);
}
代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j
@Override
public void addVarBind(SnmpObjId name, SnmpValue value) {
OID oid = new OID(name.getIds());
Variable val = ((Snmp4JValue) value).getVariable();
m_pdu.add(new VariableBinding(oid, val));
}
代码示例来源:origin: org.snmp4j/snmp4j
public SnmpUriResponse sendByBinding(URI url, List<VariableBinding> values, int pduType) throws UnknownHostException {
SnmpUriResponse response;
Request request = createSnmpRequest(url);
PDU pdu = request.getPdu();
pdu.setType(pduType);
for (VariableBinding vb : values) {
pdu.add(vb);
}
response = sendSnmpRequest(request, pdu);
return response;
}
代码示例来源:origin: org.openscada.atlantis/org.openscada.da.server.snmp
public ResponseEvent sendGET ( final OID oid ) throws IOException
{
final Target target = createTarget ();
final PDU pdu = createPDU ( target, PDU.GET );
pdu.add ( new VariableBinding ( oid ) );
return send ( target, pdu );
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
public void addVarBind(SnmpObjId name, SnmpValue value) {
OID oid = new OID(name.getIds());
Variable val = ((Snmp4JValue) value).getVariable();
m_pdu.add(new VariableBinding(oid, val));
}
代码示例来源:origin: org.apache.servicemix/servicemix-snmp
@Override
public void poll() throws Exception {
this.pdu.clear();
this.pdu.setType(PDU.GET);
// prepare the request items
for (OID oid : oids) {
this.pdu.add(new VariableBinding(oid));
}
// send the request
snmp.send(pdu, target, null, this);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j
public SnmpUriResponse sendByBinding(URI url, List<VariableBinding> values, int pduType) throws UnknownHostException {
SnmpUriResponse response;
Request request = createSnmpRequest(url);
PDU pdu = request.getPdu();
pdu.setType(pduType);
for (VariableBinding vb : values) {
pdu.add(vb);
}
response = sendSnmpRequest(request, pdu);
return response;
}
代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j
@Override
public void addOid(SnmpObjId snmpObjId) {
VariableBinding varBind = new VariableBinding(new OID(snmpObjId.getIds()));
m_nextPdu.add(varBind);
}
代码示例来源:origin: org.openscada.atlantis/org.openscada.da.server.snmp
public ResponseEvent sendGETNEXT ( final OID oid ) throws IOException
{
final Target target = createTarget ();
final PDU pdu = createPDU ( target, PDU.GETNEXT );
pdu.add ( new VariableBinding ( oid ) );
return send ( target, pdu );
}
}
内容来源于网络,如有侵权,请联系作者删除!