Autom8 Tree Rules and multi-line Notes fields

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
User avatar
gninja
Cacti User
Posts: 371
Joined: Tue Aug 24, 2004 5:02 pm
Location: San Francisco, CA
Contact:

Autom8 Tree Rules and multi-line Notes fields

Post by gninja »

I've got my host.notes field populated with multi-line text similar to:

Code: Select all

Location:soma
Product:downloads
Purpose:www
I've got a tree rule that should be creating a 'soma' branch on the Location tree, but I can't seem to find a clean way to deal with the multi-line output.

My Matching pattern is currently:

Code: Select all

^.*Location:(.*?)\s.*$
and my Replacement pattern is:

Code: Select all

${1}
But I end up with a tree leaf named:

Code: Select all

soma Product:downloads Purpose:www
If I update the matching pattern to explicitly check for product & purpose:

Code: Select all

^.*Location(.*?)\nProduct:.*\nPurpose:.*$
.. then it creates the right Tree branch, but if I expand the data I'm storing in the notes field, then I'll have to keep updating the notes field.

Any advice on how to more cleanly accomplish this?
FreeBSD/RHEL
cacti-0.8.7i, spine 0.8.7i, PIA 3.1+boost 5.1
MySQL 5.5/InnoDB
RRDtool 1.2.27, PHP 5.1.6
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Autom8 Tree Rules and multi-line Notes fields

Post by gandalf »

You're ending the rexexp by searching for a \s (whitespace); but not searching for an LF while "soma" seems to be directly followed by an LF. Well, it may happen, that php-regexp acts a bit strange ... not sure ...
R.
User avatar
gninja
Cacti User
Posts: 371
Joined: Tue Aug 24, 2004 5:02 pm
Location: San Francisco, CA
Contact:

Re: Autom8 Tree Rules and multi-line Notes fields

Post by gninja »

Yes. I'm looking for a way to get it to be greedy about matching text and multiple newlines.
FreeBSD/RHEL
cacti-0.8.7i, spine 0.8.7i, PIA 3.1+boost 5.1
MySQL 5.5/InnoDB
RRDtool 1.2.27, PHP 5.1.6
User avatar
gninja
Cacti User
Posts: 371
Joined: Tue Aug 24, 2004 5:02 pm
Location: San Francisco, CA
Contact:

Re: Autom8 Tree Rules and multi-line Notes fields

Post by gninja »

The results I'm getting make it seem like it doesn't matter if I use \n or \s in the match string.
FreeBSD/RHEL
cacti-0.8.7i, spine 0.8.7i, PIA 3.1+boost 5.1
MySQL 5.5/InnoDB
RRDtool 1.2.27, PHP 5.1.6
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Autom8 Tree Rules and multi-line Notes fields

Post by gandalf »

Does this help:
http://de2.php.net/manual/en/function.preg-match.php
//match newline control character:
preg_match('/\n/','\n'); //pattern matches and is stored as control character 0x0A in the pattern string
preg_match('/\\\n/','\n'); //very same match, but is stored escaped as 0x5C,0x6E in the pattern string
R.
User avatar
gninja
Cacti User
Posts: 371
Joined: Tue Aug 24, 2004 5:02 pm
Location: San Francisco, CA
Contact:

Re: Autom8 Tree Rules and multi-line Notes fields

Post by gninja »

Nope. I seem to have solved it with this, though:

Code: Select all

.*Location:(.*?)\n(.*[\n]?)+
FreeBSD/RHEL
cacti-0.8.7i, spine 0.8.7i, PIA 3.1+boost 5.1
MySQL 5.5/InnoDB
RRDtool 1.2.27, PHP 5.1.6
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Autom8 Tree Rules and multi-line Notes fields

Post by gandalf »

fine, then
R.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests