Skip to content

Commit

Permalink
Move event_publish_tool to sbin (#26)
Browse files Browse the repository at this point in the history
* Add conf to host, move plugin to sbin

* Add missing comma in dependencies

* Correct flag to -p

* Fix events_info and j2

* Add host event

* Revert back to creating and moving

* Split into multiple regex for each process

* Modify regex and set .py to sbin in monit_events

* Change log level from err to notice

* Move publish tool to sbin

* Remove has_timer from init cfg

* Add peer review changes

* Change to /usr/bin

* Remove empty lines

* Change monit_events
  • Loading branch information
zbud-msft authored Sep 16, 2022
1 parent d65e511 commit 2cd2385
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 46 deletions.
2 changes: 1 addition & 1 deletion dockers/docker-eventd/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependent_startup_wait_for=rsyslogd:running


[program:eventd]
command=/usr/sbin/eventd
command=/usr/bin/eventd
priority=3
autostart=false
autorestart=false
Expand Down
4 changes: 2 additions & 2 deletions dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RUN chmod a+x /usr/bin/TSA && \
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*
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"]
2 changes: 1 addition & 1 deletion files/build_templates/init_cfg.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
("pmon", "enabled", false, "enabled"),
("radv", "enabled", false, "enabled"),
("snmp", "enabled", true, "enabled"),
("eventd", "enabled", true, "enabled"),
("eventd", "enabled", false, "enabled"),
("swss", "enabled", false, "enabled"),
("syncd", "enabled", false, "enabled"),
("teamd", "enabled", false, "enabled")] %}
Expand Down
2 changes: 1 addition & 1 deletion files/build_templates/rsyslog_plugin.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ModLoad omprog
{% for proc in proclist %}
if re_match($programname, "{{ proc.name }}") then {
action(type="omprog"
binary="/usr/sbin/rsyslog_plugin -r /etc/rsyslog.d/{{ proc.parse_json }} -m {{ yang_module }}"
binary="/usr/bin/rsyslog_plugin -r /etc/rsyslog.d/{{ proc.parse_json }} -m {{ yang_module }}"
output="/var/log/rsyslog_plugin.log"
template="prog_msg")
}
Expand Down
2 changes: 1 addition & 1 deletion slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(PYTHON_SWSSCOMMON) \
$(PYTHON3_SWSSCOMMON) \
$(SONIC_DB_CLI) \
$(SONIC_RSYSLOG_PLUGIN) \
$(SONIC_RSYSLOG_PLUGIN) \
$(SONIC_UTILITIES_DATA) \
$(SONIC_HOST_SERVICES_DATA) \
$(BASH) \
Expand Down
12 changes: 6 additions & 6 deletions src/sonic-eventd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS)
@echo ' '

install:
$(MKDIR) -p $(DESTDIR)/usr/sbin
$(MKDIR) -p $(DESTDIR)/usr/bin
$(MKDIR) -p $(DESTDIR)/etc/monit/conf.d
$(CP) $(EVENTD_TARGET) $(DESTDIR)/usr/sbin
$(CP) $(EVENTD_TOOL) $(DESTDIR)/usr/sbin
$(CP) $(EVENTD_PUBLISH_TOOL) $(DESTDIR)/usr/sbin
$(CP) $(RSYSLOG-PLUGIN_TARGET) $(DESTDIR)/usr/sbin
$(CP) $(EVENTD_MONIT) $(DESTDIR)/usr/sbin
$(CP) $(EVENTD_TARGET) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_TOOL) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_PUBLISH_TOOL) $(DESTDIR)/usr/bin
$(CP) $(RSYSLOG-PLUGIN_TARGET) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_MONIT) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_MONIT_CONF) $(DESTDIR)/etc/monit/conf.d

