Re: [opennms-devel] IndexStorageStrategy - storing by name vs index

Alejandro Galue <[email protected]>
Newsgroups gmane.network.opennms.bugs
Organization Sync Consultores
Message-ID <485159D6.60506__37261.9219976061$1213291066$gmane$org@sync.com.ve>
How can I do that from StorageStrategy implementation ?

It would be great if StorageStrategy can access data 
configured on datacollection-config.xml and avoid SNMP 
request (as I suggested on my implementation).

I included here my new version for new features on 
StorageStrategy that includes 
HostFileSystemStorageStrategy. This patch is based on 
1.6-testing branch rev. 9264.

Hope this help.

Alejandro.

Matt Brozowski wrote:
> Could you just add hrStorageDescr as a collection value? and then access 
> it from the collection set?
> 
> On Thu, Jun 12, 2008 at 11:13 AM, Will Fraley <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     Hello,
> 
>     In an attempt to to make collection of disk usage data from
>     hrstoragetable resistant to index changes (like ip interface data
>     is), I've been attempting to implement a solution similar to one
>     Alejandro outlines in bug #1851.
> 
>     Is there a quick and dirty way I can get the IP of the current host
>     (so I can in turn call getAgentConfig()) from within a class
>     extending IndexStorageStrategy?  This will allow an additional snmp
>     request to get the hrstoragedescr of the particular index, which is
>     extremely ugly, but should work for my needs.
> 
>     Thanks!
> 
>     -Will
> 
>     -------------------------------------------------------------------------
>     Check out the new SourceForge.net Marketplace.
>     It's the best place to buy or sell services for
>     just about anything Open Source.
>     http://sourceforge.net/services/buy/index.php
>     _______________________________________________
>     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
> 
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

_______________________________________________
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
GenericResources.diff (text/plain, 25.3 KB)
Index: opennms-dao/src/main/java/org/opennms/netmgt/dao/support/FrameRelayStorageStrategy.java
===================================================================
--- opennms-dao/src/main/java/org/opennms/netmgt/dao/support/FrameRelayStorageStrategy.java	(revision 0)
+++ opennms-dao/src/main/java/org/opennms/netmgt/dao/support/FrameRelayStorageStrategy.java	(revision 0)
@@ -0,0 +1,56 @@
+//
+// This file is part of the OpenNMS(R) Application.
+//
+// OpenNMS(R) is Copyright (C) 2006 The OpenNMS Group, Inc.  All rights reserved.
+// OpenNMS(R) is a derivative work, containing both original code, included code and modified
+// code that was published under the GNU General Public License. Copyrights for modified
+// and included code are below.
+//
+// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+//
+// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// For more information contact:
+//      OpenNMS Licensing       <[email protected]>
+//      http://www.opennms.org/
+//      http://www.opennms.com/
+//
+package org.opennms.netmgt.dao.support;
+
+import java.util.StringTokenizer;
+
+/**
+ * This class use the new implementation of SnmpStorageStrategy extending the new
+ * IndexStorageStrategy from opennms-services
+ */
+public class FrameRelayStorageStrategy extends IndexStorageStrategy {
+
+    @Override
+    public String getResourceNameFromIndex(String resourceParent, String resourceIndex) {
+        StringTokenizer indexes = new StringTokenizer(resourceIndex, ".");
+        String ifIndex = indexes.nextToken();
+        String ifName = getInterfaceName(resourceParent, ifIndex);
+        String dlci = indexes.nextToken();
+        return ifName + "." + dlci;
+    }
+       
+    public String getInterfaceName(String nodeId, String ifIndex) {
+       String label = m_collectionAgent.getSnmpInterfaceLabel(new Integer(ifIndex));
+       return label != null ? label : ifIndex;
+    }
+
+}
Index: opennms-dao/src/main/java/org/opennms/netmgt/dao/support/IndexStorageStrategy.java
===================================================================
--- opennms-dao/src/main/java/org/opennms/netmgt/dao/support/IndexStorageStrategy.java	(revision 9264)
+++ opennms-dao/src/main/java/org/opennms/netmgt/dao/support/IndexStorageStrategy.java	(working copy)
@@ -33,10 +33,12 @@
 
 import java.io.File;
 
