On 09/09/2013 10:06 PM, David Lang wrote:
On Mon, 9 Sep 2013, Erik Steffl wrote:
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.
Ok, one new feature that was recently added was a separate namespace
that you can use that won't show up in $!
this is the $, namespace
so you can do
if isempty($!key) then
set $.filename="/var/log/no-such-key";
else
set $.filename="/var/log/%$!key%";
then you can use $.filename in your template.
Just tested this with new release 7.5.3 and the $.var part works but
it seems that isempty is returning false even for $!key that does nto
exists in json message (in fact there is no json message in this case.
if isempty($!yummlyLogOrigin!supportLevel) then
set $.supportLevel = "noSupportLevel";
else
set $.supportLevel = "someSupportLevel";
then I am using $.supportLevel in DynaFile template and end up with
'someSupportLevel' even thought this is in block where json parsing
failed (and the message is not json).
even tried:
if isempty($!yummlyLogOrigin!supportLevel) then
set $.supportLevel = "noSupportLevel";
else
set $.supportLevel = $!yummlyLogOrigin!supportLevel;
in which case the $.supportLevel ends up being empty.
running rsyslogd-dn reveals:
1929.256799878:7f86cdede700: scriptExec: batch of 1 elements, active
0x7f86c8000900, active[0]:1
1929.256805683:7f86cdede700: IF
1929.256817375:7f86cdede700: function 'isempty' (id:0, params:1)
1929.256836689:7f86cdede700: var '$!yummlyLogOrigin!supportLevel'
1929.256855896:7f86cdede700: eval expr 0x1b1a570, type 'F[70]'
1929.256862685:7f86cdede700: rainerscript: executing function id 0
1929.256869302:7f86cdede700: rainerscript: invalid function id 0 (name
'isempty')
it seems that I cannot use ismepty as a function. I don't see isempty
mentioned in rainerscript docs at
http://www.rsyslog.com/doc/rainerscript.html but I see isempty
documented here http://www.rsyslog.com/doc/rsyslog_conf_filter.html but
not sure if that means it can be used in if (and how).
also tried:
if $!yummlyLogOrigin!supportLevel == "" then
which seems to be working, is that the best way to test if there is
no value for $!yummlyLogOrigin!supportLevel?
thanks!
erik
_______________________________________________
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.