[opennms-devel] [PATCH] [RANCID] Fallback to IP when searching for RancidNode
Philippe Guillebert <[email protected]> Fri, 29 May 2009 10:29:15 +0200
| Newsgroups | gmane.network.opennms.bugs,gmane.network.opennms.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------070200040102000705040501
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Hi
We've got a little issue with the current Rancid integration : our=20
nodeLabels are arbitrary (not ip, not DNS names). So, in our Rancid=20
configuration (router.db), we use primary IP addresses as names.
And, with the current SVN HEAD, InventoryService uses nodeLabel and=20
supposes it's the name in router.db.
This patches adds a fallback : when the node cannot be found by label,=20
it tries to use primaryInterface or the first interface it finds.
It's tested and works for me ;)
I'm puzzled about :
OnmsIpInterface primaryInterface =3D node.getPrimaryInterface();
It should give me the primaryInterface, but doesn't, even for nodes=20
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 (=20
getSuitableIpForRancid() ) and that's why, in the patch, I get all=20
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=20
the alps :)
Have a nice day
--=20
Philippe Guillebert
Bull, Architect of an Open World
T=E9l : +33 (0)1 30 80 61 81
http://www.bull.com
--------------070200040102000705040501
Content-Transfer-Encoding: 7bit
Content-Type: text/x-patch;
name="Rancid_Primary_IP_fallback.patch"
Content-Disposition: inline;
filename="Rancid_Primary_IP_fallback.patch"
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)));
--------------070200040102000705040501
Content-Transfer-Encoding: 7bit
Content-Type: text/x-vcard; charset=utf-8;
name="philippe_guillebert.vcf"
Content-Disposition: attachment;
filename="philippe_guillebert.vcf"
begin:vcard
fn:Philippe Guillebert
n:Guillebert;Philippe
org:Bull Telecom & Media;Operation Support Systems
email;internet:[email protected]
title:SmartOSS Technical Manager
tel;work:+33 1 30 80 61 81
version:2.1
end:vcard
--------------070200040102000705040501
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
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
--------------070200040102000705040501
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
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
--------------070200040102000705040501--