Commits

stingh711 committed 24524ec

add ip change trap:

  • Participants
  • Parent commits b0d84c0

Comments (0)

Files changed (3)

File c.properties

-agent.ip=172.25.21.16
+agent.ip=172.25.21.42
 
 mac=00:a0:c5:00:00:11
-cpu.usage=60
-mem.usage=60
+cpu.usage=90
+mem.usage=40
 session.active=1000
 session.max=10000
 cpu.temperature=80

File src/com/zyxel/enc/netbar/agent/Main.java

     public static void main(String[] args) {
         BasicConfigurator.configure();
 
-        if (args.length == 1 && args[0].equals("trap")) {
-            sendTraps();
+        if (args.length == 1) {
+            String command = args[0];
+            if (command.equals("trap")) {
+                sendTraps();
+            } else if (command.equals("change")) {
+                sendIpChangeTrap();
+            }
         } else {
             startAgent();
         }
+        
     }
 
     private static void sendTraps() {
         TrapSender sender = new TrapSender(Config.get("server.ip"));
         sender.sendAllTraps();
     }
+    
+    private static void sendIpChangeTrap() {
+        TrapSender sender = new TrapSender(Config.get("server.ip"));
+        sender.sendIpChangeTrap();
+    }
 
     private static void startAgent() {
         Agent agent = new Agent(Config.get("agent.ip") + "/161");

File src/com/zyxel/enc/netbar/agent/TrapSender.java

     private static final OID nsTrapVarAttackCount = new OID("1.3.6.1.4.1.890.1.5.17.1.12.3.8");
     private static final OID nsTrapVarAttackRate = new OID("1.3.6.1.4.1.890.1.5.17.1.12.3.9");
     private static final OID nsTrapVarAttackTime = new OID("1.3.6.1.4.1.890.1.5.17.1.12.3.10");
+    private static final OID nsTrapVarIp = new OID("1.3.6.1.4.1.890.1.5.17.1.12.3.11");
+    
+    private static final OID nsTrapWanIpChange = new OID("1.3.6.1.4.1.890.1.5.17.1.12.2.28");
 
     private static final Map<OID, VariableAdder> variableAdders = new HashMap<OID, VariableAdder>();
 
                 pdu.add(new VariableBinding(nsTrapVarPort, new Integer32(Integer.valueOf(Config.get("nsTrapVarPort")))));
             }
         });
+        variableAdders.put(nsTrapWanIpChange, new VariableAdder() {
+            @Override
+            public void addVariableToPdu(PDU pdu) {
+                pdu.add(new VariableBinding(nsTrapVarPort, new Integer32(1)));
+                pdu.add(new VariableBinding(nsTrapVarIp, new OctetString(Config.get("agent.ip"))));
+            }
+        });
     }
 
     private Snmp snmp;
         }
         logger.info("All traps has been sent out");
     }
+    
+    public void sendIpChangeTrap() {
+        logger.info("Begin to send IP change trap");;
+        logger.info("Agent IP is changed to " + Config.get("agent.ip"));
+        sendV2Trap(nsTrapWanIpChange);
+        logger.info("IP change trap has been sent out");
+    }
 
     public static void main(String[] args) throws Exception {
         TrapSender sender = new TrapSender("172.25.21.69");