[opennms-devel] HTTP Collector Incomplete.

Jessica Mayo <[email protected]>
Newsgroups gmane.network.opennms.bugs
Message-ID <48843433.8080700__43963.9016906314$1216623754$gmane$org@ursys.com.au>
Since 2006, The documentation for the HTTP Collector has read:
  "SPECIAL NOTE: an enhancement will be made that allows the ${ipaddr} 
to be part of any of the <url> element's attributes."
but there has been no enhancement bug in bugzilla and everyone seems to 
have forgotten about this.

We have several services for which status information is available via 
3rd-party monitoring systems, but the machine cannot be contacted directly.

We aimed to use the PassiveStatusKeeper and the HTTP Collector to 
achieve full monitoring of those services. we then discovered that 
${ipaddr} could not be specified as a part of any useful field in the 
HTTP collector.

I have created an enhancement bug for this.

In the end, we have got something that does the job working well, based 
on the Importer, PSK, and a modified version of the HttpCollector.

We are using foreign keys in the importer, and don't really trust the IP 
addresses we are given... and since I was already doing some small 
lookups into the OpenNMS database to persist categories, I used 
${nodeID} as an easy persistent key in the HttpCollector.

Ideally I would be using the import's Foreign Keys here, but I'm not 
sure how to access that information in the code.

My final diff to http collector is attatched.

And I will get a copy of the Contributor agreement to you ASAP. :)

Jessica Mayo,
URSYS Pty. Ltd.
13 Burwood Rd, Burwood NSW 2134, Australia
Ph: +61 2 8745 2800  Fax: +61 2 8745 2828 http://www.ursys.com.au/

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
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
HttpCollector.patch (text/plain, 2.5 KB)
--- ../opennms.bak/opennms-services/src/main/java/org/opennms/netmgt/collectd/HttpCollector.java	2008-06-03 16:39:27.000000000 +1000
+++ ../opennms/opennms-services/src/main/java/org/opennms/netmgt/collectd/HttpCollector.java	2008-07-15 12:00:31.000000000 +1000
@@ -478,24 +478,28 @@
     private URI buildUri(final HttpCollectionSet collectionSet) throws URIException {
         return new URI(collectionSet.getUriDef().getUrl().getScheme(),
                 collectionSet.getUriDef().getUrl().getUserInfo(),
-                determineHost(collectionSet.getAgent().getInetAddress(), collectionSet.getUriDef()),
+                doSubs(collectionSet, collectionSet.getUriDef().getUrl().getHost(), "getHost"),
                 collectionSet.getUriDef().getUrl().getPort(),
-                collectionSet.getUriDef().getUrl().getPath(),
-                collectionSet.getUriDef().getUrl().getQuery(),
-                collectionSet.getUriDef().getUrl().getFragment());
+                doSubs(collectionSet, collectionSet.getUriDef().getUrl().getPath(), "getURL"),
+                doSubs(collectionSet, collectionSet.getUriDef().getUrl().getQuery(), "getQuery"),
+                doSubs(collectionSet, collectionSet.getUriDef().getUrl().getFragment(), "getFragment"));
     }
     
     //note: trouble deciding here on getHost() vs. getIpAddress() or 
     //getCanonicalHost() even.
-    private String determineHost(final InetAddress address, final Uri uriDef) {
-        String host;
-        if ("${ipaddr}".equals(uriDef.getUrl().getHost())) {
-            host = address.getHostName();
-        } else {
-            host = uriDef.getUrl().getHost();
+    private String doSubs(final HttpCollectionSet collectionSet, final String urlFragment, final String desc) {
+        String newFragment = urlFragment;
+        if (newFragment != null)
+        {
+            String hoststr = new String(collectionSet.getAgent().getInetAddress().getHostName());
+            String nodestr = new String(Integer.toString(collectionSet.getAgent().getNodeId()));
+            newFragment = newFragment.replaceAll("\\$\\{ipaddr\\}", hoststr);
+            newFragment = newFragment.replaceAll("\\$\\{nodeID\\}", nodestr);
+            if (newFragment.compareTo(urlFragment) != 0) {
+                log().debug("doSubs: "+desc+" substituted as \""+newFragment+"\"");
+            }
         }
-        log().debug("determineHost: host for URI is set to: "+host);
-        return host;
+        return newFragment;
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.