Hi All,

OpenNMS build version is 1.8.17. Modified the code where the nodeDown/nodeUp events are created, to set the interface of the device. Currently my network have only single interface devices, which we are monitoring.

I have attached the Patch please can somebody verify and tell me have anything to be changed.

*Note:* This patch will only fetch one of the interface if the device has more than one.

On 5/11/2013 7:31 PM, oreddy wrote:
Hi All,

I have tried to use the interface special value in down/up notification. I see the values are empty tried in both ways %interface% and %parm[interface]%. By looking at the events nodedown/nodeup in the events table the eventparams consists only the nodelabel.

How could I fetch the interface of the node in event notifications ??
Have anybody tried to modify the code to add the interface parameter to the eventparams of nodeup/nodedown events ??

Thanks and Regards,
Reddy.


Index: test/java/org/opennms/netmgt/mock/MockQueryManager.java
===================================================================
--- test/java/org/opennms/netmgt/mock/MockQueryManager.java     (revision 31)
+++ test/java/org/opennms/netmgt/mock/MockQueryManager.java     (working copy)
@@ -116,6 +116,11 @@
         MockNode node = m_network.getNode(nodeId);
         return (node == null ? null : node.getLabel());
     }
+               
+    public String getNodeAnyInterface(int nodeId) throws SQLException {
+        MockNode node = m_network.getNode(nodeId);
+        return (node == null ? null : node.getLabel());
+    }
 
     public int getServiceCountForInterface(String ipaddr) throws SQLException {
         return getActiveServiceIdsForInterface(ipaddr).size();
Index: main/java/org/opennms/netmgt/poller/QueryManager.java
===================================================================
--- main/java/org/opennms/netmgt/poller/QueryManager.java       (revision 31)
+++ main/java/org/opennms/netmgt/poller/QueryManager.java       (working copy)
@@ -182,5 +182,14 @@
     public String[] getCriticalPath(int nodeId);
     
     public List<String[]> getNodeServices(int nodeId);
+               
+               /**
+     * <p>getNodeAnyInterface</p>
+     *
+     * @param nodeId a int.
+     * @throws java.sql.SQLException if any.
+     * @return a {@link java.lang.String} object.
+     */
+    public String getNodeAnyInterface(int nodeId) throws SQLException;
     
 }
Index: main/java/org/opennms/netmgt/poller/DefaultQueryManager.java
===================================================================
--- main/java/org/opennms/netmgt/poller/DefaultQueryManager.java        
(revision 31)
+++ main/java/org/opennms/netmgt/poller/DefaultQueryManager.java        
(working copy)
@@ -566,6 +566,37 @@
         return servicemap;
         
     }
+               
+               /** {@inheritDoc} */
+    public String getNodeAnyInterface(int nodeId) throws SQLException {
+        ThreadCategory log = log();
+
+        String nodeInterface = null;
+        java.sql.Connection dbConn = null;
+        Statement stmt = null;
+        ResultSet rs = null;
+        final DBUtils d = new DBUtils(getClass());
+        try {
+            // Get database connection from the factory
+            dbConn = getConnection();
+            d.watch(dbConn);
+
+            // Issue query and extract nodeLabel from result set
+            stmt = dbConn.createStatement();
+            d.watch(stmt);
+            rs = stmt.executeQuery("SELECT ipaddr FROM ipinterface WHERE 
nodeid=" + String.valueOf(nodeId) + " LIMIT 1");
+            d.watch(rs);
+            if (rs.next()) {
+               nodeInterface = (String) rs.getString("ipaddr");
+                if (log.isDebugEnabled())
+                    log.debug("getNodeAnyInterface: nodeid=" + nodeId + " 
ipaddr=" + nodeInterface);
+            }
+        } finally {
+            d.cleanUp();
+        }
+
+        return nodeInterface;
+    }
     
     
 }
Index: main/java/org/opennms/netmgt/poller/DefaultPollContext.java
===================================================================
--- main/java/org/opennms/netmgt/poller/DefaultPollContext.java (revision 31)
+++ main/java/org/opennms/netmgt/poller/DefaultPollContext.java (working copy)
@@ -273,7 +273,7 @@
         
             String nodeLabel = this.getNodeLabel(nodeId);
             bldr.addParam(EventConstants.PARM_NODE_LABEL, nodeLabel);
-            
+            bldr.setInterface(this.getNodeAnyInterface(nodeId));
         }
         
         return bldr.getEvent();
@@ -417,5 +417,24 @@
         }
         return nodeLabel;
     }
+               
+       String getNodeAnyInterface(int nodeId) {
+        String nodeInterface = null;
+        try {
+               nodeInterface = getQueryManager().getNodeAnyInterface(nodeId);
+        } catch (SQLException sqlE) {
+            // Log a warning
+            log().warn("Failed to retrieve node any interface for nodeid " + 
nodeId,
+                     sqlE);
+        }
+    
+        if (nodeInterface == null) {
+            // This should never happen but if it does just
+            // use nodeId for the nodeLabel so that the
+            // event description has something to display.
+               nodeInterface = String.valueOf(nodeId);
+        }
+        return nodeInterface;
+    }
 
 }
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
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

Reply via email to