Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review docs and enhance cover of "variables": global, JSON message properties, local variables and "properties" #592

Open
deoren opened this issue Feb 27, 2018 · 10 comments

Comments

@deoren
Copy link
Contributor

deoren commented Feb 27, 2018

From a mailing list post:

I am set the variables and using them in filters. But the following are not working as expected or not working at all.
Appreciate if you can share a working example or suggest what i am doing wrong.

Not Working:
set $!configuredseverity = "3";
if ($syslogseverity <= $configuredseverity)

Defaults to severity 7:
set $!configuredseverity = 3;
if ($syslogseverity <= $configuredseverity)

My response:

rsyslog has three types of "variables":

  • global variables
  • JSON message properties
  • local variables

rsyslog also has "properties". The syntax used to access the variables and properties differs slightly depending on the configuration format syntax that you use to access them which is unfortunate, but needed for backwards compatibility (at least for now).

The syntax and scope of each also differs.

This PDF[3] of an article by David Lang gives a great overview of rsyslog as a whole, but in particular the syntax used to access each "variable" type. See the "User Variables" section of the PDF for details.

In your case, I believe (untested) that this is probably the syntax you're looking for:

set $!configuredseverity = "3";
if ($syslogseverity &lt;= $!configuredseverity) then {
doSomethingHere
}

Note the '$!' prefix for configuredseverity. The '$!' is needed when referencing JSON message properties. This is covered in the rsyslog docs, but here and there. For now, I recommend looking at the PDF instead for a concise overview.

References:

[1] http://www.rsyslog.com/doc/v8-stable/configuration/properties.html

[2] http://www.rsyslog.com/doc/v8-stable/rainerscript/variable_property_types.html

[3] https://www.usenix.org/publications/login/october-2013-volume-38-number-5/log-filtering-rsyslog

While it could have just been me flailing about in fatigue, I suspect that the information is spread thinly throughout the docs.

It would be good to find the most appropriate section and enhance it to cover everything I mentioned plus any supporting information that would be useful. We could then reference that section (via an explicit label) in other places to ease maintenance, create an include page with succinct coverage or (perhaps the better approach) do both.

I'm not sure of any potential permissions issues with using the material, but @davidelang's coverage of the topic in his Log Filtering with Rsyslog ;login article is especially good.

@davidelang
Copy link
Contributor

davidelang commented Mar 1, 2018 via email

@deoren
Copy link
Contributor Author

deoren commented Mar 1, 2018

@davidelang Awesome, thanks!

@deoren
Copy link
Contributor Author

deoren commented Mar 14, 2018

@davidelang I was looking back through the mailing list for something else and came across this response from you last year:

there is almost no technical difference between $. variables and $! variables.

$! existed first, and some functions (mmjsonparse) only put things in $!

$. was created because there is a need to have variables that aren't part of $! so that $! can be output in it's entirety.

The global variables $\ are significantly different, much slower, but visible across multiple log messages (and multiple threads), while $! and $. exist only for the one log message.

Adding it here as further reference material for when this ticket is processed.

You have a talent for conveying depth with brevity. :)

@davidelang
Copy link
Contributor

davidelang commented Mar 14, 2018 via email

@deoren
Copy link
Contributor Author

deoren commented Mar 14, 2018

@davidelang: normally I'm told I put too much detail in :-)

Down with the naysayers! ;) I've learned a lot reading your writings and appreciate the time you've taken to provide them.

Aside from the articles here (https://www.usenix.org/publications/login/david-lang-series), your writings on GitHub, the mailing list and the docs project, do you publish content elsewhere?

@davidelang
Copy link
Contributor

davidelang commented Mar 14, 2018 via email

@deoren
Copy link
Contributor Author

deoren commented Mar 15, 2018

@davidelang: I don't think the last article in the series ever got linked on that page
(splung/ElasticSearch tuning)

Is this the article you're referring to?

"Large Scale Splunk Tuning" at https://www.usenix.org/publications/login/april14/lang

@davidelang
Copy link
Contributor

davidelang commented Mar 16, 2018 via email

@deoren
Copy link
Contributor Author

deoren commented Mar 28, 2018

@atc0005
Copy link
Contributor

atc0005 commented Jun 17, 2019

Saw these remarks elsewhere from @rgerhards, figured the notes were relevant here (though the context for each may not be sufficiently clear for each remark to stand by itself as included here):

global variable updates are guarded by a mutex. So they are atomic.


https://www.rsyslog.com/doc/master/rainerscript/variable_property_types.html?highlight=variables


Set the var e.g. to zero and then increment it whenever you need. There is also a random function which you can use to init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants