df
Alejandro Acuña
2024-09-16 f56295b7f2c7282783589fb4903529b09e161daa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package art.servers.signalsboardserver.controller.trapreceiver;
 
import art.library.net.snmp.SNMPTrapReceiver;
import art.library.net.snmp.SNMPListener;
import art.servers.signalsboardserver.Shared;
import art.servers.signalsboardserver.controller.ControllerUniversal;
import java.util.List;
import org.snmp4j.smi.VariableBinding;
 
 
public class TrapReceiver
{
    private SNMPTrapReceiver receiver = null;
 
 
    public TrapReceiver()
    {
       try
       {
           receiver = new SNMPTrapReceiver("127.0.0.1", 162, "public");
           receiver.addListener(new MyListener());
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }
    }
    
    
    
   private static class MyListener extends SNMPListener
   {
        public void trap(String sourceAddress, List<VariableBinding> variables)
        {
            try
            {
                Shared.println("TrapListener", "Received trap from " + sourceAddress);
 
                // TODO: Get SNMP with this address
                ControllerUniversal controller = Shared.controllersSnmp.get(sourceAddress);
                controller.trapReceived(sourceAddress, variables);
//                for (VariableBinding variable : variables)
//                {
//                    try
//                    {
//                        Shared.println("TrapListener", "Variable: " + variable.toString());
//                        Shared.println("TrapListener", "Variable OID: " + variable.getOid().toString());
//                        controller.trapReceived(sourceAddress, variable);
//                    }
//                    catch (Exception e)
//                    {
//                    }
//                }
            }
            catch (Exception exception)
            {
                
            }
        }
    } 
 
}