fix:测试demo完善
This commit is contained in:
parent
a919287719
commit
0f46865151
@ -23,7 +23,7 @@ public class SnmpTrapSender implements AutoCloseable{
|
||||
private String community;
|
||||
private int version;
|
||||
|
||||
public SnmpTrapSender(Map<String, String> map) throws IOException {
|
||||
public SnmpTrapSender(Map<String, String> map) throws Exception {
|
||||
loadConfig(map);
|
||||
initializeSNMP();
|
||||
}
|
||||
@ -36,13 +36,13 @@ public class SnmpTrapSender implements AutoCloseable{
|
||||
version = Integer.parseInt(map.getOrDefault("snmp.version", "1"));
|
||||
}
|
||||
|
||||
private void initializeSNMP() throws IOException {
|
||||
private void initializeSNMP() throws Exception {
|
||||
TransportMapping<?> transport = new DefaultUdpTransportMapping();
|
||||
snmp = new Snmp(transport);
|
||||
snmp.listen();
|
||||
}
|
||||
|
||||
public ResponseEvent sendTrap(String message, int severity) throws IOException {
|
||||
public ResponseEvent sendTrap(String message, int severity) throws Exception {
|
||||
ResponseEvent event = null;
|
||||
switch (version) {
|
||||
case SnmpConstants.version1:
|
||||
@ -57,7 +57,7 @@ public class SnmpTrapSender implements AutoCloseable{
|
||||
return event;
|
||||
}
|
||||
|
||||
private ResponseEvent sendV1Trap(String message, int severity) throws IOException {
|
||||
private ResponseEvent sendV1Trap(String message, int severity) throws Exception {
|
||||
CommunityTarget target = createCommunityTarget(SnmpConstants.version1);
|
||||
PDUv1 pdu = new PDUv1();
|
||||
configureCommonTrap(pdu, message, severity);
|
||||
@ -65,7 +65,7 @@ public class SnmpTrapSender implements AutoCloseable{
|
||||
return snmp.send(pdu, target);
|
||||
}
|
||||
|
||||
private ResponseEvent sendV2Trap(String message, int severity) throws IOException {
|
||||
private ResponseEvent sendV2Trap(String message, int severity) throws Exception {
|
||||
CommunityTarget target = createCommunityTarget(SnmpConstants.version2c);
|
||||
PDU pdu = new PDU();
|
||||
configureCommonTrap(pdu, message, severity);
|
||||
@ -96,7 +96,7 @@ public class SnmpTrapSender implements AutoCloseable{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() throws Exception {
|
||||
if (snmp != null) {
|
||||
snmp.close();
|
||||
snmp = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user