Skip to content

Commit

Permalink
Merge pull request #3 from renukamanavalan/remanava_events
Browse files Browse the repository at this point in the history
Integrate with BGP container
  • Loading branch information
renukamanavalan authored Jul 12, 2022
2 parents 8c03eb5 + e5be04f commit 076a6ac
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 30 deletions.
6 changes: 6 additions & 0 deletions dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ COPY ["TSC", "/usr/bin/TSC"]
COPY ["TS", "/usr/bin/TS"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["zsocket.sh", "/usr/bin/"]
COPY ["*.json", "/etc/rsyslog.d/"]
COPY ["files/rsyslog_plugin.conf.j2", "/etc/rsyslog.d/"]
RUN chmod a+x /usr/bin/TSA && \
chmod a+x /usr/bin/TSB && \
chmod a+x /usr/bin/TSC && \
chmod a+x /usr/bin/zsocket.sh

RUN j2 -f json /etc/rsyslog.d/rsyslog_plugin.conf.j2 /etc/rsyslog.d/events_info.json > /etc/rsyslog.d/bgp_events.conf
RUN rm -f /etc/rsyslog.d/rsyslog_plugin.conf.j2*
RUN rm -f /etc/rsyslog.d/events_info.json*

ENTRYPOINT ["/usr/bin/docker_init.sh"]
8 changes: 8 additions & 0 deletions dockers/docker-fpm-frr/bgp_regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"tag": "bgp-state",
"regex": "Peer .default\\|([0-9a-f:.]*[0-9a-f]*). admin state is set to .(up|down).",
"params": [ "peer_ip", "status" ]
}
]

10 changes: 10 additions & 0 deletions dockers/docker-fpm-frr/events_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"yang_module": "sonic-events-bgp",
"proclist": [
{
"name": "bgp",
"parse_json": "bgp_regex.json"
}
]
}

1 change: 1 addition & 0 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ start() {
{%- endif -%}
{%- if docker_container_name == "bgp" %}
-v /etc/sonic/frr/$DEV:/etc/frr:rw \
-v /usr/share/sonic/scripts:/usr/share/sonic/scripts:ro \
{%- endif %}
{%- if docker_container_name == "database" %}
$DB_OPT \
Expand Down
19 changes: 19 additions & 0 deletions files/build_templates/rsyslog_plugin.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## rsyslog-plugin for streaming telemetry via gnmi



template(name="prog_msg" type="list") {
property(name="msg")
constant(value="\n")
}

$ModLoad omprog

{% for proc in proclist %}
if re_match($programname, "{{ proc.name }}") then {
action(type="omprog"
binary="/usr/share/sonic/scripts/rsyslog_plugin -r /etc/rsyslog.d/{{ proc.parse_json }} -m {{ yang_module }}"
output="/var/log/rsyslog_plugin.log"
template="prog_msg")
}
{% endfor %}
5 changes: 4 additions & 1 deletion files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ sudo bash -c "echo { > $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ctr_image_name
{% endfor %}
sudo bash -c "echo } >> $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ctr_image_names.json"

# copy rsyslog plugin binary for use by all dockers that use plugin to publish events.
sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}
sudo cp ${files_path}/rsyslog_plugin ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/

{% for script in installer_start_scripts.split(' ') -%}
if [ -f $TARGET_MACHINE"_{{script}}" ]; then
sudo cp $TARGET_MACHINE"_{{script}}" $FILESYSTEM_ROOT/usr/bin/{{script}}
Expand Down Expand Up @@ -813,7 +817,6 @@ sudo LANG=C cp $SCRIPTS_DIR/bgp.sh $FILESYSTEM_ROOT/usr/local/bin/bgp.sh
sudo LANG=C cp $SCRIPTS_DIR/teamd.sh $FILESYSTEM_ROOT/usr/local/bin/teamd.sh
sudo LANG=C cp $SCRIPTS_DIR/lldp.sh $FILESYSTEM_ROOT/usr/local/bin/lldp.sh
sudo LANG=C cp $SCRIPTS_DIR/radv.sh $FILESYSTEM_ROOT/usr/local/bin/radv.sh
sudo LANG=C cp $SCRIPTS_DIR/eventd.sh $FILESYSTEM_ROOT/usr/local/bin/eventd.sh
sudo LANG=C cp $SCRIPTS_DIR/asic_status.sh $FILESYSTEM_ROOT/usr/local/bin/asic_status.sh
sudo LANG=C cp $SCRIPTS_DIR/asic_status.py $FILESYSTEM_ROOT/usr/local/bin/asic_status.py

Expand Down
5 changes: 4 additions & 1 deletion rules/docker-config-engine-bullseye.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ $(DOCKER_CONFIG_ENGINE_BULLSEYE)_DEPENDS += $(LIBSWSSCOMMON) \
$(LIBYANG_CPP) \
$(LIBYANG_PY3) \
$(PYTHON3_SWSSCOMMON) \
$(SONIC_DB_CLI)
$(SONIC_DB_CLI) \
$(SONIC_EVENTD)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_PYTHON_WHEELS += $(SWSSSDK_PY3)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3) \
$(SONIC_YANG_MGMT_PY3) \
$(SONIC_YANG_MODELS_PY3)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY3)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_LOAD_DOCKERS += $(DOCKER_BASE_BULLSEYE)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(SWSS_VARS_TEMPLATE)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(RSYSLOG_PLUGIN_CONF_J2)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(DOCKER_EVENTD)_PLUGIN)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT)

$(DOCKER_CONFIG_ENGINE_BULLSEYE)_DBG_DEPENDS = $($(DOCKER_BASE_BULLSEYE)_DBG_DEPENDS) \
Expand Down
1 change: 1 addition & 0 deletions rules/docker-config-engine-buster.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_PY_COMMON_PY3) \
$(DOCKER_CONFIG_ENGINE_BUSTER)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY3)
$(DOCKER_CONFIG_ENGINE_BUSTER)_LOAD_DOCKERS += $(DOCKER_BASE_BUSTER)
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(SWSS_VARS_TEMPLATE)
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $(RSYSLOG_PLUGIN_CONF_J2)
$(DOCKER_CONFIG_ENGINE_BUSTER)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT)

