13
13
save_failure_artifacts ,
14
14
)
15
15
16
- # Constants
16
+
17
17
KEEP_UI_URL = "http://localhost:3000"
18
18
DEFAULT_SNMP_PORT = 1605 # Using a non-privileged port for testing
19
19
DOCKER_NETWORK = "keep_default" # Default network for Keep services
@@ -205,10 +205,9 @@ def test_snmp_provider(browser: Page, setup_page_logging, failure_artifacts):
205
205
# Close the provider details
206
206
browser .get_by_role ("button" , name = "Cancel" , exact = True ).click ()
207
207
208
- # Send test SNMP traps
209
208
print ("Sending test SNMP traps..." )
210
209
211
- # Get a list of all containers and find the backend container
210
+ # Dynamically find the Keep backend container
212
211
container_list = subprocess .run (
213
212
["docker" , "ps" , "--format" , "{{.Names}}" ],
214
213
capture_output = True ,
@@ -217,6 +216,7 @@ def test_snmp_provider(browser: Page, setup_page_logging, failure_artifacts):
217
216
containers = container_list .stdout .strip ().split ('\n ' )
218
217
backend_container = None
219
218
219
+ # Find any container with 'keep-backend' in its name
220
220
for container in containers :
221
221
if 'keep-backend' in container :
222
222
backend_container = container
@@ -227,13 +227,14 @@ def test_snmp_provider(browser: Page, setup_page_logging, failure_artifacts):
227
227
228
228
print (f"Found backend container: { backend_container } " )
229
229
230
+ # Get the IP address of the backend container within the Docker network
230
231
keep_backend_ip = subprocess .run (
231
232
["docker" , "inspect" , "-f" , "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" , backend_container ],
232
233
capture_output = True ,
233
234
text = True
234
235
)
236
+ # Extract the IP address and use it as the target for SNMP traps
235
237
host = keep_backend_ip .stdout .strip ()
236
- # Send a trap
237
238
send_snmp_trap (host = host , port = snmp_port )
238
239
239
240
# Wait for the trap to be processed
0 commit comments