Leading spaces in SNMP values: Bug in process_poller_output?

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
geofs
Posts: 6
Joined: Wed Jun 13, 2007 7:42 am

Leading spaces in SNMP values: Bug in process_poller_output?

Post by geofs »

Hi,

I had problems removing leading spaces from snmp values. I kept getting NaNs in my graphs.

I use VALUE/REGEXP in my snmp query XML.

SNMP Output:

Code: Select all

.1.3.6.1.4.1.2.3.51.1.2.20.1.5.1.1.3.1 = STRING: "  43.00 Centigrade"
Regex:

Code: Select all

<source>VALUE/REGEXP: *([0-9]{1,3}\.[0-9]{1,3}).*</source>
I inserted a little debug line in process_poller_output. This is what I get:

Code: Select all

06/21/2007 03:00:39 PM - POLLER: Poller[0] Output field value: '  43.00'
Notice the spaces before 43.00

I tried various syntaxes like

Code: Select all

<source>VALUE/REGEXP: *([0-9]{1,3}\.[0-9]{1,3}).*</source>
<source>VALUE/REGEXP: +([0-9]{1,3}\.[0-9]{1,3}).*</source>
<source>VALUE/REGEXP:[ ]*([0-9]{1,3}\.[0-9]{1,3}).*</source>
<source>VALUE/REGEXP:\s+([0-9]{1,3}\.[0-9]{1,3}).*</source>
Nothing works. I finally browsed through the poller.php code and modified it this way:

Code: Select all

        if (sizeof($results) > 0) {
                /* create an array keyed off of each .rrd file */
                foreach ($results as $item) {
-                       $value = rtrim(strtr(strtr($item["output"],'\r',''),'\n',''));
+                      $value = ltrim(rtrim(strtr(strtr($item["output"],'\r',''),'\n','')));
                        $unix_time = strtotime($item["time"]);
And now my graph works.

Is there a correct REGEXP syntax or is this a bug?

Thanks!
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

The field is a string, hence they way it is parsed.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
geofs
Posts: 6
Joined: Wed Jun 13, 2007 7:42 am

Post by geofs »

rony wrote:The field is a string, hence they way it is parsed.
Ok. So what is the correct way to extract the numeric value? Make a script? Btw there should be a way to get rid of those (mis-)leading spaces?
geofs
Posts: 6
Joined: Wed Jun 13, 2007 7:42 am

Post by geofs »

When I graph similar values via the OID field in a data template, it works. It seems that leading spaces, text and units are removed automatically. I still haven't found how to achieve the same result with VALUE/REGEXP.

Please can someone give some advice on this? It works with my little hack but I'd prefer to do without.

I tried a lot of possibilities but none worked.

Thanks,
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

Try it with the "trim" instead of "rtrim" and "ltrim". The trim command takes away both leading and trailing blanks, tabs and carriage returns, and a few other things from a string. Also, strtr is no longer required (so I have learned over the years now).

So the command would be:

Code: Select all

$value = trim($tem["output"]);
Let me know if that get's it.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest