Hello Nathan,

 

have you seen/read the wiki on Augeas' GitHub page already?

 

Read about how XPATH in used in Augeas:

https://github.com/hercules-team/augeas/wiki/Path-expressions

 

How you can insert new nodes to a Augeas tree:

https://github.com/hercules-team/augeas/wiki/Adding-nodes-to-the-tree

 

There is just one very useful short-cut, which is not mentioned on the wiki: 
Augeas will create any node you are about to use automatically, in case it 
doesn't exist.

 

> 1) creating 'tags' if not present

set $datadog/tags

… will create a 'tags' node (in last position) on root level if it doesn't 
exist yet, otherwise nothing will happen. ($datadog contains the path to your 
datadog.ini file)

 

> 2) checking the tag string for the presence of my key:value pair

Use 'print' or 'match' with a suitable xpath expression.

 

> 3) appending my key:value pair tag if not present

set $datadog/tags/<key> <value>

(Replace key and value with your strings) This will create a node with your key 
or update the existing node and assign it the value. This works as long as the 
key-string is unique.

 

Ciao,

Xavier.

 

 

From: [email protected] [mailto:[email protected]] 
On Behalf Of Nathan Valentine
Sent: Friday, March 04, 2016 7:58 PM
To: [email protected]
Subject: [augeas-devel] lens and query to append to a key:value pair in an INI 
file

 

Hey, folks.

 

Not sure if I'm stuck on a problem with my custom lens, my understanding of 
XPATH queries, or both (likely).

 

I'm trying to write a lens for the Datadog monitoring agent config file which 
is an INI file using ':' as the separator. I took the Puppet.lens and modified 
it ever so lightly. Here's a link for reference:

 

https://github.com/nrvale0/puppet-datadog-agent/blob/add_tag_define/lib/augeas/lenses/datadogagent.aug

 

And here's a snippet of a typical datadog.conf file:

 

https://gist.github.com/nrvale0/6fe12c3bcf7777340455

 

The motivation for writing the lens is I would like to be able to append new 
tags to /files/etc/dd-agent/datadog.conf/Main/tags but I'm unsure as to the 
best/correct way of:

 

1) creating 'tags' if not present

2) checking the tag string for the presence of my key:value pair

3) appending my key:value pair tag if not present

 

I'm also a little concerned that there will be a parse conflict with the INI 
file format of using colon as a delimeter and the values of the 'tags' entry 
having embedded colons but first things first..

 

Any advice would be greatly appreciated.

 

-- 

--- V

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to