Commits

stingh711 committed e3a18a9

change index to query switch

Comments (0)

Files changed (5)

-agent.ip=172.25.21.16
+agent.ip=172.25.21.36
 
 mac=00:a0:c5:00:00:11
 cpu.usage=90
 
 #switch QS info data
 switch.number = 1
-switch.1.ip=192.168.1.33
+switch.1.mac=00:a0:c5:00:00:33
 switch.1.cpu.usage=10
 switch.1.mem.usage=30
 switch.1.broadcast.rate=10
 switch.1.voltage=15
 switch.1.cpu.temperature=70
 
-switch.192.168.1.33.interface.1.mac=00:13:49:11:11:01
-switch.192.168.1.33.interface.1.in=9859485
-switch.192.168.1.33.interface.1.out=934
-switch.192.168.1.33.interface.2.mac=00:13:49:11:11:02
-switch.192.168.1.33.interface.2.in=0
-switch.192.168.1.33.interface.2.out=0
-switch.192.168.1.33.interface.3.mac=00:13:49:11:11:03
-switch.192.168.1.33.interface.3.in=0
-switch.192.168.1.33.interface.3.out=0
-switch.192.168.1.33.interface.4.mac=00:13:49:11:11:04
-switch.192.168.1.33.interface.4.in=0
-switch.192.168.1.33.interface.4.out=0
-switch.192.168.1.33.interface.5.mac=00:13:49:11:11:05
-switch.192.168.1.33.interface.5.in=0
-switch.192.168.1.33.interface.5.out=0
-switch.192.168.1.33.interface.6.mac=00:13:49:11:11:06
-switch.192.168.1.33.interface.6.in=0
-switch.192.168.1.33.interface.6.out=0
-switch.192.168.1.33.interface.7.mac=00:13:49:11:11:07
-switch.192.168.1.33.interface.7.in=0
-switch.192.168.1.33.interface.7.out=0
-switch.192.168.1.33.interface.8.mac=00:13:49:11:11:08
-switch.192.168.1.33.interface.8.in=0
-switch.192.168.1.33.interface.8.out=0
-switch.192.168.1.33.interface.9.mac=00:13:49:11:11:09
-switch.192.168.1.33.interface.9.in=0
-switch.192.168.1.33.interface.9.out=0
-switch.192.168.1.33.interface.10.mac=00:13:49:11:11:0a
-switch.192.168.1.33.interface.10.in=0
-switch.192.168.1.33.interface.10.out=0
-switch.192.168.1.33.interface.11.mac=00:13:49:11:11:0b
-switch.192.168.1.33.interface.11.in=0
-switch.192.168.1.33.interface.11.out=0
-switch.192.168.1.33.interface.12.mac=00:13:49:11:11:0c
-switch.192.168.1.33.interface.12.in=0
-switch.192.168.1.33.interface.12.out=0
-switch.192.168.1.33.interface.13.mac=00:13:49:11:11:0d
-switch.192.168.1.33.interface.13.in=0
-switch.192.168.1.33.interface.13.out=0
-switch.192.168.1.33.interface.14.mac=00:13:49:11:11:0e
-switch.192.168.1.33.interface.14.in=0
-switch.192.168.1.33.interface.14.out=0
-switch.192.168.1.33.interface.15.mac=00:13:49:11:11:0f
-switch.192.168.1.33.interface.15.in=0
-switch.192.168.1.33.interface.15.out=0
-switch.192.168.1.33.interface.16.mac=00:13:49:11:11:10
-switch.192.168.1.33.interface.16.in=0
-switch.192.168.1.33.interface.16.out=0
-switch.192.168.1.33.interface.17.mac=00:13:49:11:11:11
-switch.192.168.1.33.interface.17.in=0
-switch.192.168.1.33.interface.17.out=0
-switch.192.168.1.33.interface.18.mac=00:13:49:11:11:12
-switch.192.168.1.33.interface.18.in=0
-switch.192.168.1.33.interface.18.out=0
-switch.192.168.1.33.interface.19.mac=00:13:49:11:11:13
-switch.192.168.1.33.interface.19.in=0
-switch.192.168.1.33.interface.19.out=0
-switch.192.168.1.33.interface.20.mac=00:13:49:11:11:14
-switch.192.168.1.33.interface.20.in=0
-switch.192.168.1.33.interface.20.out=0
-switch.192.168.1.33.interface.21.mac=00:13:49:11:11:15
-switch.192.168.1.33.interface.21.in=0
-switch.192.168.1.33.interface.21.out=0
-switch.192.168.1.33.interface.22.mac=00:13:49:11:11:16
-switch.192.168.1.33.interface.22.in=0
-switch.192.168.1.33.interface.22.out=0
-switch.192.168.1.33.interface.23.mac=00:13:49:11:11:17
-switch.192.168.1.33.interface.23.in=0
-switch.192.168.1.33.interface.23.out=0
-switch.192.168.1.33.interface.24.mac=00:13:49:11:11:18
-switch.192.168.1.33.interface.24.in=0
-switch.192.168.1.33.interface.24.out=0
-switch.192.168.1.33.interface.25.mac=00:13:49:11:11:19
-switch.192.168.1.33.interface.25.in=0
-switch.192.168.1.33.interface.25.out=0
-switch.192.168.1.33.interface.26.mac=00:13:49:11:11:1a
-switch.192.168.1.33.interface.26.in=0
-switch.192.168.1.33.interface.26.out=0
-switch.192.168.1.33.interface.27.mac=00:13:49:11:11:1b
-switch.192.168.1.33.interface.27.in=0
-switch.192.168.1.33.interface.27.out=0
-switch.192.168.1.33.interface.28.mac=00:13:49:11:11:1c
-switch.192.168.1.33.interface.28.in=0
-switch.192.168.1.33.interface.28.out=0
-switch.192.168.1.33.interface.29.mac=00:13:49:11:11:1d
-switch.192.168.1.33.interface.29.in=0
-switch.192.168.1.33.interface.29.out=0
-switch.192.168.1.33.interface.30.mac=00:13:49:11:11:1e
-switch.192.168.1.33.interface.30.in=0
-switch.192.168.1.33.interface.30.out=0
-switch.192.168.1.33.interface.31.mac=00:13:49:11:11:1f
-switch.192.168.1.33.interface.31.in=0
-switch.192.168.1.33.interface.31.out=0
-switch.192.168.1.33.interface.32.mac=00:13:49:11:11:20
-switch.192.168.1.33.interface.32.in=0
-switch.192.168.1.33.interface.32.out=0
-switch.192.168.1.33.interface.33.mac=00:13:49:11:11:21
-switch.192.168.1.33.interface.33.in=0
-switch.192.168.1.33.interface.33.out=0
-switch.192.168.1.33.interface.34.mac=00:13:49:11:11:22
-switch.192.168.1.33.interface.34.in=0
-switch.192.168.1.33.interface.34.out=0
-switch.192.168.1.33.interface.35.mac=00:13:49:11:11:23
-switch.192.168.1.33.interface.35.in=0
-switch.192.168.1.33.interface.35.out=0
-switch.192.168.1.33.interface.36.mac=00:13:49:11:11:24
-switch.192.168.1.33.interface.36.in=0
-switch.192.168.1.33.interface.36.out=0
-switch.192.168.1.33.interface.37.mac=00:13:49:11:11:25
-switch.192.168.1.33.interface.37.in=0
-switch.192.168.1.33.interface.37.out=0
-switch.192.168.1.33.interface.38.mac=00:13:49:11:11:26
-switch.192.168.1.33.interface.38.in=0
-switch.192.168.1.33.interface.38.out=0
-switch.192.168.1.33.interface.39.mac=00:13:49:11:11:27
-switch.192.168.1.33.interface.39.in=0
-switch.192.168.1.33.interface.39.out=0
-switch.192.168.1.33.interface.40.mac=00:13:49:11:11:28
-switch.192.168.1.33.interface.40.in=0
-switch.192.168.1.33.interface.40.out=0
-switch.192.168.1.33.interface.41.mac=00:13:49:11:11:29
-switch.192.168.1.33.interface.41.in=0
-switch.192.168.1.33.interface.41.out=0
-switch.192.168.1.33.interface.42.mac=00:13:49:11:11:30
-switch.192.168.1.33.interface.42.in=0
-switch.192.168.1.33.interface.42.out=0
-switch.192.168.1.33.interface.43.mac=00:13:49:11:11:31
-switch.192.168.1.33.interface.43.in=0
-switch.192.168.1.33.interface.43.out=0
-switch.192.168.1.33.interface.44.mac=00:13:49:11:11:32
-switch.192.168.1.33.interface.44.in=0
-switch.192.168.1.33.interface.44.out=0
-switch.192.168.1.33.interface.45.mac=00:13:49:11:11:33
-switch.192.168.1.33.interface.45.in=0
-switch.192.168.1.33.interface.45.out=0
-switch.192.168.1.33.interface.46.mac=00:13:49:11:11:34
-switch.192.168.1.33.interface.46.in=0
-switch.192.168.1.33.interface.46.out=0
-switch.192.168.1.33.interface.47.mac=00:13:49:11:11:35
-switch.192.168.1.33.interface.47.in=0
-switch.192.168.1.33.interface.47.out=0
-switch.192.168.1.33.interface.48.mac=00:13:49:11:11:36
-switch.192.168.1.33.interface.48.in=0
-switch.192.168.1.33.interface.48.out=0
+switch.1.interface.1.mac=00:13:49:11:11:01
+switch.1.interface.1.in=9859485
+switch.1.interface.1.out=934
+switch.1.interface.2.mac=00:13:49:11:11:02
+switch.1.interface.2.in=0
+switch.1.interface.2.out=0
+switch.1.interface.3.mac=00:13:49:11:11:03
+switch.1.interface.3.in=0
+switch.1.interface.3.out=0
+switch.1.interface.4.mac=00:13:49:11:11:04
+switch.1.interface.4.in=0
+switch.1.interface.4.out=0
+switch.1.interface.5.mac=00:13:49:11:11:05
+switch.1.interface.5.in=0
+switch.1.interface.5.out=0
+switch.1.interface.6.mac=00:13:49:11:11:06
+switch.1.interface.6.in=0
+switch.1.interface.6.out=0
+switch.1.interface.7.mac=00:13:49:11:11:07
+switch.1.interface.7.in=0
+switch.1.interface.7.out=0
+switch.1.interface.8.mac=00:13:49:11:11:08
+switch.1.interface.8.in=0
+switch.1.interface.8.out=0
+switch.1.interface.9.mac=00:13:49:11:11:09
+switch.1.interface.9.in=0
+switch.1.interface.9.out=0
+switch.1.interface.10.mac=00:13:49:11:11:0a
+switch.1.interface.10.in=0
+switch.1.interface.10.out=0
+switch.1.interface.11.mac=00:13:49:11:11:0b
+switch.1.interface.11.in=0
+switch.1.interface.11.out=0
+switch.1.interface.12.mac=00:13:49:11:11:0c
+switch.1.interface.12.in=0
+switch.1.interface.12.out=0
+switch.1.interface.13.mac=00:13:49:11:11:0d
+switch.1.interface.13.in=0
+switch.1.interface.13.out=0
+switch.1.interface.14.mac=00:13:49:11:11:0e
+switch.1.interface.14.in=0
+switch.1.interface.14.out=0
+switch.1.interface.15.mac=00:13:49:11:11:0f
+switch.1.interface.15.in=0
+switch.1.interface.15.out=0
+switch.1.interface.16.mac=00:13:49:11:11:10
+switch.1.interface.16.in=0
+switch.1.interface.16.out=0
+switch.1.interface.17.mac=00:13:49:11:11:11
+switch.1.interface.17.in=0
+switch.1.interface.17.out=0
+switch.1.interface.18.mac=00:13:49:11:11:12
+switch.1.interface.18.in=0
+switch.1.interface.18.out=0
+switch.1.interface.19.mac=00:13:49:11:11:13
+switch.1.interface.19.in=0
+switch.1.interface.19.out=0
+switch.1.interface.20.mac=00:13:49:11:11:14
+switch.1.interface.20.in=0
+switch.1.interface.20.out=0
+switch.1.interface.21.mac=00:13:49:11:11:15
+switch.1.interface.21.in=0
+switch.1.interface.21.out=0
+switch.1.interface.22.mac=00:13:49:11:11:16
+switch.1.interface.22.in=0
+switch.1.interface.22.out=0
+switch.1.interface.23.mac=00:13:49:11:11:17
+switch.1.interface.23.in=0
+switch.1.interface.23.out=0
+switch.1.interface.24.mac=00:13:49:11:11:18
+switch.1.interface.24.in=0
+switch.1.interface.24.out=0
+switch.1.interface.25.mac=00:13:49:11:11:19
+switch.1.interface.25.in=0
+switch.1.interface.25.out=0
+switch.1.interface.26.mac=00:13:49:11:11:1a
+switch.1.interface.26.in=0
+switch.1.interface.26.out=0
+switch.1.interface.27.mac=00:13:49:11:11:1b
+switch.1.interface.27.in=0
+switch.1.interface.27.out=0
+switch.1.interface.28.mac=00:13:49:11:11:1c
+switch.1.interface.28.in=0
+switch.1.interface.28.out=0
+switch.1.interface.29.mac=00:13:49:11:11:1d
+switch.1.interface.29.in=0
+switch.1.interface.29.out=0
+switch.1.interface.30.mac=00:13:49:11:11:1e
+switch.1.interface.30.in=0
+switch.1.interface.30.out=0
+switch.1.interface.31.mac=00:13:49:11:11:1f
+switch.1.interface.31.in=0
+switch.1.interface.31.out=0
+switch.1.interface.32.mac=00:13:49:11:11:20
+switch.1.interface.32.in=0
+switch.1.interface.32.out=0
+switch.1.interface.33.mac=00:13:49:11:11:21
+switch.1.interface.33.in=0
+switch.1.interface.33.out=0
+switch.1.interface.34.mac=00:13:49:11:11:22
+switch.1.interface.34.in=0
+switch.1.interface.34.out=0
+switch.1.interface.35.mac=00:13:49:11:11:23
+switch.1.interface.35.in=0
+switch.1.interface.35.out=0
+switch.1.interface.36.mac=00:13:49:11:11:24
+switch.1.interface.36.in=0
+switch.1.interface.36.out=0
+switch.1.interface.37.mac=00:13:49:11:11:25
+switch.1.interface.37.in=0
+switch.1.interface.37.out=0
+switch.1.interface.38.mac=00:13:49:11:11:26
+switch.1.interface.38.in=0
+switch.1.interface.38.out=0
+switch.1.interface.39.mac=00:13:49:11:11:27
+switch.1.interface.39.in=0
+switch.1.interface.39.out=0
+switch.1.interface.40.mac=00:13:49:11:11:28
+switch.1.interface.40.in=0
+switch.1.interface.40.out=0
+switch.1.interface.41.mac=00:13:49:11:11:29
+switch.1.interface.41.in=0
+switch.1.interface.41.out=0
+switch.1.interface.42.mac=00:13:49:11:11:30
+switch.1.interface.42.in=0
+switch.1.interface.42.out=0
+switch.1.interface.43.mac=00:13:49:11:11:31
+switch.1.interface.43.in=0
+switch.1.interface.43.out=0
+switch.1.interface.44.mac=00:13:49:11:11:32
+switch.1.interface.44.in=0
+switch.1.interface.44.out=0
+switch.1.interface.45.mac=00:13:49:11:11:33
+switch.1.interface.45.in=0
+switch.1.interface.45.out=0
+switch.1.interface.46.mac=00:13:49:11:11:34
+switch.1.interface.46.in=0
+switch.1.interface.46.out=0
+switch.1.interface.47.mac=00:13:49:11:11:35
+switch.1.interface.47.in=0
+switch.1.interface.47.out=0
+switch.1.interface.48.mac=00:13:49:11:11:36
+switch.1.interface.48.in=0
+switch.1.interface.48.out=0
 
 app.statistics.10mins.number=7
 app.statistics.10mins.name.1=1

