Hello,

Will this feature be integrated into the next release ?

Regards,
Samuel Mutel.

----- Mail transféré -----
De: "Samuel Mutel" <smu...@monitoring-fr.org>
À: "OpenNMS Code Development and Bugs" <opennms-devel@lists.sourceforge.net>
Envoyé: Vendredi 29 Juin 2012 14:59:36
Objet: Re: [opennms-devel] Capability to convert string into integer or gauge   
in datacollection

Hello,

Please find in attached files:
  - The patch for BasePersister.java
  - The patch for SnmpAttribute.java
  - The datacollection configuration file for IBM BLADE H/E
  - The graph configuration file ibm-blade-graph.properties

The code was changed with your previous remarks.

I will send the oca on o...@opennms.org.

I already tested with the monitoring of IBM BLADE E but if you want unit test, 
please help me.

Regards,
Samuel Mutel.

----- Mail original -----
De: "Jeff Gehlbach" <je...@opennms.org>
À: "OpenNMS Code Development and Bugs" <opennms-devel@lists.sourceforge.net>
Envoyé: Jeudi 28 Juin 2012 17:09:26
Objet: Re: [opennms-devel] Capability to convert string into integer or gauge   
in datacollection

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/28/2012 06:20 AM, Samuel Mutel wrote:

> Please find below the change I made on file SnmpAttribute.java
> (package org.opennms.netmgt.collectd):

Samuel, thanks for this enhancement.  Can you resend your proposed
changes in the form of a context diff, e.g. by running "git diff"?

Design-wise, I have two pieces of input:

1. Move the regular expression parts so that they're called only after
we have caught a NumberFormatException.  Evaluating this match is
expensive compared to Double.valueOf(String).

2. Use the find() method rather than the matches() method.  Since find()
stops scanning the input string after it makes a single match, it's
cheaper than matches(), which attempts to match the entire input string.

> This peace of code could be integrated into the next release, what
> do you think about that ?

Only with accompanying unit tests and an executed contributor agreement
(http://www.opennms.org/wiki/OCA).

I can help you get started writing tests if you're not familiar with
doing that.

- -jeff


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJP7HOmAAoJEEfedldKS64sFXIQAI6UnjI7yH9FpiE3A3XYSFti
KiXfmw9TWXq1ofGaVns5oTwDpl2SlRRvmWJdE/wzcOO5k52waIhVqA9cyc8EWCX3
cJ2xpurQvMq0Ts44+qQTFl81NlyuJ/U0tr2rOq0AWgulcvyS7rA2tapu+NLqB2Hd
99Ms0NSg5Xxy1c1XtaV28Xz5dDdctNLy6/Ft2CTss2sapVTCV83U1nQAa40VaDz7
h6chTLDK6wdjzVd6aiUN0lurgn7i9Q87J1itgqRhIjFdpGoVhzsf7Xz24oxR6yaB
BbgjaNvnZJYLQvRgCpLH0ei7DeS8KWgEgPbHDv0zPPxX4REBQDliPUBFU+3ookL1
Lr8WEAxUR8tQIIosIZiZbMkRYZGX+KjZ+t4cAd8sRa0OLPc1NvbHGp3yRH61GdW1
r8LCPUVvYgcpKXZEbSaQJU8AApTvsScStJyj1dafBHQG8cJ7cfMvu5e7VbVHvoW/
yO8h96aQ54lgiupoFvIH7rBtdPSyJrAT5KsRBdiHEl5rP0iZ2uQGv7GoQHXeSFfR
aNUfRhcYhBanWW4lmh2vsW4FShq+URTkEAAZxilq4xw96X0QQZ8BgpmE48NMKoMy
izffwhWQTENHIu/y34vXwtkGELkNHxGA7v+ykVk2gyevooOQYvNfA+Ndz+WUyRyI
3HyqS8KcnmIP3VqYt0aS
=JNGE
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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
diff --git a/opennms-services/src/main/java/org/opennms/netmgt/collectd/BasePersister.java b/opennms-services/src/main/java/org/opennms/netmgt/collectd/BasePersister.java
index 88c2c80..3821718 100644
--- a/opennms-services/src/main/java/org/opennms/netmgt/collectd/BasePersister.java
+++ b/opennms-services/src/main/java/org/opennms/netmgt/collectd/BasePersister.java
@@ -140,9 +140,7 @@ public class BasePersister extends AbstractCollectionSetVisitor implements Persi
             m_builder.setTimeKeeper(resource.getTimeKeeper());
         for (Iterator<AttributeDefinition> iter = attributeTypes.iterator(); iter.hasNext();) {
             AttributeDefinition attrType = iter.next();
-            if (attrType instanceof NumericAttributeType) {
-                m_builder.declareAttribute(attrType);
-            }
+            m_builder.declareAttribute(attrType);
         }
     }
 
diff --git a/opennms-services/src/main/java/org/opennms/netmgt/collectd/SnmpAttribute.java b/opennms-services/src/main/java/org/opennms/netmgt/collectd/SnmpAttribute.java
index c90fc90..11fac85 100644
--- a/opennms-services/src/main/java/org/opennms/netmgt/collectd/SnmpAttribute.java
+++ b/opennms-services/src/main/java/org/opennms/netmgt/collectd/SnmpAttribute.java
@@ -28,6 +28,9 @@
 
 package org.opennms.netmgt.collectd;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 import org.opennms.core.utils.ThreadCategory;
 import org.opennms.netmgt.config.collector.CollectionResource;
 import org.opennms.netmgt.config.collector.CollectionSetVisitor;
@@ -46,6 +49,7 @@ public class SnmpAttribute extends AbstractCollectionAttribute {
     private CollectionResource m_resource;
     private SnmpAttributeType m_type;
     private SnmpValue m_val;
+    private static Pattern NUMBER_PATTERN = Pattern.compile("[^\\d\\-\\+]*([\\+\\-]?\\d+(\\.\\d+)?).*");
 
     /**
      * <p>Constructor for SnmpAttribute.</p>
@@ -180,8 +184,14 @@ public class SnmpAttribute extends AbstractCollectionAttribute {
             try {
                 return Double.valueOf(getValue().toString()).toString();
             } catch(NumberFormatException e) {
-                log().trace("Unable to process data received for attribute " + this + " maybe this is not a number? See bug 1473 for more information. Skipping.");
-                return null;
+                Matcher m = NUMBER_PATTERN.matcher(getValue().toString());
+                if (m.find()) {
+                    String value = m.group(1);
+                    return value;
+                } else {
+                    log().trace("Unable to process data received for attribute " + this + " maybe this is not a number? See bug 1473 for more information. Skipping.");
+                    return null;
+                }
             }
         }
     }

Attachment: ibm-blade.xml
Description: XML document

Attachment: ibm-blade-graph.properties
Description: Binary data

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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