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

syslog-ng-ctl config to print pre-processed configuration #2280

Merged
merged 4 commits into from Sep 18, 2018

Conversation

Kokan
Copy link
Collaborator

@Kokan Kokan commented Sep 14, 2018

Currently there is no way to tell what configuration syslog-ng has in effect.
Sure the file in the disk can be checked, and most of the time it would be save to assume the active config and the disk content are equal.

This gives an opportunity to both get the content of the top level configuration file and also the preprocessed configuration.

The way it could be queried via syslog-ng-ctl:

> syslog-ng-ctl 
Syntax: /tmp/install/sbin/syslog-ng-ctl <command> [options]
Possible commands are:
    stats                Get syslog-ng statistics in CSV format
...
    config               Print current config

This prints the top level configuration file:

> syslog-ng-ctl config

With an option --preprocess it prints the preprocessed version of the config:

> syslog-ng-ctl config --preprocessed

@bazsi
Copy link
Collaborator

bazsi commented Sep 14, 2018

This is a good idea, but is it also that it gives you the preprocessed configuration? I would have the assumption that it would return the one that matches the disk file.

OTOH, it is true, that include files wouldn't be part of that, whereas this one contains them.

In that case, I think I would rename the syslog-ng-ctl command to reflect this fact, e.g. syslog-ng-ctl preprocessed-config (which I don't like too much) or running-config (if that's enough to indicate that it might not be equal to disk file) or something else. the key that it should be clear that it is different.

@Kokan
Copy link
Collaborator Author

Kokan commented Sep 14, 2018

I was thinking about to make it possible to provide the original configuration and in such case add an additional option to syslog-ng-ctl config for example --preprocessed.

It was a quick patch, I did not want to complicate things. But you have a valid point, this should be cleared now.

Does this alternatives look good to you ?
syslog-ng-ctl config would return with the config without preprocessing.
syslog-ng-ctl config --preprocessed would return with the preprocessed configuration

This syntax would support an option like --verify later on, which could check against the config stored on disk.

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@kira-syslogng
Copy link
Contributor

Build SUCCESS

@Kokan Kokan added the user-visible-feature User visible feature label Sep 17, 2018
@gaborznagy gaborznagy self-requested a review September 18, 2018 07:05
lib/cfg.c Show resolved Hide resolved
lib/cfg.c Outdated
gsize res;
GString *result = g_string_new("");

while ((res = fread(buf, 1, sizeof(buf), fd)) > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional:
If the goal is just to read the content, you could use g_file_get_contents.
https://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-file-get-contents

Though in the end you need GString, though I would still use a library function to read into cstring, then convert to glib, as it would result in cleaner code, and performance is not important here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, actually I wanted to get such function but my query was not successful, and I did not try that hard.

lib/cfg.c Outdated

lexer = cfg_lexer_new_buffer(self, config_string, strlen(config_string));
lexer->preprocess_output = preprocess_output;
if (!fd)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to log the reason here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is opened again where the reason not able to open a file is logged. I wanted to avoid logging the same thing twice (the two open's result could differ, but I think that has a low chanse, while this failing this open is not critical, while the other is.)

Signed-off-by: Kokan <kokaipeter@gmail.com>
Signed-off-by: Kokan <kokaipeter@gmail.com>
Signed-off-by: Kokan <kokaipeter@gmail.com>
Signed-off-by: Kokan <kokaipeter@gmail.com>
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@gaborznagy gaborznagy merged commit d8ad085 into syslog-ng:master Sep 18, 2018
@Kokan Kokan deleted the ctl-cat-config branch September 21, 2018 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-visible-feature User visible feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants