Skip to content

Commit 171a1f9

Browse files
Added event for container_checker (sonic-net#20)
1 parent bcc5421 commit 171a1f9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

files/image_config/monit/container_checker

+15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import sys
2222
from sonic_py_common import multi_asic, device_info
2323
from swsscommon import swsscommon
2424

25+
EVENTS_PUBLISHER_SOURCE = "sonic-events-host"
26+
EVENTS_PUBLISHER_TAG = "event-container"
27+
2528
def get_expected_running_containers():
2629
"""
2730
@summary: This function will get the expected running & always-enabled containers by following the rule:
@@ -150,6 +153,17 @@ def get_current_running_containers(always_running_containers):
150153
return current_running_containers
151154

152155

156+
def publish_events(lst):
157+
events_handle = swsscommon.events_init_publisher(EVENTS_PUBLISHER_SOURCE)
158+
params = swsscommon.FieldValueMap()
159+
160+
for ctr in lst:
161+
params["name"] = ctr;
162+
swsscommon.event_publish(events_handle, EVENTS_PUBLISHER_TAG, params)
163+
164+
swsscommon.events_deinit_publisher(events_handle)
165+
166+
153167
def main():
154168
"""
155169
@summary: This function will compare the difference between the current running containers
@@ -162,6 +176,7 @@ def main():
162176
expected_running_containers |= always_running_containers
163177
not_running_containers = expected_running_containers.difference(current_running_containers)
164178
if not_running_containers:
179+
publish_events(not_running_containers)
165180
print("Expected containers not running: " + ", ".join(not_running_containers))
166181
sys.exit(3)
167182

0 commit comments

Comments
 (0)