Re: [rsyslog] What is the syntax for comparing a global variable against a local variable?

2018-03-06 Thread deoren

On 3/6/2018 2:53 AM, Rainer Gerhards wrote:

2018-03-06 9:04 GMT+01:00 deoren
:

On 3/6/2018 1:43 AM, Rainer Gerhards wrote:


2018-03-05 19:17 GMT+01:00 deoren
:


Hi,

When refactoring an older configuration I figured I would give global
variables a try.

I'm attempting to create a generic email notification ruleset that can be
called after setting values in a subtree of the $.email-notification
local
variable.

Example (email templates and associated ruleset not included here):

set $/default-email-notification!sender = 'rsyslog-ale...@example.com';
set $/default-email-notification!recipient = 'rsyslog-ad...@example.com';
set $/default-email-notification!subject-template =
'email-notification-standard-subject';
set $/default-email-notification!body-template =
'email-notification-standard-body';
set $/default-email-notification!server-ip = '127.0.0.1';
set $/default-email-notification!server-port = '25';

action(
  name="email-alert-action"
  type="ommail"
  server="$.email-notification!server-ip"
  port="$.email-notification!server-port"
  mailfrom="$.email-notification!sender"
  mailto="$.email-notification!recipient"
  subject.template="$.email-notification!subject-template"
  template="$.email-notification!body-template"
  body.enable="on"

  # The parameter is included for every client request, so if we do
  # not apply some sort of rate limiting we will be flooded in a
  # very short amount of time.
  # Note: The interval is configured in number of seconds.
  action.execonlyonceeveryinterval=$.email-notification!interval
)



But I think the above will not work, as the parameters must be constant
strings.

Rainer



I ended up learning that the hard way. It's too bad really, as that felt
like a really good place to have support for variables.


For ommail, I would in theory not be such a big problem to support
these things, but in general this would be immensely
performance-hungry. In the concrete case, however, there is no
plumbing at all in the module interface/rsyslog core for this, so it
would probably require weeks of refactoring to make it happen. And for
almost all other cases you really don't want to have that capability,
as it slows down things very, very considerably.

Rainer


Thanks for explaining. As you've noted, the time investment sounds like 
it would be better spent elsewhere.

___
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.


Re: [rsyslog] What is the syntax for comparing a global variable against a local variable?

2018-03-06 Thread Rainer Gerhards
2018-03-06 9:04 GMT+01:00 deoren
:
> On 3/6/2018 1:43 AM, Rainer Gerhards wrote:
>>
>> 2018-03-05 19:17 GMT+01:00 deoren
>> :
>>>
>>> Hi,
>>>
>>> When refactoring an older configuration I figured I would give global
>>> variables a try.
>>>
>>> I'm attempting to create a generic email notification ruleset that can be
>>> called after setting values in a subtree of the $.email-notification
>>> local
>>> variable.
>>>
>>> Example (email templates and associated ruleset not included here):
>>>
>>> set $/default-email-notification!sender = 'rsyslog-ale...@example.com';
>>> set $/default-email-notification!recipient = 'rsyslog-ad...@example.com';
>>> set $/default-email-notification!subject-template =
>>> 'email-notification-standard-subject';
>>> set $/default-email-notification!body-template =
>>> 'email-notification-standard-body';
>>> set $/default-email-notification!server-ip = '127.0.0.1';
>>> set $/default-email-notification!server-port = '25';
>>>
>>> action(
>>>  name="email-alert-action"
>>>  type="ommail"
>>>  server="$.email-notification!server-ip"
>>>  port="$.email-notification!server-port"
>>>  mailfrom="$.email-notification!sender"
>>>  mailto="$.email-notification!recipient"
>>>  subject.template="$.email-notification!subject-template"
>>>  template="$.email-notification!body-template"
>>>  body.enable="on"
>>>
>>>  # The parameter is included for every client request, so if we do
>>>  # not apply some sort of rate limiting we will be flooded in a
>>>  # very short amount of time.
>>>  # Note: The interval is configured in number of seconds.
>>>  action.execonlyonceeveryinterval=$.email-notification!interval
>>> )
>>
>>
>> But I think the above will not work, as the parameters must be constant
>> strings.
>>
>> Rainer
>
>
> I ended up learning that the hard way. It's too bad really, as that felt
> like a really good place to have support for variables.

