On 09/09/2013 08:00 PM, David Lang wrote:
On Mon, 9 Sep 2013, Erik Steffl wrote:

On 09/09/2013 07:22 PM, David Lang wrote:
On Mon, 9 Sep 2013, Erik Steffl wrote:

Using a property in template (after action(type="mmjsonparse")
succeeds):

property(name="$!key!anotherKey")

Is there a way to specify default value (just a string constant,
nothing dynamic) that should be used in case incoming messages do not
have $key!anotherKey element?

not directly, but you can do:

if isempty($!key!anotherKey) then $!key!anotherKey=default

 that changes the parsed json structure though which I was hoping to
avoid,

huh? how does it change it any more than setting a default value for
$!key!anotherKey would?

I do not want to set $!key!anotherKey to the default value, I want to use a default value in template if there is no value in incoming message for $!key!anotherKey

template(name="dynamicFilename" type="list") {
  constant(value="/var/log/")
  property(name="$!key")
}

I would like to achieve:

  - if there is no "key" in icoming message, e.g. @cee:{"a":"b"}
filename would be: /var/log/no-such-key

  - if there is "key" in incoming message, e.g. @cee:{"key":"got-a-key"}
filename would be: /var/log/got-a-key

I would like to achieve the above, preferably without changing the parsed incoming message. In other words I would like to use the property $!key if it exists, otherwise use a default value.

 also was thinking that regexp match might work - match at least one
character and if no match use regex.NoMatchMode (DFLT or ZERO might
work). Seem like it might not be good for performance, it would add 7
regular expressions to each message (the regular expression would be
pretty simple, something like '^.+$' so it might not be that bad)

regular expressions are very expensive, I don't understand what you
think you are gaining?

it illustrates what I am trying to achieve, i.e. the default would be used when template is evaluated but the parsed incoming message would not be changed.

        erik


David Lang
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad
of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you
DON'T LIKE THAT.

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to