src/com/zyxel/enc/netbar/agent/SwitchDataHelper.java

         int number = Integer.parseInt(Config.get("switch.number"));
         for (int i = 1; i <= number; i++) {
             String prefix = "switch." + i + ".";
-            String ip = Config.get(prefix + "ip");
-            OID cpuUsageOid = new OID(cpuUsageOidPrefix + ip);
+            String mac = Config.get(prefix + "mac");
+            String index = Utils.convertMacToOid(mac);
+            OID cpuUsageOid = new OID(cpuUsageOidPrefix + index);
             server.register(MOCreator.createReadOnly(cpuUsageOid, Config.getInt(prefix + "cpu.usage")), context);
-            OID memUsageOid = new OID(memUsageOidPrefix + ip);
+            OID memUsageOid = new OID(memUsageOidPrefix + index);
             server.register(MOCreator.createReadOnly(memUsageOid, Config.getInt(prefix + "mem.usage")), context);
-            OID broadcastRateOid = new OID(broadcastRateOidPrefix + ip);
+            OID broadcastRateOid = new OID(broadcastRateOidPrefix + index);
             server.register(MOCreator.createReadOnly(broadcastRateOid, Config.getInt(prefix + "broadcast.rate")), context);
-            OID voltageOid = new OID(voltageOidPrefix + ip);
+            OID voltageOid = new OID(voltageOidPrefix + index);
             server.register(MOCreator.createReadOnly(voltageOid, Config.getInt(prefix + "voltage")), context);
-            OID cpuTemperature = new OID(cpuTemperatureOidPrefix + ip);
+            OID cpuTemperature = new OID(cpuTemperatureOidPrefix + index);
             server.register(MOCreator.createReadOnly(cpuTemperature, Config.getInt(prefix + "cpu.temperature")), context);
 
-            OID sysUpTimeOid = new OID(sysUptimeOidPrefix + ip);
+            OID sysUpTimeOid = new OID(sysUptimeOidPrefix + index);
             server.register(MOCreator.createTimeTicks(sysUpTimeOid, NRrouterMib.getStartTime()), context);
 
-            OID sysDateTimeOid = new OID(sysDateTimeOidPrefix + ip);
+            OID sysDateTimeOid = new OID(sysDateTimeOidPrefix + index);
             server.register(new DateAndTimeScalar(sysDateTimeOid, MOAccessImpl.ACCESS_READ_ONLY, new OctetString(NRrouterMib.getCurrentTimeAsString())), context);
         }
     }
