📄 networkdiscovery.java
字号:
swrec.put("portnavn", null); swrec.put("boksbak", boksbak.toString()); swrec.put("static", "t"); if (vlan != null) { swrec.put("change", "Inserted ("+vlan+")"); } else { swrec.put("change", "Error, vlan is null"); } swport.add(swrec); //swrecMap.put(key, swrec); } */ } if (DEBUG_OUT) outl("boksMp listing done.<br>"); iter = swrecMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry me = (Map.Entry)iter.next(); String key = (String)me.getKey(); HashMap swrec = (HashMap)me.getValue(); String swportid = (String)swrec.get("swportid"); String boksbak = (String)swrec.get("to_netboxid"); String swportbak = (String)swrec.get("to_swportid"); if (swportbak != null && swportbak.length() > 0) { boolean reset = false; if (boksbak == null || boksbak.length() == 0) { reset = true; } else { Map swrecBak = (Map)swrecSwportidMap.get(swportbak); if (swrecBak == null || !boksbak.equals(swrecBak.get("netboxid"))) { reset = true; } } if (reset) { resetcnt++; // Sett felter til null String[] updateFields = { "to_swportid", "null" }; String[] condFields = { "swportid", swportid }; Database.update("swport", updateFields, condFields); if (DEBUG_OUT) outl("Want to reset swportbak(2) for swportid: " + swportid + "<br>"); swportbak = null; } } if (swrec.containsKey("deleted")) continue; if (boksbak != null && boksbak.length() > 0) { // Sett til null resetcnt++; String[] updateFields = { "to_netboxid", "null", "to_swportid", "null" }; String[] condFields = { "swportid", swportid }; Database.update("swport", updateFields, condFields); if (DEBUG_OUT) outl("Want to reset boksbak for swportid: " + swportid + "<br>"); } else if (swportbak != null && swportbak.length() > 0) { // Sett felter til null resetcnt++; String[] updateFields = { "to_swportid", "null" }; String[] condFields = { "swportid", swportid }; Database.update("swport", updateFields, condFields); if (DEBUG_OUT) outl("Want to reset swportbak for swportid: " + swportid + "<br>"); } } /* iter = swrecMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry me = (Map.Entry)iter.next(); String key = (String)me.getKey(); HashMap swrec = (HashMap)me.getValue(); //if (!swrec.get("static").equals("t")) continue; if (swrec.containsKey("deleted")) continue; remcnt++; StringTokenizer st = new StringTokenizer(key, ":"); String boksid = st.nextToken(); String modul = st.nextToken(); String port = st.nextToken(); String swportid = (String)swrec.get("swportid"); // boksbak_s kan egentlig ikke være null, men for sikkerhets skyld String boksbak_s = (String)swrec.get("boksbak"); Integer boksbak = (boksbak_s == null) ? new Integer(0-1) : new Integer((String)swrec.get("boksbak")); //Database.update("DELETE FROM swport WHERE swportid='"+swportid+"'"); if (DEBUG_OUT) outl("[DELETED] swportid: <b>"+swportid+"</b> sysName: <b>" + boksNavn.get(new Integer(boksid)) + "</b> Modul: <b>" + modul + "</b> Port: <b>" + port + "</b> Link: <b>" + boksNavn.get(boksbak) + "</b><br>"); } */ outl("<table>"); outl(" <tr>"); outl(" <td><b>swpid</b></td>"); outl(" <td><b>boksid</b></td>"); outl(" <td><b>sysName</b></td>"); outl(" <td><b>typeId</b></td>"); outl(" <td><b>Speed</b></td>"); outl(" <td><b>Duplex</b></td>"); outl(" <td><b>Ifindex</b></td>"); outl(" <td><b>Portnavn</b></td>"); outl(" <td><b>Boksbak</b></td>"); outl(" <td><b>Change (vlan)</b></td>"); outl(" </tr>"); int attCnt=0; for (int i=0; i < swport.size(); i++) { HashMap swrec = (HashMap)swport.get(i); String boksid = (String)swrec.get("netboxid"); String ifindex = (String)swrec.get("ifindex"); String portnavn = (String)swrec.get("portname"); //boolean isStatic = swrec.get("static").equals("t"); String change = (String)swrec.get("change"); if (portnavn == null) portnavn = ""; String boksbak = ""; //Integer idbak = (Integer)boksMp.get(boksid+":"+modul+":"+port); BoksMpBak bmp = (BoksMpBak)boksMp.get(boksid+":"+ifindex); Integer idbak = (bmp != null) ? bmp.boksbak : null; if (idbak != null) boksbak = (String)boksNavn.get(idbak); if (boksbak == null) { outl("ERROR! boksbak is null for idbak: " + idbak + "<br>"); continue; } String color = "gray"; if (change != null && change.startsWith("Error")) { color = "red"; } else if (portnavn.length() == 0 && boksbak.length()>0) { color = "blue"; } else if (portnavn.length() > 0 && boksbak.length()==0) { if (portnavn.indexOf("-h") != -1 || portnavn.indexOf("-sw") != -1 || portnavn.indexOf("-gw") != -1) { color = "purple"; } } else if (portnavn.length() > 0 && boksbak.length()>0 && portnavn.endsWith(boksbak) ) { color = "green"; } else if (portnavn.length() > 0 && boksbak.length()>0 && !portnavn.endsWith(boksbak) ) { color = "red"; } if (!color.equals("purple") && !color.equals("red")) continue; if (portnavn.length() > 2 && portnavn.charAt(0) == 'n' && portnavn.charAt(2) == ':') continue; attCnt++; String color1 = "<font color="+color+">"; String color2 = "</font>"; outl("<tr>"); //outl("<td align=right>"+color1+ swrec.get("swportid") + color2+"</td>"); outl("<td align=right><a href=\"#" + swrec.get("swportid") + "\">" + swrec.get("swportid") + "</a></td>"); outl("<td align=right>"+color1+ swrec.get("netboxid") + color2+"</td>"); outl("<td>"+color1+ boksNavn.get(new Integer((String)swrec.get("netboxid"))) + color2+"</td>"); outl("<td>"+color1+ boksType.get(new Integer((String)swrec.get("netboxid"))) + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("speed") + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("duplex") + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("ifindex") + color2+"</td>"); outl("<td>"+color1+ portnavn + color2+"</td>"); outl("<td>"+color1+ boksbak + color2+"</td>"); if (change != null) outl("<td><b>"+change+"</b></td>"); outl("</tr>"); } outl("</table>"); outl("Found <b>" + attCnt + "</b> rows in need of attention.<br>"); outl("<h2>swport:</h2>"); outl("<table>"); outl(" <tr>"); outl(" <td><b>swpid</b></td>"); outl(" <td><b>boksid</b></td>"); outl(" <td><b>sysName</b></td>"); outl(" <td><b>Speed</b></td>"); outl(" <td><b>Duplex</b></td>"); outl(" <td><b>Ifindex</b></td>"); outl(" <td><b>Portnavn</b></td>"); outl(" <td><b>Boksbak</b></td>"); outl(" <td><b>Change (vlan)</b></td>"); outl(" </tr>"); for (int i=0; i < swport.size(); i++) { HashMap swrec = (HashMap)swport.get(i); String boksid = (String)swrec.get("netboxid"); String ifindex = (String)swrec.get("ifindex"); String portnavn = (String)swrec.get("portname"); //boolean isStatic = swrec.get("static").equals("t"); String change = (String)swrec.get("change"); if (portnavn == null) portnavn = ""; String boksbak = ""; BoksMpBak bmp = (BoksMpBak)boksMp.get(boksid+":"+ifindex); Integer idbak = (bmp != null) ? bmp.boksbak : null; if (idbak != null) boksbak = (String)boksNavn.get(idbak); if (boksbak == null) { outl("ERROR! boksbak is null for idbak: " + idbak + "<br>"); continue; } // På grunn av altfor stort volum tas ikke KANT-bokser med tomt portnavn og boksbak med i listen if (boksKat.get(new Integer(boksid)) == null) { System.err.println("ERROR, boksKat is null for boksid: " + boksid); continue; } if (((String)boksKat.get(new Integer(boksid))).equalsIgnoreCase("edge") && portnavn.length() == 0 && boksbak.length() == 0) continue; String color = "gray"; if (change != null && change.startsWith("Error")) { color = "red"; } else if (portnavn.length() == 0 && boksbak.length()>0) { color = "blue"; } else if (portnavn.length() > 0 && boksbak.length()==0) { if (portnavn.indexOf("-h") != -1 || portnavn.indexOf("-sw") != -1 || portnavn.indexOf("-gw") != -1) { color = "purple"; } } else if (portnavn.length() > 0 && boksbak.length()>0 && portnavn.endsWith(boksbak) ) { color = "green"; } else if (portnavn.length() > 0 && boksbak.length()>0 && !portnavn.endsWith(boksbak) ) { color = "red"; } String color1 = "<font color="+color+">"; String color2 = "</font>"; outl("<tr><a name=\"" + swrec.get("swportid") + "\">"); outl("<td align=right>"+color1+ swrec.get("swportid") + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("netboxid") + color2+"</td>"); outl("<td>"+color1+ boksNavn.get(new Integer((String)swrec.get("netboxid"))) + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("speed") + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("duplex") + color2+"</td>"); outl("<td align=right>"+color1+ swrec.get("ifindex") + color2+"</td>"); outl("<td>"+color1+ portnavn + color2+"</td>"); outl("<td>"+color1+ boksbak + color2+"</td>"); if (change != null) outl("<td><b>"+change+"</b></td>"); outl("</tr>"); } outl("</table>"); //outl("New rows: <b>" + newcnt + "</b> Updated rows: <b>" + updcnt + "</b> Removed rows: <b>"+remcnt+"</b><br>"); outl("New rows: <b>" + newcnt + "</b> Updated rows: <b>" + updcnt + "</b><br>"); outl("Sum rows: <b>" + swport.size() + "</b><br>"); /* if (newcnt > 0 || updcnt > 0 || resetcnt > 0) { if (DEBUG_OUT) outl("** COMMIT ON DATABASE **<br>"); Database.commit(); } */ //Database.rollback(); outl("All done.<br>"); } private HashMap getHashFromResultSet(ResultSet rs, ResultSetMetaData md) throws SQLException { HashMap hm = new HashMap(); for (int i=md.getColumnCount(); i > 0; i--) { hm.put(md.getColumnName(i), rs.getString(i)); } return hm; } /* [/ni.avledVlan] * */ public void avledVlan() throws SQLException { boolean DB_UPDATE = true; boolean DB_COMMIT = true; boolean DEBUG_OUT = false; boolean TIME_OUT = true; long beginTime; //String debugParam = com.getp("debug"); if (debugParam != null && debugParam.equals("yes")) DEBUG_OUT = true; if (DEBUG_OUT) outl("Begin<br>"); // Vis dato { java.util.Date currentTime = new GregorianCalendar().getTime(); outl("Generated on: <b>" + currentTime + "</b><br>"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -