本文整理了Java中org.snmp4j.Snmp.send()
方法的一些代码示例,展示了Snmp.send()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Snmp.send()
方法的具体详情如下:
包路径:org.snmp4j.Snmp
类名称:Snmp
方法名:send
[英]Sends a PDU
to the given target and if the PDU
is a confirmed request, then the received response is returned synchronously.
[中]向给定目标发送PDU
,如果PDU
是已确认的请求,则同步返回收到的响应。
代码示例来源:origin: apache/cloudstack
public void sendSnmpTrap(SnmpTrapInfo snmpTrapInfo) {
try {
if (_snmp != null) {
_snmp.send(createPDU(snmpTrapInfo), _target, null, null);
}
} catch (IOException e) {
throw new CloudRuntimeException(" Error in sending SNMP Trap, " + e.getMessage());
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j
public void send(PDU pdu, Target target,
TransportMapping transport,
Object userHandle,
ResponseListener listener) throws IOException {
if (!pdu.isConfirmedPdu()) {
sendMessage(pdu, target, transport, null);
return;
}
if (timer == null) {
createPendingTimer();
}
PendingRequest request =
new AsyncPendingRequest(listener, userHandle, pdu, target, transport);
sendMessage(request.pdu, target, transport, request);
}
代码示例来源:origin: pentaho/pentaho-kettle
pdu1.add( new VariableBinding( new OID( Oid ), new OctetString( messageString ) ) );
response = snmp.send( pdu1, target );
response = snmp.send( pdu, usertarget );
代码示例来源:origin: org.kaazing/snmp4j
public void send(PDU pdu, Target target,
TransportMapping transport,
Object userHandle,
ResponseListener listener) throws IOException {
if (!pdu.isConfirmedPdu()) {
sendMessage(pdu, target, transport, null);
return;
}
if (timer == null) {
createPendingTimer();
}
PendingRequest request =
new AsyncPendingRequest(listener, userHandle, pdu, target, transport);
sendMessage(pdu, target, transport, request);
}
代码示例来源: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: org.snmp4j/snmp4j
public void send(PDU pdu, Target target,
Object userHandle,
ResponseListener listener) throws IOException {
send(pdu, target, null, userHandle, listener);
}
代码示例来源:origin: org.openscada.atlantis/org.openscada.da.server.snmp
public ResponseEvent send ( final Target target, final PDU pdu ) throws IOException
{
return this.snmp.send ( pdu, target );
}
代码示例来源:origin: org.snmp4j/snmp4j
public ResponseEvent send(PDU pdu, Target target) throws IOException {
return send(pdu, target, null);
}
代码示例来源:origin: org.kaazing/snmp4j
public ResponseEvent send(PDU pdu, Target target) throws IOException {
return send(pdu, target, null);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j
public ResponseEvent send(PDU pdu, Target target) throws IOException {
return send(pdu, target, null);
}
代码示例来源:origin: org.openhab.binding/org.openhab.binding.snmp
private void sendPDU(CommunityTarget target, PDU pdu) {
try {
snmp.send(pdu, target, null, this);
} catch (IOException e) {
logger.error("Error sending PDU", e);
}
}
代码示例来源:origin: jrask/snmp-blog
public void getAsString(OID oids,ResponseListener listener) {
try {
snmp.send(getPDU(new OID[]{oids}), getTarget(),null, listener);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: jrask/snmp-blog
public ResponseEvent get(OID oids[]) throws IOException {
ResponseEvent event = snmp.send(getPDU(oids), getTarget(), null);
if(event != null) {
return event;
}
throw new RuntimeException("GET timed out");
}
代码示例来源:origin: fbacchella/jrds
private PDU request(PDU requestPDU, Target target) throws Exception {
Snmp snmp = getSnmp();
ResponseEvent re = snmp.send(requestPDU, target);
if(re == null)
throw new IOException("SNMP Timeout");
PDU response = re.getResponse();
if(response == null || re.getError() != null) {
Exception snmpException = re.getError();
if(snmpException == null)
snmpException = new IOException("SNMP Timeout");
throw snmpException;
}
return response;
}
代码示例来源:origin: griddynamics/jagger
public ResponseEvent get(List<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");
}
代码示例来源: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: com.addc/addc-alerts
@Override
public int notifyAlert(Alert alert, Translator translator) {
if (alert.getLevel().ordinal() < threshold.ordinal()) {
return 0;
}
long timeTicks= System.currentTimeMillis() - startTime;
PDU pdu= varBindsBuilder.populateTrap(alert, getApplicationId(), timeTicks, snmpVersion);
if (pdu == null) {
LOGGER.error("Failed to generate version {} Trap", snmpVersion + 1);
return 1;
}
try {
context.send(pdu, comTarget);
return 0;
} catch (IOException e) {
LOGGER.error(I18nText.markKey("Failed to send PDU"), e);
return 1;
}
}
代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit
private VariableBinding getSingleVariable(OID oid) throws IOException {
PDU pdu = this.pduFactory.createPDU(getTarget());
pdu.setType(PDU.GETNEXT);
pdu.add(new VariableBinding(oid));
ResponseEvent responseEvent = snmp.send(pdu, getTarget());
PDU responsePDU = null;
if (responseEvent != null) responsePDU = responseEvent.getResponse();
VariableBinding vb = null;
if (responsePDU != null) vb = responsePDU.get(0);
return vb;
}
代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j
protected void sendNextPdu(WalkerPduBuilder pduBuilder) throws IOException {
Snmp4JPduBuilder snmp4JPduBuilder = (Snmp4JPduBuilder)pduBuilder;
if (m_session == null) {
m_session = m_agentConfig.createSnmpSession();
m_session.listen();
}
if (log().isDebugEnabled()) {
log().debug("Sending tracker pdu of size "+snmp4JPduBuilder.getPdu().size());
}
m_session.send(snmp4JPduBuilder.getPdu(), m_tgt, null, m_listener);
}
代码示例来源:origin: org.opendaylight.cardinal/cardinal-impl
public boolean sendTrap() throws IOException{
//create PDU
PDU trap = new PDU();
trap.setType(PDU.TRAP);
OID oid = new OID(".1.3.6.1.3.1.1.1.36.0");
trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
Variable var = new OctetString("My system is in trouble");
trap.add(new VariableBinding(oid, var));
//create target
Address targetaddress = new UdpAddress("localhost/162");
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(targetaddress);
//send trap
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.send(trap, target, null, null);
return true;
}
}
内容来源于网络,如有侵权,请联系作者删除!