RegEx in DCI

Started by jdl, March 10, 2010, 07:24:11 PM

Previous topic - Next topic

jdl

Quick one...

How would you handle regex in the DCI transformation?

Let's say you poll an SNMP OID which returns a string similar to "MyVal=18#-99#AB_01".
You want to extract the "-99" and return an integer to graph it...

In Perl it would sth like $1 ~=/#(.+)#/ - if I'm right.

Regards,

Jdamien

jdl

#1
Well I'm glad I can answer myself this time ;-)

Solution is...

sub main()
{
  $1~="#(.*)#";
  return $1;
}


This script will return "-99" if I give it as input "MyVal=18#-99#AB_01".
And for those interested...

sub main()
{
   $1~="#(.*)#(.*)$";
   return $2;
}


This one will return "AB_01"

PS.: "main" not "Main"!!! Otherwise -> Error

JDamien