+import org.opennms.netmgt.config.SnmpCollectionAgent;
 import org.opennms.netmgt.config.StorageStrategy;
 
 public class IndexStorageStrategy implements StorageStrategy {
     private String m_resourceTypeName;
+    protected SnmpCollectionAgent m_collectionAgent;
 
     public String getRelativePathForAttribute(String resourceParent, String resource,
             String attribute) {
@@ -46,9 +48,11 @@
         buffer.append(m_resourceTypeName);
         buffer.append(File.separator);
         buffer.append(resource);
-        buffer.append(File.separator);
-        buffer.append(attribute);
-        buffer.append(RrdFileConstants.getRrdSuffix());
+        if (attribute != null) {
+            buffer.append(File.separator);
+            buffer.append(attribute);
+            buffer.append(RrdFileConstants.getRrdSuffix());
+        }
         return buffer.toString();
     }
 
@@ -59,4 +63,12 @@
     public String getResourceTypeName() {
         return m_resourceTypeName;
     }
+
+    public String getResourceNameFromIndex(String resourceParent, String resourceIndex) {
+        return resourceIndex;
+    }
+
+    public void setCollectionAgent(SnmpCollectionAgent agent) {
+        m_collectionAgent = agent;
+    }
 }
Index: opennms-dao/src/main/java/org/opennms/netmgt/dao/support/HostFileSystemStorageStrategy.java
===================================================================
--- opennms-dao/src/main/java/org/opennms/netmgt/dao/support/HostFileSystemStorageStrategy.java	(revision 0)
+++ opennms-dao/src/main/java/org/opennms/netmgt/dao/support/HostFileSystemStorageStrategy.java	(revision 0)
@@ -0,0 +1,61 @@
+//
+// This file is part of the OpenNMS(R) Application.
+//
+// OpenNMS(R) is Copyright (C) 2006 The OpenNMS Group, Inc.  All rights reserved.
+// OpenNMS(R) is a derivative work, containing both original code, included code and modified
+// code that was published under the GNU General Public License. Copyrights for modified
+// and included code are below.
+//
+// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+//
+// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// For more information contact:
+//      OpenNMS Licensing       <[email protected]>
+//      http://www.opennms.org/
+//      http://www.opennms.com/
+//
+package org.opennms.netmgt.dao.support;
+
+import org.opennms.netmgt.snmp.SnmpObjId;
+import org.opennms.netmgt.snmp.SnmpUtils;
+import org.opennms.netmgt.snmp.SnmpValue;
+
+public class HostFileSystemStorageStrategy extends IndexStorageStrategy {
+
+    public static String HR_STORAGE_DESC = ".1.3.6.1.2.1.25.2.3.1.3";
+
+    @Override
+    public String getResourceNameFromIndex(String resourceParent, String resourceIndex) {
+        SnmpObjId oid = SnmpObjId.get(HR_STORAGE_DESC + "." + resourceIndex);
+        SnmpValue snmpValue = SnmpUtils.get(m_collectionAgent.getAgentConfig(), oid);
+        String value = (snmpValue != null ? snmpValue.toString() : resourceIndex);
+        /*
+         * Use special translation for root (base) filesystem
+         */
+        if (value.equals("/"))
+            return "_root_fs";
+        /*
+         * 1. Eliminate first slash character
+         * 2. Eliminate tabs and spaces on filesystem names
+         * 3. Replace slash (file separator) character with "-"
+         * 4. Remove Additional Information on Windows Drives
+         */
+        return value.replaceFirst("/", "").replaceAll("\\s", "").replaceAll("/", "-").replaceAll(":\\\\.*", "");
+    }
+
+}
Index: opennms-dao/src/main/java/org/opennms/netmgt/config/SnmpCollectionAgent.java
===================================================================
--- opennms-dao/src/main/java/org/opennms/netmgt/config/SnmpCollectionAgent.java	(revision 0)
+++ opennms-dao/src/main/java/org/opennms/netmgt/config/SnmpCollectionAgent.java	(revision 0)
@@ -0,0 +1,16 @@
+package org.opennms.netmgt.config;
+
+import org.opennms.netmgt.snmp.SnmpAgentConfig;
+
+public interface SnmpCollectionAgent {
+
+    public SnmpAgentConfig getAgentConfig();
+
+    /*
+     * This method is used on SnmpStorageStrategy implementation when the resource index is associated to
+     * a physical interface like frame relay resources. OpenNMS always track changes on ifTable so, make SNMP
+     * queries on this table is redundant, and implementations of CollectionAgent know ifTable content always.
+     * This method give interface information from a specific ifIndex.
+     */
+    public String getSnmpInterfaceLabel(int ifIndex);
+}
Index: opennms-dao/src/main/java/org/opennms/netmgt/config/StorageStrategy.java
===================================================================
--- opennms-dao/src/main/java/org/opennms/netmgt/config/StorageStrategy.java	(revision 9264)
+++ opennms-dao/src/main/java/org/opennms/netmgt/config/StorageStrategy.java	(working copy)
@@ -35,4 +35,21 @@
     public String getRelativePathForAttribute(String resourceParent, String resource, String attribute);
 
     public void setResourceTypeName(String name);
+
+    /*
+     * This functions translate resourceIndex into a "unique" and "non-variable" name that could be identify
+     * a resource, as described earlier.
+     * 
+     * This method could be expensive because it could require send SNMP queries and make complicated functions to
+     * build the name. So you must try to call it only when is necessary.
+     */
+    public String getResourceNameFromIndex(String resourceParent, String resourceIndex);
+    
+    /*
+     * Add to a strategy the possibility to get additional information using SNMP when is necessary.
+     * There are complex tables on some MIBs where indexes depends on indexes from other tables (indirect indexing).
+     * For this kind of resources we must send some additional SNMP queries to build a unique name.
+     */ 
+    public void setCollectionAgent(SnmpCollectionAgent agent);
+
 }
Index: opennms-daemon/src/main/filtered/etc/snmp-graph.properties
===================================================================
--- opennms-daemon/src/main/filtered/etc/snmp-graph.properties	(revision 9264)
+++ opennms-daemon/src/main/filtered/etc/snmp-graph.properties	(working copy)
@@ -118,7 +118,8 @@
 airport.numClients,iisTraffic,iisRequests,exchangeMessages,exchangeBytes, \
 exchangeRecipPartitions,dnsThroughput,mssqlmemory,mssqlusage,mssqlhitratios,mssqllockwaittime, \
 windowsCPU,livecommsusers,livecommsmessages,mailmarshal, \
-alvarion.droppedrec,alvarion.surb-stats,alvarion.lqi-stats
+alvarion.droppedrec,alvarion.surb-stats,alvarion.lqi-stats, \
+framerelay.bits, framerelay.frames, framerelay.congestion
 
 
 # values available to prefab reports:
@@ -5946,5 +5947,71 @@
  GPRINT:pktsOut:AVERAGE:"Avg  \\: %8.2lf %s" \
  GPRINT:pktsOut:MIN:"Min  \\: %8.2lf %s" \
  GPRINT:pktsOut:MAX:"Max  \\: %8.2lf %s\\n"