For ommail, I would in theory not be such a big problem to support
these things, but in general this would be immensely
performance-hungry. In the concrete case, however, there is no
plumbing at all in the module interface/rsyslog core for this, so it
would probably require weeks of refactoring to make it happen. And for
almost all other cases you really don't want to have that capability,
as it slows down things very, very considerably.

Rainer
>
> The workaround (for me) was to create a common email body template and a
> common email subject template. I then set common values for the majority of
> each template and then added a variable reference at the end of each
> template.
>
> Then from applicable rulesets I used string concatenation (tie together
> constant strings with local variables and message properties) to build what
> I wanted the latter parts of the templates to contain and assigned the
> result to that last variable in the templates.
>
> It feels like an odd way to go about it, so I'm sure I'm doing something
> wrong. It works though and gives me something flexible I can use now until I
> learn a better way to go about it.
>
> Example:
>
> template(name="email-notification-standard-subject" type="list") {
>
> constant(value="RSYSLOG Alert from ")
> property(name="$myhostname")
> constant(value=" for ")
> # Set by a lookup table in a ruleset tied to an
> # input on the receiver
> property(name="$.hostname")
> constant(value=": ")
> property(name="$.email-notification!subject!topic")
>
> }
>
> In the rulesets, I use an approach similar to this (the simplest example):
>
> if ($programname == 'rsyslogd') then {
> if ($msg contains "Permission denied") then {
> set $.email-notification!subject!topic = $msg;
> call email-prod-notification
>
> }
> }
>
> ___
> 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.


Re: [rsyslog] What is the syntax for comparing a global variable against a local variable?

2018-03-06 Thread deoren

On 3/6/2018 1:43 AM, Rainer Gerhards wrote:

2018-03-05 19:17 GMT+01:00 deoren
:

Hi,

When refactoring an older configuration I figured I would give global
variables a try.

I'm attempting to create a generic email notification ruleset that can be
called after setting values in a subtree of the $.email-notification local
variable.

Example (email templates and associated ruleset not included here):

set $/default-email-notification!sender = 'rsyslog-ale...@example.com';
set $/default-email-notification!recipient = 'rsyslog-ad...@example.com';
set $/default-email-notification!subject-template =
'email-notification-standard-subject';
set $/default-email-notification!body-template =
'email-notification-standard-body';
set $/default-email-notification!server-ip = '127.0.0.1';
set $/default-email-notification!server-port = '25';

action(
 name="email-alert-action"
 type="ommail"
 server="$.email-notification!server-ip"
 port="$.email-notification!server-port"
 mailfrom="$.email-notification!sender"
 mailto="$.email-notification!recipient"
 subject.template="$.email-notification!subject-template"
 template="$.email-notification!body-template"
 body.enable="on"

 # The parameter is included for every client request, so if we do
 # not apply some sort of rate limiting we will be flooded in a
 # very short amount of time.
 # Note: The interval is configured in number of seconds.
 action.execonlyonceeveryinterval=$.email-notification!interval
)


But I think the above will not work, as the parameters must be constant strings.

Rainer


I ended up learning that the hard way. It's too bad really, as that felt 
like a really good place to have support for variables.


The workaround (for me) was to create a common email body template and a 
common email subject template. I then set common values for the majority 
of each template and then added a variable reference at the end of each 
template.


Then from applicable rulesets I used string concatenation (tie together 
constant strings with local variables and message properties) to build 
what I wanted the latter parts of the templates to contain and assigned 
the result to that last variable in the templates.


It feels like an odd way to go about it, so I'm sure I'm doing something 
wrong. It works though and gives me something flexible I can use now 
until I learn a better way to go about it.


