From: Antonio R. <rss...@ya...> - 2009-06-20 10:17:35
|
Philippe there was an issue in getPrimaryInterface, now is fixed. Regards Antonio Il giorno 29/mag/09, alle ore 10:29, Philippe Guillebert ha scritto: > Hi > > We've got a little issue with the current Rancid integration : our > nodeLabels are arbitrary (not ip, not DNS names). So, in our Rancid > configuration (router.db), we use primary IP addresses as names. > > And, with the current SVN HEAD, InventoryService uses nodeLabel and > supposes it's the name in router.db. > > This patches adds a fallback : when the node cannot be found by > label, it tries to use primaryInterface or the first interface it > finds. > > It's tested and works for me ;) > > I'm puzzled about : > OnmsIpInterface primaryInterface = node.getPrimaryInterface(); > > It should give me the primaryInterface, but doesn't, even for nodes > where there is a 'P' in the column issnmpprimary in the ipinterface > table. > > Am I getting the primary interface concept right ? > > So I borrowed code from another function in > RancidProvisioningAdapter ( getSuitableIpForRancid() ) and that's > why, in the patch, I get all interfaces and pick the first. Not very > elegant, but it works. > > I hope this will be integrated in SVN by our friends the other side > of the alps :) > > Have a nice day > > -- > Philippe Guillebert > > Bull, Architect of an Open World > Tél : +33 (0)1 30 80 61 81 > http://www.bull.com > > Index: InventoryService.java > =================================================================== > --- InventoryService.java (revision 13486) > +++ InventoryService.java (working copy) > @@ -4,6 +4,7 @@ > import java.util.Iterator; > import java.util.List; > import java.util.Map; > +import java.util.Set; > import java.util.TreeMap; > > import org.apache.log4j.Category; > @@ -11,6 +12,7 @@ > import org.opennms.core.resource.Vault; > import org.opennms.netmgt.config.RWSConfig; > import org.opennms.netmgt.dao.NodeDao; > +import org.opennms.netmgt.model.OnmsIpInterface; > import org.opennms.netmgt.model.OnmsNode; > import org.opennms.rancid.ConnectionProperties; > import org.opennms.rancid.InventoryElement2; > @@ -114,11 +116,46 @@ > > nodeModel.put("RWSStatus","OK"); > OnmsNode node = m_nodeDao.get(nodeid); > - String rancidName = node.getLabel(); > + String rancidName; > > + log().debug("getRancidNodeBase rancid node name search..."); > + > + // Test if node label is known in Rancid > + if(checkRancidNode(node.getLabel())) { > + rancidName = node.getLabel(); > + log().debug("getRancidNodeBase rancid node name found > by label : " + rancidName); > + } > + else { > + // else, fall back to the Primary IP address if it exists > + String intf = ""; > + OnmsIpInterface primaryInterface = > node.getPrimaryInterface(); > + > + if (primaryInterface == null) { > + log().debug("getRancidNodeBase primaryIP not found"); > + Set<OnmsIpInterface> ipInterfaces = > node.getIpInterfaces(); > + for (OnmsIpInterface onmsIpInterface : > ipInterfaces) { > + log().debug("getRancidNodeBase alternate intf > found : " + onmsIpInterface.getIpAddress()); > + intf = onmsIpInterface.getIpAddress(); > + break; > + } > + } > + else { > + intf = primaryInterface.getIpAddress(); > + } > + > + if(intf != null && intf.length() > 0 && > checkRancidNode(intf)) { > + rancidName = intf; > + log().debug("getRancidNodeBase rancid node name > found by IPAddr : " + rancidName); > + } > + else { > + // TODO manage unknown nodes better ? > + rancidName = node.getLabel(); > + log().debug("getRancidNodeBase rancid node name NOT > found"); > + } > + } > + > log().debug("getRancidNodeBase rancid node name: " + > rancidName); > > - > nodeModel.put("id", rancidName); > nodeModel.put("db_id", nodeid); > nodeModel.put("status_general", > ElementUtil.getNodeStatusString(node.getType().charAt(0))); > < > philippe_guillebert > .vcf > > > ------------------------------------------------------------------------------ > Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT > is a gathering of tech-side developers & brand creativity > professionals. Meet > the minds behind Google Creative Lab, Visual Complexity, Processing, & > iPhoneDevCamp as they present alongside digital heavyweights like > Barbarian > Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com > _______________________________________________ > Please read the OpenNMS Mailing List FAQ: > http://www.opennms.org/index.php/Mailing_List_FAQ > > opennms-devel mailing list > > To *unsubscribe* or change your subscription options, see the bottom > of this page: > https://lists.sourceforge.net/lists/listinfo/opennms-devel |