- 
+
+report.framerelay.bits.name=Bits In/Out
+report.framerelay.bits.columns=frReceivedOctets,frSentOctets
+report.framerelay.bits.propertiesValues=frDlci
+report.framerelay.bits.type=frCircuitIfIndex
+report.framerelay.bits.command=--title="Bits In/Out of DLCI {frDlci}" \
+ --vertical-label="Bits per second" \
+ DEF:octIn={rrd1}:frReceivedOctets:AVERAGE \
+ DEF:octOut={rrd2}:frSentOctets:AVERAGE \
+ CDEF:rawbitsIn=octIn,8,* \
+ CDEF:rawbitsOut=octOut,8,* \
+ CDEF:rawbitsOutNeg=0,rawbitsOut,- \
+ CDEF:rawtotBits=octIn,octOut,+,8,* \
+ CDEF:bitsIn=rawbitsIn,UN,0,rawbitsIn,IF \
+ CDEF:bitsOut=rawbitsOut,UN,0,rawbitsOut,IF \
+ CDEF:totBits=rawtotBits,UN,0,rawtotBits,IF \
+ CDEF:outSum=bitsOut,{diffTime},* \
+ CDEF:inSum=bitsIn,{diffTime},* \
+ CDEF:totSum=totBits,{diffTime},* \
+ AREA:rawbitsIn#00ff00:"In " \
+ GPRINT:rawbitsIn:AVERAGE:"Avg  \\: %8.2lf %s" \
+ GPRINT:rawbitsIn:MIN:"Min  \\: %8.2lf %s" \
+ GPRINT:rawbitsIn:MAX:"Max  \\: %8.2lf %s\\n" \
+ AREA:rawbitsOutNeg#0000ff:"Out" \
+ GPRINT:rawbitsOut:AVERAGE:"Avg  \\: %8.2lf %s" \
+ GPRINT:rawbitsOut:MIN:"Min  \\: %8.2lf %s" \
+ GPRINT:rawbitsOut:MAX:"Max  \\: %8.2lf %s\\n" \
+ GPRINT:inSum:AVERAGE:"  Tot In  \\: %8.2lf %s" \
+ GPRINT:outSum:AVERAGE:" Tot Out  \\: %8.2lf %s" \
+ GPRINT:totSum:AVERAGE:" Tot  \\: %8.2lf %s\\n"
+
+report.framerelay.frames.name=Frames In/Out
+report.framerelay.frames.columns=frReceivedFrames,frSentFrames
+report.framerelay.frames.propertiesValues=frDlci
+report.framerelay.frames.type=frCircuitIfIndex
+report.framerelay.frames.command=--title="Frames In/Out of DLCI {frDlci}" \
+ --vertical-label="Frames per Second" \
+ DEF:fpsIn={rrd1}:frReceivedFrames:AVERAGE \
+ DEF:fpsOut={rrd2}:frSentFrames:AVERAGE \
+ CDEF:fpsOutNeg=0,fpsOut,- \
+ AREA:fpsIn#00ff00:"In " \
+ GPRINT:fpsIn:AVERAGE:"Avg  \\: %8.2lf %s" \
+ GPRINT:fpsIn:MIN:"Min  \\: %8.2lf %s" \
+ GPRINT:fpsIn:MAX:"Max  \\: %8.2lf %s\\n" \
+ AREA:fpsOutNeg#0000ff:"Out" \
+ GPRINT:fpsOut:AVERAGE:"Avg  \\: %8.2lf %s" \
+ GPRINT:fpsOut:MIN:"Min  \\: %8.2lf %s" \
+ GPRINT:fpsOut:MAX:"Max  \\: %8.2lf %s\\n" \
+
+report.framerelay.congestion.name=FECNs / BECNs
+report.framerelay.congestion.columns=frReceivedBECNs,frReceivedFECNs
+report.framerelay.congestion.propertiesValues=frDlci
+report.framerelay.congestion.type=frCircuitIfIndex
+report.framerelay.congestion.command=--title="FECNs/BECNs of DLCI {frDlci}" \
+ --vertical-label="FECN/BECN per Second" \
+ DEF:becns={rrd1}:frReceivedBECNs:AVERAGE \
+ DEF:fecns={rrd2}:frReceivedFECNs:AVERAGE \
+ CDEF:fecnsNeg=0,fecns,- \
+ AREA:becns#00ff00:"BECNs" \
+ GPRINT:becns:AVERAGE:"Avg  \\: %8.2lf %s" \
+ GPRINT:becns:MIN:"Min  \\: %8.2lf %s" \
+ GPRINT:becns:MAX:"Max  \\: %8.2lf %s\\n" \
+ AREA:fecnsNeg#0000ff:"FECNs" \
+ GPRINT:fecns:AVERAGE:"Avg  \\: %8.2lf %s" \
+ GPRINT:fecns:MIN:"Min  \\: %8.2lf %s" \
+ GPRINT:fecns:MAX:"Max  \\: %8.2lf %s\\n" \
+
 ## EOF
