Skip to content

Event and alarm management#22617

Merged
Praveen-Brcm merged 26 commits into
sonic-net:masterfrom
bhaveshdell:eventd-comm
May 14, 2026
Merged

Event and alarm management#22617
Praveen-Brcm merged 26 commits into
sonic-net:masterfrom
bhaveshdell:eventd-comm

Conversation

@bhaveshdell

@bhaveshdell bhaveshdell commented May 14, 2025

Copy link
Copy Markdown
Contributor

Why I did it
This PR contains code changes for providing extension to the Event Framework as specified in the sonic-net/SONiC#1409

How I did it
Followed design specified in sonic-net/SONiC#1409.

How to verify it
Unit tests added.

This PR was originally reviewed and merged.
#17949

However, due to build error post-merge the PR was reverted.
#20052

The possible fix for build error has been fixed as per comments in PR
#20064

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 22617 in repo sonic-net/sonic-buildimage

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 22617 in repo sonic-net/sonic-buildimage

@prsunny

prsunny commented May 20, 2025

Copy link
Copy Markdown
Contributor

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@prsunny

prsunny commented May 20, 2025

Copy link
Copy Markdown
Contributor

/AzurePipelines run Azure.sonic-buildimage

@bhaveshdell , you can try with /azpw run Azure.sonic-buildimage

@venkatmahalingam

Copy link
Copy Markdown
Collaborator

/azpw run Azure.sonic-buildimage

@mssonicbld

Copy link
Copy Markdown
Collaborator

Only PR owner can use /azpw run

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azpw run Azure.sonic-buildimage

@mssonicbld

Copy link
Copy Markdown
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@zhangyanzhao

Copy link
Copy Markdown

/azpw run Azure.sonic-buildimage

@mssonicbld

Copy link
Copy Markdown
Collaborator

Only PR owner can use /azpw run

@qiluo-msft qiluo-msft requested a review from Copilot June 5, 2025 17:42
@qiluo-msft

qiluo-msft commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage #Closed

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the existing Event Framework by introducing alarm management via a new YANG model and by adding a standalone eventdb service alongside adjustments to eventd. Key changes include:

  • Adding sonic-alarm.yang to define alarm state and statistics.
  • Introducing eventdb daemon: source code, build/test integration, Debian install, and supervisor configuration.
  • Updating build scripts, test configs, and Docker templates to support both eventd and eventdb.

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/sonic-yang-models/yang-models/sonic-alarm.yang New YANG module for alarm operational data
src/sonic-eventd/var/evprofile/default.json Empty default event profile
src/sonic-eventd/tests/subdir.mk Added eventdb_ut dependency
src/sonic-eventd/tests/eventdb_database_config_*.json Test database config for eventdb
src/sonic-eventd/tests/eventd.json eventd JSON config for history limits
src/sonic-eventd/src/subdir.mk Added eventdb build/test object lists
src/sonic-eventd/src/loghandler.{h,cpp} Syslog helper API for events/alarm logging
src/sonic-eventd/src/eventutils.{h,cpp} Parsing utilities for JSON configs and event profiles
src/sonic-eventd/src/eventdb.cpp Entry point for eventdb, signal handling
src/sonic-eventd/src/eventconsume.{h,cpp} Core logic for consuming events and updating stats
src/sonic-eventd/etc/eventd.json Default eventd config
src/sonic-eventd/debian/sonic-eventd.install Install rules for eventdb and its configs
src/sonic-eventd/Makefile New eventdb targets and test targets
files/build_templates/docker_image_ctl.j2 Cold-boot Redis load logic
dockers/docker-eventd/supervisord.conf Added eventdb supervisord program
dockers/docker-database/database_config.json.j2 Added EVENT_DB mapping
Comments suppressed due to low confidence (2)

src/sonic-yang-models/yang-models/sonic-alarm.yang:96

  • The id leaf in ALARM_STATS_LIST uses an enumeration with only a single member state and no explicit value; this is likely incomplete. Define all intended enum values with associated numeric values or revisit the choice of type.