Example:

template(name="email-notification-standard-subject" type="list") {

constant(value="RSYSLOG Alert from ")
property(name="$myhostname")
constant(value=" for ")
# Set by a lookup table in a ruleset tied to an
# input on the receiver
property(name="$.hostname")
constant(value=": ")
property(name="$.email-notification!subject!topic")

}

In the rulesets, I use an approach similar to this (the simplest example):

if ($programname == 'rsyslogd') then {
if ($msg contains "Permission denied") then {
set $.email-notification!subject!topic = $msg;
call email-prod-notification
}
}

___
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.


Re: [rsyslog] What is the syntax for comparing a global variable against a local variable?

2018-03-05 Thread Rainer Gerhards
2018-03-05 19:17 GMT+01:00 deoren
:
> Hi,
>
> When refactoring an older configuration I figured I would give global
> variables a try.
>
> I'm attempting to create a generic email notification ruleset that can be
> called after setting values in a subtree of the $.email-notification local
> variable.
>
> Example (email templates and associated ruleset not included here):
>
> set $/default-email-notification!sender = 'rsyslog-ale...@example.com';
> set $/default-email-notification!recipient = 'rsyslog-ad...@example.com';
> set $/default-email-notification!subject-template =
> 'email-notification-standard-subject';
> set $/default-email-notification!body-template =
> 'email-notification-standard-body';
> set $/default-email-notification!server-ip = '127.0.0.1';
> set $/default-email-notification!server-port = '25';
>
> action(
> name="email-alert-action"
> type="ommail"
> server="$.email-notification!server-ip"
> port="$.email-notification!server-port"
> mailfrom="$.email-notification!sender"
> mailto="$.email-notification!recipient"
> subject.template="$.email-notification!subject-template"
> template="$.email-notification!body-template"
> body.enable="on"
>
> # The parameter is included for every client request, so if we do
> # not apply some sort of rate limiting we will be flooded in a
> # very short amount of time.
> # Note: The interval is configured in number of seconds.
> action.execonlyonceeveryinterval=$.email-notification!interval
> )

But I think the above will not work, as the parameters must be constant strings.

Rainer
>
> If I opt to not supply some values, I'd like to fallback to using global
> variables for those values.
>
> I am attempting something like this:
>
> if $.email-notification!sender == '' then {
> $.email-notification!sender = $/default-email-notification!sender;
> }
>
> and I'm getting errors:
>
> rsyslogd: error during parsing file /etc/rsyslog.conf, on or before line 89:
> invalid character '$' - is there an invalid escape sequence somewhere?
> [v8.34.0.08efa27d0aa2 try http://www.rsyslog.com/e/2207 ]
> rsyslogd: invalid character in selector line - ';template' expected
> [v8.34.0.08efa27d0aa2]
>
> I'm also getting errors for attempting to use a variable with
> action.execonlyonceeveryinterval, but I figured I would handle that issue
> separately (not sure if that is a bug or if rsyslog just doesn't support
> using variables in some places).
> ___
> 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.


Re: [rsyslog] What is the syntax for comparing a global variable against a local variable?

2018-03-05 Thread deoren

On 3/5/2018 7:48 PM, David Lang wrote:

On Mon, 5 Mar 2018, deoren wrote:


if $.email-notification!sender == '' then {
   $.email-notification!sender = $/default-email-notification!sender;


This needs to be set $.email-notification!sender = 
$/default-email-notification!sender;


(you forgot the 'set')


Heh, too funny. Forest for the trees ...

Thank you for pointing out what I should have seen!
___
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.

Re: [rsyslog] What is the syntax for comparing a global variable against a local variable?

2018-03-05 Thread David Lang

On Mon, 5 Mar 2018, deoren wrote:


if $.email-notification!sender == '' then {
   $.email-notification!sender = $/default-email-notification!sender;


This needs to be set $.email-notification!sender = 
$/default-email-notification!sender;

(you forgot the 'set')
___
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.