Index: opennms-daemon/src/main/filtered/etc/datacollection-config.xml
===================================================================
--- opennms-daemon/src/main/filtered/etc/datacollection-config.xml	(revision 9264)
+++ opennms-daemon/src/main/filtered/etc/datacollection-config.xml	(working copy)
@@ -9,6 +9,11 @@
       <rra>RRA:MIN:0.5:288:366</rra>
     </rrd>
 
+    <resourceType name="frCircuitIfIndex" label="Frame-Relay (RFC1315)">
+      <persistenceSelectorStrategy class="org.opennms.netmgt.collectd.PersistAllSelectorStrategy"/>
+      <storageStrategy class="org.opennms.netmgt.dao.support.FrameRelayStorageStrategy"/>
+    </resourceType>
+
     <resourceType name="ciscoEnvMonTemperatureStatusIndex" label="Cisco Temperature"
                   resourceLabel="${cvmTempStatusDescr} (index ${index})">
       <persistenceSelectorStrategy class="org.opennms.netmgt.collectd.PersistAllSelectorStrategy"/>
@@ -36,7 +41,7 @@
     <resourceType name="hrStorageIndex" label="Storage (MIB-2 Host Resources)"
                   resourceLabel="${hrStorageDescr} (index ${index})">
       <persistenceSelectorStrategy class="org.opennms.netmgt.collectd.PersistAllSelectorStrategy"/>
-      <storageStrategy class="org.opennms.netmgt.dao.support.IndexStorageStrategy"/>
+      <storageStrategy class="org.opennms.netmgt.dao.support.HostFileSystemStorageStrategy"/>
     </resourceType>
 
     <resourceType name="ipuMGCPMsgStatsEntry" label="IP Unity MGCP Message Stats"
@@ -129,6 +134,27 @@
     </resourceType>
 
     <groups>
+      <group name="cisco-frame-relay" ifType="all">
+        <mibObj oid=".1.3.6.1.4.1.9.9.49.1.2.2.1.1" instance="frCircuitIfIndex" alias="frIfName"     type="string" />
+        <mibObj oid=".1.3.6.1.4.1.9.9.49.1.2.2.1.2" instance="frCircuitIfIndex" alias="frIfType"     type="string" />
+        <mibObj oid=".1.3.6.1.4.1.9.9.49.1.2.2.1.3" instance="frCircuitIfIndex" alias="frSubifIndex" type="string" />
+        <mibObj oid=".1.3.6.1.4.1.9.9.49.1.2.1.1.1" instance="frCircuitIfIndex" alias="frDEins"        type="counter" />
+        <mibObj oid=".1.3.6.1.4.1.9.9.49.1.2.1.1.2" instance="frCircuitIfIndex" alias="frDEouts"       type="counter" />
+        <mibObj oid=".1.3.6.1.4.1.9.9.49.1.2.1.1.3" instance="frCircuitIfIndex" alias="frDropPktsOuts" type="counter" />
+      </group>
+
+      <group name="rfc1315-frame-relay" ifType="all">
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.1" instance="frCircuitIfIndex" alias="frIfIndex"        type="string" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.2" instance="frCircuitIfIndex" alias="frDlci"           type="string" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.3" instance="frCircuitIfIndex" alias="frState"          type="string" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.4" instance="frCircuitIfIndex" alias="frReceivedFECNs"  type="Counter" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.5" instance="frCircuitIfIndex" alias="frReceivedBECNs"  type="Counter" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.6" instance="frCircuitIfIndex" alias="frSentFrames"     type="Counter" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.7" instance="frCircuitIfIndex" alias="frSentOctets"     type="Counter" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.8" instance="frCircuitIfIndex" alias="frReceivedFrames" type="Counter" />
+        <mibObj oid=".1.3.6.1.2.1.10.32.2.1.9" instance="frCircuitIfIndex" alias="frReceivedOctets" type="Counter" />
+      </group>
+
       <!-- data from standard (mib-2) sources -->
       <group name="mib2-interfaces" ifType="all">
         <mibObj oid=".1.3.6.1.2.1.2.2.1.10" instance="ifIndex" alias="ifInOctets" type="counter" />