+    
+    
+    
+    public static void main(String[] args) {
+    }
 }

src/com/zyxel/enc/netbar/agent/Utils.java

+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.zyxel.enc.netbar.agent;
+
+/**
+ *
+ * @author sting
+ */
+public class Utils {
+    public static String convertMacToOid(String mac) {
+        String[] subs = mac.split(":");
+        StringBuilder sb = new StringBuilder();
+
+        for (int i = 0; i < subs.length; i++) {
+            String s = subs[i];
+            sb.append(Integer.parseInt(s, 16));
+            if (i != subs.length - 1) {
+                sb.append(".");
+            }
+        }
+        
+        return sb.toString();
+    }
+}

src/com/zyxel/enc/netbar/agent/data/Switch.java

  * @author sting
  */
 public class Switch {
-    public static List<SwitchInterface> buildInterfaces(int portNumber, String ip) {
+    public static List<SwitchInterface> buildInterfaces(int portNumber, int number) {
         List<SwitchInterface> result = new ArrayList<SwitchInterface>();
         for (int i = 1; i <= portNumber; i++) {
-            String prefix = "switch." + ip + ".interface." + i + ".";
+            String prefix = "switch." + number + ".interface." + i + ".";
             SwitchInterface in = new SwitchInterface();
             in.index = i;
             in.description = "port" + i;
     public List<SwitchInterface> interfaces;
 
     public static void main(String[] args) {
-        List<SwitchInterface> ins = buildInterfaces(48, "192.168.1.33");
+        List<SwitchInterface> ins = buildInterfaces(48, 1);
         System.out.println(ins);
     }
 }

src/com/zyxel/enc/netbar/agent/generator/SwitchInterfaceTableGenerator.java

 import org.snmp4j.smi.Variable;
 
 import com.zyxel.enc.netbar.agent.AbstractTableGenerator;
+import com.zyxel.enc.netbar.agent.Utils;
 import com.zyxel.enc.netbar.agent.data.Config;
 import com.zyxel.enc.netbar.agent.data.Switch;
 import com.zyxel.enc.netbar.agent.data.SwitchInterface;
         int number = Config.getInt("switch.number");
         for (int i = 1; i <= number; i++) {
             int portNumber = Config.getInt("device." + i + ".portnumber");
-            String ip = Config.get("device." + i + ".ip");
-            List<SwitchInterface> list = Switch.buildInterfaces(portNumber, ip);
+            List<SwitchInterface> list = Switch.buildInterfaces(portNumber, i);
+            String mac = Config.get("switch." + i + ".mac");
             for (int j = 1; j <= list.size(); j++) {
                 SwitchInterface in = list.get(j-1);
                 Variable[] v = new Variable[]{
                     new Counter32(in.in),
                     new Counter32(in.out)
                 };
-                model.addRow(new DefaultMOMutableRow2PC(new OID(ip + "." + j), v));
+                String index = Utils.convertMacToOid(mac);
+                model.addRow(new DefaultMOMutableRow2PC(new OID(index + "." + j), v));
             }
         }
     }