Skip to content

Commit

Permalink
Added event for container_checker (sonic-net#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
renukamanavalan authored Sep 12, 2022
1 parent bcc5421 commit 171a1f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions files/image_config/monit/container_checker
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import sys
from sonic_py_common import multi_asic, device_info
from swsscommon import swsscommon

EVENTS_PUBLISHER_SOURCE = "sonic-events-host"
EVENTS_PUBLISHER_TAG = "event-container"

def get_expected_running_containers():
"""
@summary: This function will get the expected running & always-enabled containers by following the rule:
Expand Down Expand Up @@ -150,6 +153,17 @@ def get_current_running_containers(always_running_containers):
return current_running_containers


def publish_events(lst):
events_handle = swsscommon.events_init_publisher(EVENTS_PUBLISHER_SOURCE)
params = swsscommon.FieldValueMap()

for ctr in lst:
params["name"] = ctr;
swsscommon.event_publish(events_handle, EVENTS_PUBLISHER_TAG, params)

swsscommon.events_deinit_publisher(events_handle)


def main():
"""
@summary: This function will compare the difference between the current running containers
Expand All @@ -162,6 +176,7 @@ def main():
expected_running_containers |= always_running_containers
not_running_containers = expected_running_containers.difference(current_running_containers)
if not_running_containers:
publish_events(not_running_containers)
print("Expected containers not running: " + ", ".join(not_running_containers))
sys.exit(3)

Expand Down

0 comments on commit 171a1f9

Please sign in to comment.