@@ -1642,6 +1668,8 @@
           <includeGroup>adsl-line</includeGroup>
           <includeGroup>cisco-rttmon-latest-jitter-stats</includeGroup>
           <includeGroup>cisco-rttmon-latest-rtp-stats</includeGroup>
+          <includeGroup>rfc1315-frame-relay</includeGroup>
+          <includeGroup>cisco-frame-relay</includeGroup>
         </collect>
       </systemDef>
 
@@ -1810,6 +1838,7 @@
         <collect>
           <includeGroup>mib2-host-resources-system</includeGroup>
           <includeGroup>mib2-host-resources-memory</includeGroup>
+          <includeGroup>mib2-host-resources-storage</includeGroup>
           <includeGroup>net-snmp-disk</includeGroup>
           <includeGroup>ucd-loadavg</includeGroup>
           <includeGroup>ucd-memory</includeGroup>
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/NodeInfo.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/NodeInfo.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/NodeInfo.java	(working copy)
@@ -91,4 +91,9 @@
     public String getInstance() {
         return null; //For node type resources, use the default instance
     }
+
+    public String getLabel() {
+        return null;
+    }
+
 } // end class
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/AliasedResource.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/AliasedResource.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/AliasedResource.java	(working copy)
@@ -123,4 +123,8 @@
     public String getInstance() {
         return null; //For node and interface type resources, use the default instance
     }
+
+    public String getLabel() {
+        return getDomain() + '/' + getAliasDir();
+    }
 }
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/CollectionResource.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/CollectionResource.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/CollectionResource.java	(working copy)
@@ -67,4 +67,11 @@
      * @return
      */
     public String getInstance();
+
+    /**
+     * Returns a unique label for each resource depending on resource type.
+     * This label is the same label used when constructing the resource ID.
+     * @Return
+     */
+    public String getLabel();
 }
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/CollectionAgent.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/CollectionAgent.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/CollectionAgent.java	(working copy)
@@ -38,6 +38,7 @@
 import java.net.InetAddress;
 import java.util.Set;
 
+import org.opennms.netmgt.config.SnmpCollectionAgent;
 import org.opennms.netmgt.poller.NetworkInterface;
 import org.opennms.netmgt.snmp.SnmpAgentConfig;
 
@@ -45,7 +46,7 @@
  * 
  * @author <a href="mailto:[email protected]">Mathew Brozowski</a>
  */