deinstall:
Expand Down
5 changes: 3 additions & 2 deletions src/sonic-eventd/debian/sonic-eventd.install
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
usr/sbin/eventd
usr/sbin/events_tool
usr/bin/eventd
usr/bin/events_tool
usr/bin/events_publish_tool.py
4 changes: 2 additions & 2 deletions src/sonic-eventd/debian/sonic-rsyslog-plugin.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
usr/sbin/rsyslog_plugin
usr/sbin/events_monit_test.py
usr/bin/rsyslog_plugin
usr/bin/events_monit_test.py
etc/monit/conf.d/monit_events
46 changes: 17 additions & 29 deletions src/sonic-eventd/tools/events_monit_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python -u
#! /usr/bin/env python3

from inspect import getframeinfo, stack
from swsscommon.swsscommon import events_init_publisher, event_publish, FieldValueMap
Expand All @@ -25,11 +25,11 @@

# Async connection wait time in milliseconds.
ASYNC_CONN_WAIT = 300

RECEIVE_TIMEOUT = 1000

# Thread results
rc_test_receive = -1

publish_cnt = 0

def _log_msg(lvl, pfx, msg):
if lvl <= chk_log_level:
Expand Down Expand Up @@ -60,28 +60,32 @@ def map_dict_fvm(s, d):
def test_receiver(event_obj, cnt):
global rc_test_receive

sh = events_init_subscriber()
sh = events_init_subscriber(false, RECEIVE_TIMEOUT, null)

# Sleep ASYNC_CONN_WAIT to ensure async connectivity is complete.
time.sleep(ASYNC_CONN_WAIT/1000)

exp_params = dict(test_event_params)

# Signal main thread that subscriber is ready to receive
event_obj.set()
cnt_done = 0

for i in range(cnt):
while cnt_done < cnt:
p = event_receive_op_t()
rc = event_receive(sh, p)

if rc > 0 && publish_cnt < 2:
# ignore timeout as test code has not yet published an event yet
continue

if (rc != 0):
if rc != 0:
log_notice("Failed to receive. {}/{} rc={}".format(i, cnt, rc))
break

if test_event_key != p.key:
log_notice("key mismatch {} != {} {}/{}".format(test_event_key,
p.key, i, cnt))
break
# received a different event than published
continue

exp_params["index"] = str(i)
rcv_params = {}
Expand Down Expand Up @@ -117,20 +121,8 @@ def test_receiver(event_obj, cnt):
else:
log_notice("test receive abort {}/{}".format(cnt_done, cnt))

# wait for a max of 5 secs for main thread to clear the event.
tout = 5000
while(event_obj.is_set()):
# main thread yet to consume last set event
if tout > 0:
t_sleep = 100
time.sleep(t_sleep / 1000)
tout -= t_sleep
else:
log_notice("test_receiver:Internal err: event not cleared by main")
break

# Signal main thread that subscriber thread is done
event_obj.set()

events_deinit_subscriber(sh)


Expand All @@ -157,6 +149,7 @@ def publish_events(cnt):
log_notice("Failed to publish. {}/{} rc={}".format(i, cnt, rc))
break
log_debug("published: {}/{}".format(i+1, cnt))
publish_cnt += 1

# Sleep ASYNC_CONN_WAIT to ensure publish complete, before closing channel.
time.sleep(ASYNC_CONN_WAIT/1000)
Expand All @@ -179,6 +172,8 @@ def run_test(cnt):
thread_sub = threading.Thread(target=test_receiver, args=(event_sub, cnt))
thread_sub.start()

# Wait until subscriber thread completes the async subscription
# Any event published prior to that could get lost
# Subscriber would wait for ASYNC_CONN_WAIT. Wait additional 200ms
# for signal from test_receiver as ready.
event_sub.wait((ASYNC_CONN_WAIT + 200)/1000)
Expand Down Expand Up @@ -227,10 +222,3 @@ def main():

if __name__ == "__main__":
main()







2 changes: 1 addition & 1 deletion src/sonic-eventd/tools/monit_events
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###############################################################################
## Monit configuration for telemetry container
###############################################################################
check program container_eventd with path "/usr/sbin/events_monit_test.py"
check program container_eventd with path "/usr/bin/events_monit_test.py"
every 5 cycles
if status != 0 for 3 cycle then alert repeat every 1 cycles

0 comments on commit 2cd2385

Please sign in to comment.