mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import time
|
|
from typing import Any, Dict
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
from zerver.decorator import REQ, api_key_only_webhook_view, has_request_variables
|
|
from zerver.lib.response import json_success
|
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
|
from zerver.models import UserProfile
|
|
|
|
MESSAGE_TEMPLATE = """
|
|
State changed to **{state}**:
|
|
* **URL**: {url}
|
|
* **Response time**: {response_time} ms
|
|
* **Timestamp**: {timestamp}
|
|
""".strip()
|
|
|
|
@api_key_only_webhook_view('Insping')
|
|
@has_request_variables
|
|
def api_insping_webhook(
|
|
request: HttpRequest, user_profile: UserProfile,
|
|
payload: Dict[str, Dict[str, Any]]=REQ(argument_type='body'),
|
|
) -> HttpResponse:
|
|
|
|
data = payload['webhook_event_data']
|
|
|
|
state_name = data['check_state_name']
|
|
url_tested = data['request_url']
|
|
response_time = data['response_time']
|
|
timestamp = data['request_start_time']
|
|
|
|
time_formatted = time.strftime("%c", time.strptime(timestamp,
|
|
"%Y-%m-%dT%H:%M:%S.%f+00:00"))
|
|
|
|
body = MESSAGE_TEMPLATE.format(
|
|
state=state_name, url=url_tested,
|
|
response_time=response_time, timestamp=time_formatted,
|
|
)
|
|
|
|
topic = 'insping'
|
|
|
|
check_send_webhook_message(request, user_profile, topic, body)
|
|
|
|
return json_success()
|