Skip to content

Commit a6d4909

Browse files
pkableoplklum
authored andcommitted
Event and alarm management (sonic-net#22617)
1 parent 5161281 commit a6d4909

26 files changed

+1961
-8
lines changed

dockers/docker-database/database_config.json.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@
140140
"instance" : {% if include_remote_db %} "remote_redis" {% else %} "redis" {% endif %}
141141
}
142142
{% else %}
143+
,
144+
"EVENT_DB" : {
145+
"id" : 19,
146+
"separator": "|",
147+
"instance" : "redis"
148+
}
143149
,
144150
"BMP_STATE_DB" : {
145151
"id" : 20,

dockers/docker-eventd/Dockerfile.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
3636
COPY ["critical_processes", "/etc/supervisor"]
3737
COPY ["*.json", "/etc/rsyslog.d/rsyslog_plugin_conf/"]
3838
COPY ["files/rsyslog_plugin.conf.j2", "/etc/rsyslog.d/rsyslog_plugin_conf/"]
39+
COPY ["eventdb_wrapper.sh", "/usr/bin"]
3940

4041
RUN j2 -f json /etc/rsyslog.d/rsyslog_plugin_conf/rsyslog_plugin.conf.j2 /etc/rsyslog.d/rsyslog_plugin_conf/host_events_info.json > /etc/rsyslog.d/rsyslog_plugin_conf/host_events.conf
4142
RUN j2 -f json /etc/rsyslog.d/rsyslog_plugin_conf/rsyslog_plugin.conf.j2 /etc/rsyslog.d/rsyslog_plugin_conf/bgp_events_info.json > /etc/rsyslog.d/rsyslog_plugin_conf/bgp_events.conf
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
JSON_FILE="/etc/evprofile/default.json"
4+
5+
# Check if file exists and is not empty
6+
if [ -s "$JSON_FILE" ]; then
7+
# Check if "events" is defined and has at least one entry
8+
if jq -e '.events and (.events | length > 0)' "$JSON_FILE" > /dev/null; then
9+
echo "Valid events found. Starting eventdb."
10+
exec /usr/bin/eventdb
11+
else
12+
echo "'events' list is missing or empty. Skipping eventdb start."
13+
exit 0
14+
fi
15+
else
16+
echo "JSON file missing or empty. Skipping eventdb start."
17+
exit 0
18+
fi

dockers/docker-eventd/supervisord.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,15 @@ stderr_logfile=syslog
5050
dependent_startup=true
5151
dependent_startup_wait_for=start:exited
5252

53+
[program:eventdb]
54+
command=/usr/bin/eventdb_wrapper.sh
55+
priority=3
56+
autostart=false
57+
autorestart=false
58+
startsecs=0
59+
startretries=0
60+
exitcodes=0
61+
stdout_logfile=syslog
62+
stderr_logfile=syslog
63+
dependent_startup=true
64+
dependent_startup_wait_for=start:exited

files/build_templates/docker_image_ctl.j2

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,17 @@ function preStartAction()
9494
# Load redis content from /host/warmboot/dump.rdb
9595
docker cp $WARM_DIR/dump.rdb database$DEV:/var/lib/redis/dump.rdb
9696
else
97-
# Create an emtpy file and overwrite any RDB if already there
98-
echo -n > /tmp/dump.rdb
99-
docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/
100-
docker cp /tmp/dump.rdb database$DEV:/var/lib/redis_bmp/
97+
COLD_DIR=/host/coldboot
98+
#In case of cold reboot, load redis content from /host/coldboot/dump.rdb
99+
if [[ -f $COLD_DIR/dump.rdb ]]; then
100+
#Load redis content from /host/coldboot/dump.rdb
101+
docker cp $COLD_DIR/dump.rdb database$DEV:/var/lib/redis/dump.rdb
102+
else
103+
# Create an emtpy file and overwrite any RDB if already there
104+
echo -n > /tmp/dump.rdb
105+
docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/
106+
docker cp /tmp/dump.rdb database$DEV:/var/lib/redis_bmp/
107+
fi
101108
fi
102109
fi
103110
{%- elif docker_container_name == "pde" %}

src/sonic-eventd/Makefile

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
RM := rm -rf
22
EVENTD_TARGET := eventd
33
EVENTD_TEST := tests/tests
4+
EVENTDB_TEST := tests/eventdb
45
EVENTD_TOOL := tools/events_tool
56
EVENTD_PUBLISH_TOOL := tools/events_publish_tool.py
67
RSYSLOG-PLUGIN_TARGET := rsyslog_plugin/rsyslog_plugin
78
RSYSLOG-PLUGIN_TEST := rsyslog_plugin_tests/tests
89
EVENTD_MONIT := tools/events_monit_test.py
910
EVENTD_MONIT_CONF := tools/monit_events
11+
EVENTDB_TARGET := eventdb
12+
EVENTDB_DEFAULT_PROFILE := var/evprofile/default.json
13+
EVENTDB_PROF := etc/eventd.json
1014

1115
CP := cp
1216
MKDIR := mkdir
@@ -19,7 +23,7 @@ PWD := $(shell pwd)
1923

2024
ifneq ($(MAKECMDGOALS),clean)
2125
ifneq ($(strip $(C_DEPS)),)
22-
-include $(C_DEPS) $(OBJS)
26+
-include $(C_DEPS) $(OBJS) $(EVENTDB_OBJS)
2327
endif
2428
endif
2529

@@ -29,7 +33,7 @@ endif
2933
-include rsyslog_plugin/subdir.mk
3034
-include rsyslog_plugin_tests/subdir.mk
3135

32-
all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests
36+
all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests sonic-eventdb eventdb-tests
3337

3438
sonic-eventd: $(OBJS)
3539
@echo 'Building target: $@'
@@ -38,13 +42,29 @@ sonic-eventd: $(OBJS)
3842
@echo 'Finished building target: $@'
3943
@echo ' '
4044

45+
sonic-eventdb: $(EVENTDB_OBJS)
46+
@echo 'Building target: $@'
47+
@echo 'Invoking: G++ Linker'
48+
$(CC) $(LDFLAGS) -o $(EVENTDB_TARGET) $(EVENTDB_OBJS) $(LIBS)
49+
@echo 'Finished building target: $@'
50+
@echo ' '
51+
4152
eventd-tool: $(TOOL_OBJS)
4253
@echo 'Building target: $@'
4354
@echo 'Invoking: G++ Linker'
4455
$(CC) $(LDFLAGS) -o $(EVENTD_TOOL) $(TOOL_OBJS) $(LIBS)
4556
@echo 'Finished building target: $@'
4657
@echo ' '
4758

59+
eventdb-tests: $(EVENTDB_TEST_OBJS)
60+
@echo 'Building target: $@'
61+
@echo 'Invoking: G++ Linker'
62+
$(CC) $(LDFLAGS) -o $(EVENTDB_TEST) $(EVENTDB_TEST_OBJS) $(LIBS) $(TEST_LIBS)
63+
@echo 'Finished building target: $@'
64+
$(EVENTDB_TEST)
65+
@echo 'Finished running tests'
66+
@echo ' '
67+
4868
rsyslog-plugin: $(RSYSLOG-PLUGIN_OBJS)
4969
@echo 'Buidling Target: $@'
5070
@echo 'Invoking: G++ Linker'
@@ -73,12 +93,16 @@ rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS)
7393
install:
7494
$(MKDIR) -p $(DESTDIR)/usr/bin
7595
$(MKDIR) -p $(DESTDIR)/etc/monit/conf.d
96+
$(MKDIR) -p $(DESTDIR)/etc/evprofile
7697
$(CP) $(EVENTD_TARGET) $(DESTDIR)/usr/bin
7798
$(CP) $(EVENTD_TOOL) $(DESTDIR)/usr/bin
7899
$(CP) $(EVENTD_PUBLISH_TOOL) $(DESTDIR)/usr/bin
79100
$(CP) $(RSYSLOG-PLUGIN_TARGET) $(DESTDIR)/usr/bin
80101
$(CP) $(EVENTD_MONIT) $(DESTDIR)/usr/bin
81102
$(CP) $(EVENTD_MONIT_CONF) $(DESTDIR)/etc/monit/conf.d
103+
$(CP) $(EVENTDB_TARGET) $(DESTDIR)/usr/bin
104+
$(CP) $(EVENTDB_PROF) $(DESTDIR)/etc/eventd.json
105+
$(CP) $(EVENTDB_DEFAULT_PROFILE) $(DESTDIR)/etc/evprofile/default.json
82106

83107
deinstall:
84108
$(RM) -rf $(DESTDIR)/usr
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
usr/bin/eventd
2+
usr/bin/eventdb
23
usr/bin/events_tool
34
usr/bin/events_publish_tool.py
5+
etc/evprofile/default.json
6+
etc/eventd.json

src/sonic-eventd/etc/eventd.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"__README__": "Specify size of event history table. Whichever limit is hit first, eventd wraps event history table around and deletes older records.",
3+
"max-records": 40000,
4+
"max-days": 30
5+
}

0 commit comments

Comments
 (0)