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

Add rsyslog plugin and tests #2

Merged
merged 8 commits into from
Jun 27, 2022
Merged

Add rsyslog plugin and tests #2

merged 8 commits into from
Jun 27, 2022

Conversation

zbud-msft
Copy link
Collaborator

- What I did

Add rsyslog plugin that will parse messages coming from rsyslog.d and call events publish api

- How I did it
Created c++ plugin that will parse each message given a list of regex expressions, parameters
- How to verify it
Run tests
- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/syslog_parser.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/syslog_parser.cpp Outdated Show resolved Hide resolved
src/sonic-eventd/rsyslog_plugin/syslog_parser.cpp Outdated Show resolved Hide resolved

if(regex_path.empty() || module_name.empty()) { // Missing required rc path
cerr << "Error: Missing regex_path and module_name." << endl;
return 1;

Choose a reason for hiding this comment

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

1

Since there are multiple exit reason, let's define multiple return code, and user macro name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return 1;
}

RsyslogPlugin* plugin = new RsyslogPlugin(module_name, regex_path);

Choose a reason for hiding this comment

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

new

memory leak. Suggest use smart pointer

Choose a reason for hiding this comment

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

I believe LGTM could catch this kind of critical bug. Suggest you raise a draft PR to public repo, so you will have all PR checkers result, like build/lgtm/coverage.

Copy link
Owner

Choose a reason for hiding this comment

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

new

memory leak. Suggest use smart pointer

There is no mem leak here, as process exits at that point. Said that, valgrind will not be happy and it is always a good idea to make clean exit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to smart pointer.

@@ -0,0 +1,83 @@
RM := rm -rf

Choose a reason for hiding this comment

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

The other components in this repo is using Debian package build infra, not plain Makefile. Could you adapt?

Copy link
Owner

Choose a reason for hiding this comment

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

This is using debian package -- pretty similar to dhcp-relay

RsyslogPlugin* plugin = new RsyslogPlugin(module_name, regex_path);
if(!plugin->onInit()) {
SWSS_LOG_ERROR("Rsyslog plugin was not able to be initialized.\n");
return 1;

Choose a reason for hiding this comment

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

Mixing tabs and spaces, prefer 4-space each indentation level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

event_params_t param_dict;
if(!m_parser->parseMessage(msg, tag, param_dict)) {
SWSS_LOG_DEBUG("%s was not able to be parsed into a structured event\n", msg.c_str());
return false;

Choose a reason for hiding this comment

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

The same. Please check all the files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

vector<string> params = m_parser->m_regex_list[i]["params"];
regex expr(regex_string);
expression = expr;
} catch (exception& exception) {

Choose a reason for hiding this comment

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

exception

Do not catch general exception in normal use cases. It will hide bugs. Use more specific types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

class SyslogParser {
public:
vector<regex> m_expressions;
json m_regex_list = json::array();

Choose a reason for hiding this comment

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

m_regex_list

Naming convention: m_regexList

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

return false;
}

SyslogParser::SyslogParser(vector<regex> expressions, json regex_list) {

Choose a reason for hiding this comment

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

vector

copy ctor of vector and json are expensive. Use const reference?

Copy link
Owner

Choose a reason for hiding this comment

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

The args are redundant. You may drop them, as you are constructing with empty objects and manipulating the objects directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed args

void run();
RsyslogPlugin(string module_name, string regex_path);
private:
SyslogParser* m_parser;
Copy link
Owner

@renukamanavalan renukamanavalan Jun 19, 2022

Choose a reason for hiding this comment

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

In line with Qi's comments, you may make this shared-ptr too, so it gets deleted when this object gets deleted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using smart pointer now

@zbud-msft zbud-msft merged commit b80b884 into renukamanavalan:syslog_telemetry_shared Jun 27, 2022
renukamanavalan pushed a commit that referenced this pull request Jan 14, 2023
#### Why I did it
Update sonic-host-services submodule to include below commits:
```
bc8698d Merge pull request #21 from abdosi/feature
557a110 Fix the issue where if dest port is not specified in ACL rule than for multi-asic where we create NAT rule to forward traffic from Namespace to host fail with exception.
6e45acc (master) Merge pull request #14 from abdosi/feature
4d6cad7 Merge remote-tracking branch 'upstream/master' into feature
bceb13e Install libyang to azure pipeline (#20)
82299f5 Merge pull request #13 from SuvarnaMeenakshi/cacl_fabricns
15d3bf4 Merge branch 'master' into cacl_fabricns
de54082 Merge pull request #16 from ZhaohuiS/feature/caclmgrd_external_client_warning_log
b4b368d Add warning log if destination port is not defined
d4bb96d Merge branch 'master' into cacl_fabricns
35c76cb Add unit-test and fix typo.
17d44c2 Made Changes to be Python 3.7 compatible
978afb5 Aligning Code
1fbf8fb Merge remote-tracking branch 'upstream/master' into feature
7b8c7d1 Added UT for the changes
91c4c42 Merge pull request #9 from ZhaohuiS/feature/caclmgrd_external_client
7c0b56a Add 4 test cases for external_client_acl, including single port and port range for ipv4 and ipv6
b71e507 Merge remote-tracking branch 'origin/master' into HEAD
d992dc0 Merge branch 'master' into feature/caclmgrd_external_client
bd7b172 DST_PORT is configuralbe in json config file for EXTERNAL_CLIENT_ACL
f9af7ae [CLI] Move hostname, mgmt interface/vrf config to hostcfgd (#2)
70ce6a3 Merge pull request #10 from sujinmkang/cold_reset
29be8d2 Added Support to render Feature Table using Device running metadata. Also added support to render 'has_asic_scope' field of Feature Table.
3437e35 [caclmgrd][chassis]: Add ip tables rules to accept internal docker traffic from fabric asic namespaces.
8720561 Fix and add hardware reboot cause determination tests
0dcc7fe remove the empty bracket if no hardware reboot cause minor
e47d831 fix the wrong expected result comparision
ef86b53 Fix startswith Attribute error
8a630bb fix mock patch
8543ddf update the reboot cause logic and update the unit test
53ad7cd fix the mock patch function
7c8003d fix the reboot-cause regix for test
1ba611f fix typo
25379d3 Add unit test case
a56133b Add hardware reboot cause as actual reboot cause for soft reboot failed
c7d3833 Support Restapi/gnmi control plane acls
f6ea036 caclmgrd: Don't block traffic to mgmt by default
a712fc4 Update test cases
adc058b caclmgrd: Don't block traffic to mgmt by default
06ff918 Merge pull request #7 from bluecmd/patch-1
e3e23bc ci: Rename sonic-buildimage repository
e83a858 Merge pull request #4 from kamelnetworks/acl-ip2me-test
f5a2e50 [caclmgrd]: Tests for IP2ME rules generation
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants