hi Andres,

the %user action list variable gets indeed overwritten if multiple
deployments for different services are ongoing simultaneously. However, you
can utilize DEPLOY_STARTED_<service> context for storing the user name for
the given service (provided that you are not using this context already for
storing other event data). Saving the user name into the event store of the
context can be accomplished with the 'add action, for example:

add DEPLOY_STARTED_$+{service} $+{user}

If you augment your first rule with this action, the rule might look as
follows:

type=Single
ptype=PerlFunc
pattern=sub { if ($_[0] =~ /({.+\"status\":\"started\".+})/) { \
              return SecJson::json2matchvar($1); } return 0; }
context=!DEPLOY_STARTED_$+{service}
continue=TakeNext
desc=Started deploy of service $+{service} by user $+{user}
action=create DEPLOY_STARTED_$+{service} 1800; add
DEPLOY_STARTED_$+{service} $+{user}

For retrieving the user name from the event store of the service context,
the 'copy' action can be harnessed in the second rule. For example, the
following modification to the rule will get the user name from context and
assign it to the %user action list variable, and %user variable is then
employed by the 'write' action:

type=Single
ptype=PerlFunc
pattern=sub { if ($_[0] =~ /({ .+\"message":\".+\",
\"service_name\":\".+\", \"region\":\".+\" })/) { \
              return SecJson::json2matchvar($1); } return 0; }
context=DEPLOY_STARTED_$+{service}
continue=TakeNext
desc=Container was killed by service
action=copy DEPLOY_STARTED_$+{service} %user; \
       write $+{service_name}_$+{region}_%user

A small side note -- if DEPLOY_STARTED_<service> context is not used
anywhere else in your rule base and its only purpose is to just connect
above two rules together, you could also consider deleting the context with
'delete' action in the second rule (but that will entirely depend on the
nature of your rule base).

Hope this helps,
risto

Kontakt Andres Pihlak (<apih...@gmail.com>) kirjutas kuupƤeval T, 26.
november 2019 kell 15:05:

> Hello,
>
> I have rule that creates context if software deploy is started. The json
> message also consists user variable which I like to pass on to second rule
> that do not have this user in the pattern. Tried multiple solutions but
> unfortunately I was unable to do that.
>
> * First rule creates context DEPLOY_STARTED_myservice. And I want to pass
> $+{user} variable to other rule. I tried to pass this argument with "assign
> %user $+{user}" but this raises problem that if the same time other deploy
> is started then this user variable is overwritten and second rule gets
> wrong username.
> type=Single
> ptype=PerlFunc
> pattern=sub { if ($_[0] =~ /({.+\"status\":\"started\".+})/) { \
>               return SecJson::json2matchvar($1); } return 0; }
> context=!DEPLOY_STARTED_$+{service}
> continue=TakeNext
> desc=Started deploy of service $+{service} by user $+{user}
> action=create DEPLOY_STARTED_$+{service} 1800
>
> * Second rule waits that context DEPLOY_STARTED_myservice is created and I
> need to pass user parameter to this rule. User do not exists on the pattern.
> type=Single
> ptype=PerlFunc
> pattern=sub { if ($_[0] =~ /({ .+\"message":\".+\",
> \"service_name\":\".+\", \"region\":\".+\" })/) { \
>               return SecJson::json2matchvar($1); } return 0; }
> context=DEPLOY_STARTED_$+{service}
> continue=TakeNext
> desc=Container was killed by service
> action=write $+{service_name}_$+{region}_$+{user};
>
> Regards,
> Andres
> _______________________________________________
> Simple-evcorr-users mailing list
> Simple-evcorr-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users
>
_______________________________________________
Simple-evcorr-users mailing list
Simple-evcorr-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users

Reply via email to