code: def test_log_pattern_send_webhook(should_match: bool) -> None:
      port = 5006
      server = utils.WebhookServer(port)
      sess = api_utils.determined_test_session(admin=True)
  
      regex = r"assert 0 <= self\.metrics_sigma"
      if not should_match:
          regex = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b"
  
      webhook_trigger = bindings.v1Trigger(
          triggerType=bindings.v1TriggerType.TASK_LOG,
          condition={"regex": regex},
      )
  
      slack_path = f"/test/slack/path/here/{str(uuid.uuid4())}"
      bindings.post_PostWebhook(
          sess,
          body=bindings.v1Webhook(
              url=f"http://localhost:{port}{slack_path}",
              webhookType=bindings.v1WebhookType.SLACK,
              triggers=[webhook_trigger],
          ),
      )
  
      default_path = f"/test/path/here/{str(uuid.uuid4())}"
      bindings.post_PostWebhook(
          sess,
          body=bindings.v1Webhook(
              url=f"http://localhost:{port}{default_path}",
              webhookType=bindings.v1WebhookType.DEFAULT,
              triggers=[webhook_trigger],
          ),
      )
  
      exp_id = exp.create_experiment(
          conf.fixtures_path("no_op/single-medium-train-step.yaml"),
          conf.fixtures_path("no_op"),
          ["--config", "hyperparameters.metrics_sigma=-1.0"],
      )
      exp.wait_for_experiment_state(
          exp_id, bindings.experimentv1State.ERROR
      )
  
      for _ in range(10):
          responses = server.return_responses()
          if default_path in responses and slack_path in responses:
              break
          time.sleep(1)
  
      responses = server.close_and_return_responses()
      if should_match:
          assert len(responses) >= 2
          # Only need a spot check we get the default / slack responses.
          # Further tested in integrations.
          assert "TASK_LOG" in responses[default_path]
          assert "This log matched the regex" in responses[slack_path]
      else:
          assert default_path not in responses
          assert slack_path not in responses
  
file_path: determined/e2e_tests/tests/cluster/test_webhooks.py
imports: import json
  import time
  import uuid
  import pytest
  from determined.common.api import bindings
  from tests import api_utils
  from tests import config
  from tests import experiment
  from tests.cluster import utils
label_desc: Use image node_id 2 for calling a global function with example usage: test_log_pattern_send_webhook(should_match) without return types