Defining classes based on regexp comparison

21 views
Skip to first unread message

tentaculartentacle

unread,
Nov 20, 2014, 4:26:30 AM11/20/14
to help-c...@googlegroups.com
I suspect I'm approaching this the wrong way entirely:

vars:
 "myappversion"  string => execresult("/opt/myapp/bin/runme --version","noshell");
classes:
  "myapp_compliant" expression => strcmp("$(myappversion)","1.2.3-fix5");
  "myapp_fixable" expression => strcmp("$(myappversion)","1.2.3-.*"); ### doesnt work obviously
  "myapp_unfixable" should be defined if !myapp_compliant AND !myapp_fixable


Any tips on how to do achieve what I'm trying to do in the last two lines?


Neil Watson

unread,
Nov 20, 2014, 7:05:38 AM11/20/14
to help-c...@googlegroups.com
On Thu, Nov 20, 2014 at 01:26:30AM -0800, tentaculartentacle wrote:
> strcmp("$(myappversion)","1.2.3-fix5");
>   "myapp_fixable" expression => strcmp("$(myappversion)","1.2.3-.*");
> ### doesnt work obviously

I'm not clear on your intentions, but strcmp requires strings, not
expressions. See regcmp for expressions.

--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting: https://github.com/evolvethinking/delta_reporting
CFEngine policy: https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3
CFEngine support: http://evolvethinking.com

Ted Zlatanov

unread,
Nov 20, 2014, 9:18:39 AM11/20/14
to help-c...@googlegroups.com
On Thu, 20 Nov 2014 01:26:30 -0800 (PST) tentaculartentacle <fred.o...@gmail.com> wrote:

t> vars:
t> "myappversion" string => execresult("/opt/myapp/bin/runme
t> --version","noshell");
t> classes:
t> "myapp_compliant" expression => strcmp("$(myappversion)","1.2.3-fix5");
t> "myapp_fixable" expression => strcmp("$(myappversion)","1.2.3-.*");

# no need to quote var
"myapp_fixable" expression => regcmp($(myappversion), "1.2.3-.*");

t> "myapp_unfixable" should be defined if !myapp_compliant AND !myapp_fixable

# no need to quote var
"myapp_unfixable" not => regcmp($(myappversion), "1.2.3-.*");

If you did `myapp_unfixable` as `!myapp_compliant AND !myapp_fixable` then it could get
defined in an intermediate pass because the `execresult` hasn't been
evaluated. So it's better to define it only based on the contents of
the `execresult`.

Ted

Reply all
Reply to author
Forward
0 new messages