[augeas-devel] help with nrpe.cfg lens

Francis Giraldeau francis.giraldeau at revolutionlinux.com
Mon Aug 23 16:02:36 UTC 2010


Le lundi 09 août 2010 à 18:13 +0200, Marc Fournier a écrit : 
> Hello,
> 
> Thanks for you answer, Francis !
> 
> > There was 2 problems. First: look at the test. The lens that is tested
> > is "command", but the iteration is defined only in "lns", that's why
> > it matches only once. Your lens works when using "lns" for the test.
> > The second problem I see is the subtree of the command lens. This
> > subtree shouldn't be iterated. It doesn't prevent the lens from
> > working, but it doesn't seems make sens to allow iteration there.
> > 
> > If you need debugging, then you can use this trick:
> > 
> >    let _ = print_regexp(lens_ctype(some_fucked_lens))
> >    let _ = print_endline ""
> > 
> > The "ctype" is the actual regexp that will be used to match the input
> > file.
> 
> Excellent, I wasn't aware of these debugging functions. The error was
> obvious once you pointed it out...
> 
> > As for the tree, I would do at first a simple lens, try it, and see if
> > it fits the need with a use case.
> 
> I'm still having some trouble understanding how my subtree should be
> defined. The test2.aug you sent on friday (as well as most of the
> attempts I've been iterating on today) fails with a variation of this
> error:
> 
>  Expected:
> { 
>   { "command"
>     { "foo" = "bar" }
>     { "bar" = "baz" }
>   }
> }
> 
>  Actual:
> { 
>   { "command"
>     { "foo" = "bar" }
>   }
>   { "command"
>     { "bar" = "baz" }
>   }
> }
> 
> In the first case (the expected one), I would be able to use augtool
> this way: "set /files/etc/nrpe.cfg/command/foo bar". In the second one,
> augtool is used this way: "set /files/etc/nrpe.cfg/command[1]/foo bar"
> which I don't find as elegant...

The command "set /files/etc/nrpe.cfg/command/foo bar" on the "actual"
tree is working, because only one node is selected by the path. 

A problem occur when selecting nodes based on the value of a children: 

  test lns put sample after set "/*[ foo = 'bar' ]/bar" "buz" =  ?

because the path selects command[1], then a new node /command[1]/bar is
created with the value buz, and the value baz stays intact. We would
like the result

/command[1]/foo = bar
/command[2]/bar = buz

but the result is actualy

/command[1]/foo = bar
/command[1]/bar = buz
/command[2]/bar = baz

It will not match the tree regexp and fail miserably. It will work by
using two steps, first getting the node name from the search, then
setting the node value. There must not have two "foo" because many nodes
will match!

> o I'm actually wondering if it really is possible to define a subtree
> the way I'm trying to ? ie:
> 
> option1=bla
> command[foo]=bla
> command[bar]=blabla
> option2=blabla
> command[bla]=foobar
> 
> would be:
> 
> /files/etc/nrpe.cfg/option1
> /files/etc/nrpe.cfg/command/foo
> /files/etc/nrpe.cfg/command/bar
> /files/etc/nrpe.cfg/option2
> /files/etc/nrpe.cfg/command/bla

I don't think it's possible to get this tree. I get ambiguity, because
the number of commands node to collapse is star rep, and the number of
those sections are star rep. The sample config is nice, because each
"commands" sections like is isolated by an option. The maximum I think
it's possible is a tree like this: 

/files/etc/nrpe.cfg/option1
/files/etc/nrpe.cfg/command[1]/foo
/files/etc/nrpe.cfg/command[1]/bar
/files/etc/nrpe.cfg/option2
/files/etc/nrpe.cfg/command[2]/bla

And I even were not able to get it (see attached lens) the only tree I
get is:

  { "option1" = "bla" }
  { "option2" = "blabla" }
  { "command"
    { "bla" = "foobar" }
  }

Seems that the command nodes get overwritten with the last captured tree
node. (Could it be a bug?)

Cheer, 

Francis

-------------- next part --------------
module Nrpe = 

let sample = "option1=bla
command[foo]=bla
command[bar]=blabla
option2=blabla
command[bla]=foobar
"

let eol = Util.eol
let dels (s:string) = del s s 
let word = /[a-zA-Z0-9]+/
let eq = dels "="
let option = [ key word . eq . store word . eol ]
let inner = [ key word . dels "]" . eq . store word . eol ]
let commands = [ key "command" . dels "[" . inner . (dels "command[" . inner )* ]

let lns = (option . commands)*

test lns get sample = ?

test lns put sample after set "/command/bla" "blah" = ?



More information about the augeas-devel mailing list