type enumeration {

files/build_templates/docker_image_ctl.j2:103

  • Typo in comment: change emtpy to empty.
# Create an emtpy file and overwrite any RDB if already there

Comment thread src/sonic-eventd/src/loghandler.h Outdated
Comment thread src/sonic-eventd/src/loghandler.cpp Outdated
extern "C" void writeToSyslog(std::string ev_id, int ev_sev, std::string ev_type, std::string ev_act, std::string ev_msg, std::string ev_static_msg) {
int SYSLOG_FACILITY = LOG_LOCAL4;
if (ev_act.empty()) {
const char LOG_FORMAT[] = "[%s], %%%s: %s %s";

Copilot AI Jun 5, 2025

Copy link

Choose a reason for hiding this comment

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

The format string uses %%%s, which will emit a literal % before the %s. It should likely be %s instead of %%%s to correctly interpolate the event name.

Suggested change
const char LOG_FORMAT[] = "[%s], %%%s: %s %s";
const char LOG_FORMAT[] = "[%s], %s: %s %s";

Copilot uses AI. Check for mistakes.
Comment thread src/sonic-eventd/src/eventutils.h Outdated
Comment on lines +7 to +22
using namespace std;

const string EVENT_SEVERITY_CRITICAL_STR = "CRITICAL";
const string EVENT_SEVERITY_MAJOR_STR = "MAJOR";
const string EVENT_SEVERITY_MINOR_STR = "MINOR";
const string EVENT_SEVERITY_WARNING_STR = "WARNING";
const string EVENT_SEVERITY_INFORMATIONAL_STR = "INFORMATIONAL";

const string EVENT_ENABLE_TRUE_STR = "true";
const string EVENT_ENABLE_FALSE_STR = "false";

const string EVENT_ACTION_RAISE_STR = "RAISE";
const string EVENT_ACTION_CLEAR_STR = "CLEAR";
const string EVENT_ACTION_ACK_STR = "ACKNOWLEDGE";
const string EVENT_ACTION_UNACK_STR = "UNACKNOWLEDGE";

Copilot AI Jun 5, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Avoid using namespace std; in a header file to prevent namespace pollution; qualify standard types explicitly.

Suggested change
using namespace std;
const string EVENT_SEVERITY_CRITICAL_STR = "CRITICAL";
const string EVENT_SEVERITY_MAJOR_STR = "MAJOR";
const string EVENT_SEVERITY_MINOR_STR = "MINOR";
const string EVENT_SEVERITY_WARNING_STR = "WARNING";
const string EVENT_SEVERITY_INFORMATIONAL_STR = "INFORMATIONAL";
const string EVENT_ENABLE_TRUE_STR = "true";
const string EVENT_ENABLE_FALSE_STR = "false";
const string EVENT_ACTION_RAISE_STR = "RAISE";
const string EVENT_ACTION_CLEAR_STR = "CLEAR";
const string EVENT_ACTION_ACK_STR = "ACKNOWLEDGE";
const string EVENT_ACTION_UNACK_STR = "UNACKNOWLEDGE";
const std::string EVENT_SEVERITY_CRITICAL_STR = "CRITICAL";
const std::string EVENT_SEVERITY_MAJOR_STR = "MAJOR";
const std::string EVENT_SEVERITY_MINOR_STR = "MINOR";
const std::string EVENT_SEVERITY_WARNING_STR = "WARNING";
const std::string EVENT_SEVERITY_INFORMATIONAL_STR = "INFORMATIONAL";
const std::string EVENT_ENABLE_TRUE_STR = "true";
const std::string EVENT_ENABLE_FALSE_STR = "false";
const std::string EVENT_ACTION_RAISE_STR = "RAISE";
const std::string EVENT_ACTION_CLEAR_STR = "CLEAR";
const std::string EVENT_ACTION_ACK_STR = "ACKNOWLEDGE";
const std::string EVENT_ACTION_UNACK_STR = "UNACKNOWLEDGE";
``` #Closed

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is a valid comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Will address the comments

Comment thread src/sonic-eventd/src/eventdb.cpp Outdated
Comment on lines +4 to +10
static EventConsume *evtd_instance = NULL;

void signalHandler(const int signal) {
SWSS_LOG_NOTICE("in signalHandler");

if (signal == SIGINT) {
evtd_instance->read_eventd_config();

Copilot AI Jun 5, 2025

Copy link

Choose a reason for hiding this comment

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

Calling non-async-signal-safe functions inside a signal handler is unsafe and can cause undefined behavior. Consider deferring configuration reload to the main loop or using a flag checked outside the handler.

Suggested change
static EventConsume *evtd_instance = NULL;
void signalHandler(const int signal) {
SWSS_LOG_NOTICE("in signalHandler");
if (signal == SIGINT) {
evtd_instance->read_eventd_config();
#include <atomic>
static EventConsume *evtd_instance = NULL;
static std::atomic<bool> reload_config_flag(false);
void signalHandler(const int signal) {
SWSS_LOG_NOTICE("in signalHandler");
if (signal == SIGINT) {
reload_config_flag.store(true);

Copilot uses AI. Check for mistakes.
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azpw run Azure.sonic-buildimage

@yxieca

yxieca commented May 9, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

- database_config.json.j2: Add 'is defined' guard for include_system_eventd
- Dockerfile.j2: Add ENV INCLUDE_SYSTEM_EVENTD to bake build-time flag into container
- docker-database-init.sh: Pass include_system_eventd to jinjanate calls
@yijingyan2

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1111176:

✅Stage Build:

  • Job mellanox: retried.

✅Stage Test:

  • Job Trivy vulnerability scan (docker-ptf): skipped (optional job and does not block the PR merge).
  • Job impacted-area-kvmtest-t0 by Elastictest: retried.

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@yijingyan2

Copy link
Copy Markdown
Contributor

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1111176:

✅Stage Test:

  • Job Trivy vulnerability scan (docker-ptf): skipped (optional job and does not block the PR merge).
  • Job impacted-area-kvmtest-t0 by Elastictest: retried.

@bhaveshdell

Copy link
Copy Markdown
Contributor Author

/azpw retry

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

The following failed(or canceled) jobs were not retried:

  • Trivy vulnerability scan (docker-ptf)

Job Trivy vulnerability scan (docker-ptf) is an optional job and does not block the PR merge, so it will not be retried.

@leeprecy

Copy link
Copy Markdown
Contributor

Approved

@Praveen-Brcm Praveen-Brcm merged commit 6f18294 into sonic-net:master May 14, 2026
25 of 27 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in SONiC 202605 Release May 14, 2026
vidyac86 pushed a commit to vidyac86/sonic-buildimage that referenced this pull request May 23, 2026
* Local make customizations.

* Support for event persistence in redis-db.

* Updates

* Updates including fix to  eventdb in test enviroment.

* Add sonic yang to model event and alarm table.
remove ack, noack from sonic-common-event yang.

* Add event/alarm  persistence related testscases

* Remove file eventdb_ut.cpp.

* Updates to eventdb testsuite.

* Revert changes to existing eventd UT.
Set eventdb testcases as separate test binary.
Skip testcase execution if DB connection failure.

* Commit test related config files.

* wRevert "Local make customizations."

This reverts commit e9425a0aad5d9413efaaf1b4eccd6236aef50aba.

* Separate eventd and eventdb targets in the makefile.
Set eventdb process startretries= 0 and expected exit code=0.
This is since if no event types are defined in the event_profile, the process can exit.

* Address review comments.
Avoid using namespace std; in a header file to prevent namespace pollution; qualify standard types explicitly.
Avoid non-async-signal-safe function inside signal handler.

* Updates.

* Remove debug statements.

* Add script to start eventdb.
Script starts eventdb only if atleast one event is defined in the profile.
Add validation around json operations.

* Handle specific exception while parsing json file.
Fix indentation.

* Add the new yangs to setup.py

* Add the sonic-alarm.yang and sonic-event.yang as NON_CONF_YANG_FILES

* Address review comments.
Fix event purge time computation.
Fix stats update on purge.

* Resolve build errors.

* fix: Fix review comments

- Remove namespace pollution from eventconsume.h and fix build issues
- Add explicit swss:: and std:: prefixes to maintain type safety
- Optimize clearAckAlarmStatistic with early exit flag

* Add timeout to event receive blocking call.
Updates to the eventdb testsuite.

* Remove loading of eventdb on database start.

* Guard creation of EVENTDB with flag include_system_eventdb.

* Pass include_system_eventd to runtime jinjanate rendering

- database_config.json.j2: Add 'is defined' guard for include_system_eventd
- Dockerfile.j2: Add ENV INCLUDE_SYSTEM_EVENTD to bake build-time flag into container
- docker-database-init.sh: Pass include_system_eventd to jinjanate calls

Signed-off-by: Vidya Chidambaram <vidya_chidambaram@dell.com>
purush-nexthop pushed a commit to nexthop-ai/sonic-buildimage that referenced this pull request Jun 10, 2026
* Local make customizations.

* Support for event persistence in redis-db.

* Updates

* Updates including fix to  eventdb in test enviroment.

* Add sonic yang to model event and alarm table.
remove ack, noack from sonic-common-event yang.

* Add event/alarm  persistence related testscases

* Remove file eventdb_ut.cpp.

* Updates to eventdb testsuite.

* Revert changes to existing eventd UT.
Set eventdb testcases as separate test binary.
Skip testcase execution if DB connection failure.

* Commit test related config files.

* wRevert "Local make customizations."

This reverts commit e9425a0aad5d9413efaaf1b4eccd6236aef50aba.

* Separate eventd and eventdb targets in the makefile.
Set eventdb process startretries= 0 and expected exit code=0.
This is since if no event types are defined in the event_profile, the process can exit.

* Address review comments.
Avoid using namespace std; in a header file to prevent namespace pollution; qualify standard types explicitly.
Avoid non-async-signal-safe function inside signal handler.

* Updates.

* Remove debug statements.

* Add script to start eventdb.
Script starts eventdb only if atleast one event is defined in the profile.
Add validation around json operations.

* Handle specific exception while parsing json file.
Fix indentation.

* Add the new yangs to setup.py

* Add the sonic-alarm.yang and sonic-event.yang as NON_CONF_YANG_FILES

* Address review comments.
Fix event purge time computation.
Fix stats update on purge.

* Resolve build errors.

* fix: Fix review comments

- Remove namespace pollution from eventconsume.h and fix build issues
- Add explicit swss:: and std:: prefixes to maintain type safety
- Optimize clearAckAlarmStatistic with early exit flag

* Add timeout to event receive blocking call.
Updates to the eventdb testsuite.

* Remove loading of eventdb on database start.

* Guard creation of EVENTDB with flag include_system_eventdb.

* Pass include_system_eventd to runtime jinjanate rendering

- database_config.json.j2: Add 'is defined' guard for include_system_eventd
- Dockerfile.j2: Add ENV INCLUDE_SYSTEM_EVENTD to bake build-time flag into container
- docker-database-init.sh: Pass include_system_eventd to jinjanate calls
roger530-ho pushed a commit to roger530-ho/sonic-buildimage that referenced this pull request Jun 23, 2026
* Local make customizations.

* Support for event persistence in redis-db.

* Updates

* Updates including fix to  eventdb in test enviroment.

* Add sonic yang to model event and alarm table.
remove ack, noack from sonic-common-event yang.

* Add event/alarm  persistence related testscases

* Remove file eventdb_ut.cpp.

* Updates to eventdb testsuite.

* Revert changes to existing eventd UT.
Set eventdb testcases as separate test binary.
Skip testcase execution if DB connection failure.

* Commit test related config files.

* wRevert "Local make customizations."

This reverts commit e9425a0aad5d9413efaaf1b4eccd6236aef50aba.

* Separate eventd and eventdb targets in the makefile.
Set eventdb process startretries= 0 and expected exit code=0.
This is since if no event types are defined in the event_profile, the process can exit.

* Address review comments.
Avoid using namespace std; in a header file to prevent namespace pollution; qualify standard types explicitly.
Avoid non-async-signal-safe function inside signal handler.

* Updates.

* Remove debug statements.

* Add script to start eventdb.
Script starts eventdb only if atleast one event is defined in the profile.
Add validation around json operations.

* Handle specific exception while parsing json file.
Fix indentation.

* Add the new yangs to setup.py

* Add the sonic-alarm.yang and sonic-event.yang as NON_CONF_YANG_FILES

* Address review comments.
Fix event purge time computation.
Fix stats update on purge.

* Resolve build errors.

* fix: Fix review comments

- Remove namespace pollution from eventconsume.h and fix build issues
- Add explicit swss:: and std:: prefixes to maintain type safety
- Optimize clearAckAlarmStatistic with early exit flag

* Add timeout to event receive blocking call.
Updates to the eventdb testsuite.

* Remove loading of eventdb on database start.

* Guard creation of EVENTDB with flag include_system_eventdb.

* Pass include_system_eventd to runtime jinjanate rendering

- database_config.json.j2: Add 'is defined' guard for include_system_eventd
- Dockerfile.j2: Add ENV INCLUDE_SYSTEM_EVENTD to bake build-time flag into container
- docker-database-init.sh: Pass include_system_eventd to jinjanate calls
xdqi pushed a commit to canonical/sonic-buildimage that referenced this pull request Jul 6, 2026
* Local make customizations.

* Support for event persistence in redis-db.

* Updates

* Updates including fix to  eventdb in test enviroment.

* Add sonic yang to model event and alarm table.
remove ack, noack from sonic-common-event yang.

* Add event/alarm  persistence related testscases

* Remove file eventdb_ut.cpp.

* Updates to eventdb testsuite.

* Revert changes to existing eventd UT.
Set eventdb testcases as separate test binary.
Skip testcase execution if DB connection failure.

* Commit test related config files.

* wRevert "Local make customizations."

This reverts commit e9425a0aad5d9413efaaf1b4eccd6236aef50aba.

* Separate eventd and eventdb targets in the makefile.
Set eventdb process startretries= 0 and expected exit code=0.
This is since if no event types are defined in the event_profile, the process can exit.

* Address review comments.
Avoid using namespace std; in a header file to prevent namespace pollution; qualify standard types explicitly.
Avoid non-async-signal-safe function inside signal handler.

* Updates.

* Remove debug statements.

* Add script to start eventdb.
Script starts eventdb only if atleast one event is defined in the profile.
Add validation around json operations.

* Handle specific exception while parsing json file.
Fix indentation.

* Add the new yangs to setup.py

* Add the sonic-alarm.yang and sonic-event.yang as NON_CONF_YANG_FILES

* Address review comments.
Fix event purge time computation.
Fix stats update on purge.

* Resolve build errors.

* fix: Fix review comments

- Remove namespace pollution from eventconsume.h and fix build issues
- Add explicit swss:: and std:: prefixes to maintain type safety
- Optimize clearAckAlarmStatistic with early exit flag

* Add timeout to event receive blocking call.
Updates to the eventdb testsuite.

* Remove loading of eventdb on database start.

* Guard creation of EVENTDB with flag include_system_eventdb.

* Pass include_system_eventd to runtime jinjanate rendering

- database_config.json.j2: Add 'is defined' guard for include_system_eventd
- Dockerfile.j2: Add ENV INCLUDE_SYSTEM_EVENTD to bake build-time flag into container
- docker-database-init.sh: Pass include_system_eventd to jinjanate calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.