-public interface CollectionAgent extends NetworkInterface {
+public interface CollectionAgent extends NetworkInterface,SnmpCollectionAgent {
 
     public abstract void setMaxVarsPerPdu(int maxVarsPerPdu);
 
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/GenericIndexResource.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/GenericIndexResource.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/GenericIndexResource.java	(working copy)
@@ -33,6 +33,7 @@
 
 import java.io.File;
 
+import org.opennms.netmgt.config.StorageStrategy;
 import org.opennms.netmgt.model.RrdRepository;
 import org.opennms.netmgt.snmp.SnmpInstId;
 
@@ -40,6 +41,7 @@
 
     private SnmpInstId m_inst;
     private String m_name;
+    private String m_resourceLabel;
 
     public GenericIndexResource(ResourceType def, String name, SnmpInstId inst) {
         super(def);
@@ -47,19 +49,16 @@
         m_inst = inst;
     }
 
-    // XXX should be based on the storageStrategy
     @Override
     public File getResourceDir(RrdRepository repository) {
-        File rrdBaseDir = repository.getRrdBaseDir();
-        File nodeDir = new File(rrdBaseDir, String.valueOf(getCollectionAgent().getNodeId()));
-        File typeDir = new File(nodeDir, m_name);
-        File instDir = new File(typeDir, m_inst.toString());
-        log().debug("getResourceDir: " + instDir.toString());
-        return instDir;
+        String resourcePath = getStrategy().getRelativePathForAttribute(getParent(), getLabel(), null);
+        File resourceDir = new File(repository.getRrdBaseDir(), resourcePath);
+        log().debug("getResourceDir: " + resourceDir);
+        return resourceDir;
     }
 
     public String toString() {
-        return "node["+getCollectionAgent().getNodeId() + "]." + getResourceTypeName() + "[" + m_inst + "]";
+        return "node["+getCollectionAgent().getNodeId() + "]." + getResourceTypeName() + "[" + getLabel() + "]";
     }
 
 
@@ -80,4 +79,23 @@
     public String getInstance() {
         return m_inst.toString();
     }
+
+    private StorageStrategy getStrategy() {
+        return ((GenericIndexResourceType)getResourceType()).getStorageStrategy();
+    }
+
+    private String getParent() {
+        return String.valueOf(getCollectionAgent().getNodeId());
+    }
+
+    /*
+     * Because call getResourceNameFromIndex could be expensive.
+     * This class save the returned value from Strategy on a local variable.
+     */
+    public String getLabel() {
+        if (m_resourceLabel == null) {
+            m_resourceLabel = getStrategy().getResourceNameFromIndex(getParent(), getInstance());
+        }
+        return m_resourceLabel;
+    }
 }
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/DefaultCollectionAgent.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/DefaultCollectionAgent.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/DefaultCollectionAgent.java	(working copy)
@@ -279,6 +279,14 @@
         return ifInfos;
     }
 
+    public String getSnmpInterfaceLabel(int ifIndex) {
+        for (SnmpIfData ifData : getSnmpInterfaceData()) {
+            if (ifData.getIfIndex() == ifIndex)
+                return ifData.getLabelForRRD();
+        }
+        return null;
+    }
+
     public long getSavedSysUpTime() {
         return m_sysUpTime;
     }
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/GenericIndexResourceType.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/GenericIndexResourceType.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/GenericIndexResourceType.java	(working copy)
@@ -85,6 +85,8 @@
         }
 
         m_storageStrategy.setResourceTypeName(m_name);
+        if (getAgent() != null)
+            m_storageStrategy.setCollectionAgent(getAgent());
     }
 
     @Override
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/HttpCollector.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/HttpCollector.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/HttpCollector.java	(working copy)
@@ -675,6 +675,10 @@
         public String getInstance() {
             return null;
         }
+
+        public String getLabel() {
+            return null;
+        }
     }
     
     class HttpCollectionAttributeType implements CollectionAttributeType {
Index: opennms-services/src/main/java/org/opennms/netmgt/collectd/AbstractCollectionResource.java
===================================================================
--- opennms-services/src/main/java/org/opennms/netmgt/collectd/AbstractCollectionResource.java	(revision 9264)
+++ opennms-services/src/main/java/org/opennms/netmgt/collectd/AbstractCollectionResource.java	(working copy)
@@ -111,4 +111,8 @@
 
     public abstract boolean shouldPersist(ServiceParameters params);
 
-}
\ No newline at end of file
+    public String getLabel() {
+        return null;
+    }
+
+}
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.