$(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS = $($(DOCKER_BASE_BUSTER)_DBG_DEPENDS) \
Expand Down
8 changes: 8 additions & 0 deletions rules/docker-eventd.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ $(DOCKER_EVENTD)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro

SONIC_BULLSEYE_DOCKERS += $(DOCKER_EVENTD)
SONIC_BULLSEYE_DBG_DOCKERS += $(DOCKER_EVENTD_DBG)

$(DOCKER_EVENTD)_FILESPATH = $($(SONIC_EVENTD)_SRC_PATH)/rsyslog_plugin

$(DOCKER_EVENTD)_PLUGIN = rsyslog_plugin
$($(DOCKER_EVENTD)_PLUGIN)_PATH = $($(DOCKER_EVENTD)_FILESPATH)

SONIC_COPY_FILES += $($(DOCKER_EVENTD)_PLUGIN)

4 changes: 4 additions & 0 deletions rules/scripts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ $(SWSS_VARS_TEMPLATE)_PATH = files/build_templates
COPP_CONFIG_TEMPLATE = copp_cfg.j2
$(COPP_CONFIG_TEMPLATE)_PATH = files/image_config/copp

RSYSLOG_PLUGIN_CONF_J2 = rsyslog_plugin.conf.j2
$(RSYSLOG_PLUGIN_CONF_J2)_PATH = files/build_templates

SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \
$(ARP_UPDATE_SCRIPT) \
$(ARP_UPDATE_VARS_TEMPLATE) \
Expand All @@ -42,4 +45,5 @@ SONIC_COPY_FILES += $(CONFIGDB_LOAD_SCRIPT) \
$(SYSCTL_NET_CONFIG) \
$(UPDATE_CHASSISDB_CONFIG_SCRIPT) \
$(SWSS_VARS_TEMPLATE) \
$(RSYSLOG_PLUGIN_CONF_J2) \
$(COPP_CONFIG_TEMPLATE)
6 changes: 4 additions & 2 deletions rules/telemetry.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

SONIC_TELEMETRY = sonic-telemetry_0.1_$(CONFIGURED_ARCH).deb
$(SONIC_TELEMETRY)_SRC_PATH = $(SRC_PATH)/sonic-telemetry
$(SONIC_TELEMETRY)_DEPENDS = $(SONIC_MGMT_COMMON) $(SONIC_MGMT_COMMON_CODEGEN)
$(SONIC_TELEMETRY)_RDEPENDS =
$(SONIC_TELEMETRY)_DEPENDS = $(SONIC_MGMT_COMMON) $(SONIC_MGMT_COMMON_CODEGEN) \
$(LIBSAIREDIS_DEV) $(LIBSAIMETADATA_DEV) $(LIBSWSSCOMMON_DEV) $(LIBSWSSCOMMON)
$(SONIC_TELEMETRY)_RDEPENDS = $(LIBSAIREDIS) $(LIBSAIMETADATA) \
$(LIBSWSSCOMMON) $(LIBSWSSCOMMON_DEV)
SONIC_DPKG_DEBS += $(SONIC_TELEMETRY)
6 changes: 3 additions & 3 deletions src/sonic-eventd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ RM := rm -rf
EVENTD_TARGET := eventd
EVENTD_TEST := tests/tests
EVENTD_TOOL := tools/events_tool
RSYSLOG-PLUGIN_TARGET := rsyslog_plugin
RSYSLOG-PLUGIN_TEST: rsyslog_plugin_tests/tests
RSYSLOG-PLUGIN_TARGET := rsyslog_plugin/rsyslog_plugin
RSYSLOG-PLUGIN_TEST := rsyslog_plugin_tests/tests
CP := cp
MKDIR := mkdir
CC := g++
Expand All @@ -26,7 +26,7 @@ endif
-include rsyslog_plugin/subdir.mk
-include rsyslog_plugin_tests/subdir.mk

all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests
all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin

sonic-eventd: $(OBJS)
@echo 'Building target: $@'
Expand Down
6 changes: 3 additions & 3 deletions src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <fstream>
#include <regex>
#include "rsyslog_plugin.h"
#include "common/json.hpp"
#include "json.hpp"

using json = nlohmann::json;

Expand All @@ -16,7 +16,7 @@ bool RsyslogPlugin::onMessage(string msg) {
} else {
int returnCode = event_publish(m_eventHandle, tag, &paramDict);
if (returnCode != 0) {
SWSS_LOG_ERROR("rsyslog_plugin was not able to publish event for %s. last thrown event error: %d\n", tag.c_str(), event_last_error());
SWSS_LOG_ERROR("rsyslog_plugin was not able to publish event for %s.\n", tag.c_str());
return false;
}
return true;
Expand Down Expand Up @@ -64,7 +64,7 @@ bool RsyslogPlugin::createRegexList() {
return true;
}

[[noreturn]] void RsyslogPlugin::run() {
void RsyslogPlugin::run() {
while(true) {
string line;
getline(cin, line);
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-eventd/rsyslog_plugin/rsyslog_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <string>
#include <memory>
#include "syslog_parser.h"
#include "common/events.h"
#include "common/logger.h"
#include "events.h"
#include "logger.h"

using namespace std;
using namespace swss;
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-eventd/rsyslog_plugin/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ rsyslog_plugin/%.o: rsyslog_plugin/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
$(CC) -D__FILENAME__="$(subst rsyslog_plugin/,,$<)" $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$(@)" "$<"
@echo 'Finished building: $<
'@echo ' '
@echo 'Finished building: $<'
@echo ' '
2 changes: 1 addition & 1 deletion src/sonic-eventd/rsyslog_plugin/syslog_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>
#include "syslog_parser.h"
#include "common/logger.h"
#include "logger.h"

/**
* Parses syslog message and returns structured event
Expand Down
4 changes: 2 additions & 2 deletions src/sonic-eventd/rsyslog_plugin/syslog_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <vector>
#include <string>
#include <regex>
#include "common/json.hpp"
#include "common/events.h"
#include "json.hpp"
#include "events.h"

using namespace std;
using json = nlohmann::json;
Expand Down
24 changes: 11 additions & 13 deletions src/sonic-eventd/tools/events_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,22 @@ do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt
ASSERT(h != NULL, "Failed to get subscriber handle");

while(!term_receive) {
string key;
event_params_t params;
map_str_str_t evt;
int missed_cnt=-1;
event_receive_op_t evt;
map_str_str_t evtOp;

int rc = event_receive(h, key, params, missed_cnt);
if (rc != 0) {
ASSERT(rc == EAGAIN, "Failed to receive rc=%d index=%d\n",
rc, index);
evt = event_receive(h);
if (evt.rc != 0) {
ASSERT(evt.rc == EAGAIN, "Failed to receive rc=%d index=%d\n",
evt.rc, index);
continue;
}
ASSERT(!key.empty(), "received EMPTY key");
ASSERT(missed_cnt >= 0, "Missed count uninitialized");
ASSERT(!evt.key.empty(), "received EMPTY key");
ASSERT(evt.missed_cnt >= 0, "Missed count uninitialized");

total_missed += missed_cnt;
total_missed += evt.missed_cnt;

evt[key] = t_map_to_str(params);
(*fp) << t_map_to_str(evt) << "\n";
evtOp[evt.key] = t_map_to_str(evt.params);
(*fp) << t_map_to_str(evtOp) << "\n";
fp->flush();

if ((++index % PRINT_CHUNK_SZ) == 0) {
Expand Down

0 comments on commit 076a6ac

Please sign in to comment.