From: Sasa M. <sa...@us...> - 2004-04-08 12:13:10
|
Update of /cvsroot/jrobin/src/org/jrobin/mrtg/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24435/org/jrobin/mrtg/server Modified Files: Device.java Poller.java Port.java Server.java Log Message: MRTG: Allowed for duplicate interface names found on a SNMP enabled device Index: Poller.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Poller.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Poller.java 7 Apr 2004 13:46:05 -0000 1.2 --- Poller.java 8 Apr 2004 12:00:01 -0000 1.3 *************** *** 30,36 **** import java.net.InetAddress; import java.net.SocketException; ! import java.util.Iterator; ! import java.util.Map; ! import java.util.TreeMap; class Poller { --- 30,34 ---- import java.net.InetAddress; import java.net.SocketException; ! import java.util.*; class Poller { *************** *** 115,120 **** } ! public Map walk(String base) throws IOException { ! TreeMap map = new TreeMap(); String baseOid = getNumericOid(base); String currentOid = baseOid; --- 113,118 ---- } ! public SortedMap walk(String base) throws IOException { ! SortedMap map = new TreeMap(); String baseOid = getNumericOid(base); String currentOid = baseOid; *************** *** 143,148 **** } public int getIfIndexByIfDescr(String ifDescr) throws IOException { ! Map map = walk("ifDescr"); Iterator it = map.keySet().iterator(); while(it.hasNext()) { --- 141,168 ---- } + public SortedMap walkIfDescr() throws IOException { + SortedMap rawInterfacesMap = walk("ifDescr"); + SortedMap enumeratedInterfacesMap = new TreeMap(); + Collection enumeratedInterfaces = enumeratedInterfacesMap.values(); + // check for duplicate interface names + // append integer suffix to duplicated name + Iterator iter = rawInterfacesMap.keySet().iterator(); + while(iter.hasNext()) { + Integer ifIndex = (Integer) iter.next(); + String ifDescr = (String) rawInterfacesMap.get(ifIndex); + if(enumeratedInterfaces.contains(ifDescr)) { + int ifDescrSuffix = 1; + while(enumeratedInterfaces.contains(ifDescr + "#" + ifDescrSuffix)) { + ifDescrSuffix++; + } + ifDescr += "#" + ifDescrSuffix; + } + enumeratedInterfacesMap.put(ifIndex, ifDescr); + } + return enumeratedInterfacesMap; + } + public int getIfIndexByIfDescr(String ifDescr) throws IOException { ! SortedMap map = walkIfDescr(); Iterator it = map.keySet().iterator(); while(it.hasNext()) { Index: Port.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Port.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Port.java 9 Dec 2003 12:22:04 -0000 1.1 --- Port.java 8 Apr 2004 12:00:01 -0000 1.2 *************** *** 93,96 **** --- 93,106 ---- } + String getIfDescrCore() { + int index = ifDescr.indexOf("#"); + if(index != -1) { + return ifDescr.substring(0, index); + } + else { + return ifDescr; + } + } + void setIfDescr(String ifDescr) { if(ifDescr != null) { *************** *** 180,184 **** void processSample(RawSample sample) throws MrtgException { // check if ifDescr match ! if(!ifDescr.equals(sample.getIfDescr())) { // something changed on the router switchToIfIndex(-1); --- 190,194 ---- void processSample(RawSample sample) throws MrtgException { // check if ifDescr match ! if(!getIfDescrCore().equals(sample.getIfDescr())) { // something changed on the router switchToIfIndex(-1); Index: Server.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Server.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Server.java 11 Mar 2004 13:54:26 -0000 1.9 --- Server.java 8 Apr 2004 12:00:01 -0000 1.10 *************** *** 119,122 **** --- 119,127 ---- listener.terminate(); active = false; + try { + RrdDbPool.getInstance().reset(); + } catch (IOException e) { + throw new MrtgException(e); + } } *************** *** 217,223 **** int retCode = deviceList.removeLink(host, ifDescr); saveHardware(); ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); return retCode; } --- 222,230 ---- int retCode = deviceList.removeLink(host, ifDescr); saveHardware(); ! if(retCode == 0 && REMOVE_RRD_FOR_DEACTIVATED_LINK) { ! // remove the underlying RRD file ! String rrdFile = RrdWriter.getRrdFilename(host, ifDescr); ! new File(rrdFile).delete(); ! } return retCode; } *************** *** 273,276 **** --- 280,284 ---- s.start(acceptedClients); } + } Index: Device.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/mrtg/server/Device.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Device.java 9 Dec 2003 12:22:04 -0000 1.1 --- Device.java 8 Apr 2004 12:00:01 -0000 1.2 *************** *** 158,162 **** try { comm = new Poller(host, community); ! Map links = comm.walk("ifDescr"); return (String[]) links.values().toArray(new String[0]); } --- 158,162 ---- try { comm = new Poller(host, community); ! Map links = comm.walkIfDescr(); return (String[]) links.values().toArray(new String[0]); } |