Forum: Cfengine Help
Subject: insert_lines, whitespace_policy, and regex characters
Author: bbomgardner
Link to topic: https://cfengine.com/forum/read.php?3,22046,22046#msg-22046
I have noticed that if I use whitespace_policy when inserting a string that has
regex characters in it cfengine does not escape them when it builds the regex
to search for.
I don't know if this something that should happen or not.
The goal of this example is to manage what syslog facilities are written to a
particular log file regardless of the number of tabs between the values.
bundle edit_line set_value_rev(o,delim,v)
{
body common control {
bundlesequence => { "test" };
}
bundle agent test {
files:
"/tmp/blah"
handle => "test_file",
comment => "This is my favorite file.",
edit_line =>
set_value_rev("*.info;mail.none;authpriv.none;cron.none","$(const.t)","/var/log/messages"),
create => "true";
}
bundle edit_line set_value_rev(o,delim,v)
{
field_edits:
".*$(delim)\s*$(v)",
comment => "Correct a variable definition",
edit_field => col("$(delim)","1","$(o)","set");
insert_lines:
"$(o)$(delim)$(v)",
comment => "Insert a variable definition",
whitespace_policy => { "ignore_imbedded" };
}
body edit_field col(split,col,newval,method)
{
field_separator => "$(split)";
select_field => "$(col)";
value_separator => ",";
field_value => "$(newval)";
field_operation => "$(method)";
extend_fields => "true";
allow_blank_fields => "true";
}
If /tmp/blah looks like this:
momo:~/.cfagent 0> cat /tmp/blah
*.info;mail.none;authpriv.none;cron.none
/var/log/messages
I get this output:
momo:~/.cfagent 0> bin/cf-agent -f test.cf -IK
Regular expression error "nothing to repeat" in expression
"*.info;mail.none;authpriv.none;cron.none\s+/var/log/messages" at 0
!! Could not parse regular expression
'*.info;mail.none;authpriv.none;cron.none\s+/var/log/messages'
-> Edited file /tmp/blah
momo:~/.cfagent 0> cat /tmp/blah
*.info;mail.none;authpriv.none;cron.none
/var/log/messages
*.info;mail.none;authpriv.none;cron.none /var/log/messages
Is this as designed? Or should I submit a bug report? (v3.1.5)
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine