0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 09:14:46 +01:00

Fix webhooks specifity (#3463)

* Fix webhooks specifity

* Make REST hook firing monitoring better reflect reality
This commit is contained in:
Michael Matloka 2021-02-24 23:14:02 +01:00 committed by GitHub
parent 76b3a7d002
commit b9f00b2710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 17 deletions

View File

@ -1,6 +1,7 @@
import json
from typing import Optional
import statsd
from django.conf import settings
from django.db import models
from rest_hooks.models import AbstractHook
@ -26,6 +27,7 @@ def find_and_fire_hook(
# action_performed is a resource_id-filterable hook
hooks = hooks.filter(models.Q(resource_id=instance.pk))
for hook in hooks:
statsd.Counter("%s_posthog_cloud_hooks_rest_fired" % (settings.STATSD_PREFIX,)).increment()
hook.deliver_hook(instance, payload_override)

View File

@ -1,4 +1,3 @@
import re
from typing import Any, Dict, Sequence, cast
import requests
@ -50,22 +49,20 @@ def post_event_to_webhook_ee(self: Task, event: Dict[str, Any], team_id: int, si
# REST hooks
if is_zapier_available:
action.on_perform(ephemeral_postgres_event)
statsd.Counter("%s_posthog_cloud_hooks_rest_fired" % (settings.STATSD_PREFIX,)).increment()
# webhooks
if not team.slack_incoming_webhook:
continue
message_text, message_markdown = get_formatted_message(action, ephemeral_postgres_event, site_url,)
if determine_webhook_type(team) == "slack":
message = {
"text": message_text,
"blocks": [{"type": "section", "text": {"type": "mrkdwn", "text": message_markdown},},],
}
else:
message = {
"text": message_markdown,
}
statsd.Counter("%s_posthog_cloud_hooks_web_fired" % (settings.STATSD_PREFIX,)).increment()
requests.post(team.slack_incoming_webhook, verify=False, json=message)
if team.slack_incoming_webhook and action.post_to_slack:
message_text, message_markdown = get_formatted_message(action, ephemeral_postgres_event, site_url)
if determine_webhook_type(team) == "slack":
message = {
"text": message_text,
"blocks": [{"type": "section", "text": {"type": "mrkdwn", "text": message_markdown}}],
}
else:
message = {
"text": message_markdown,
}
statsd.Counter("%s_posthog_cloud_hooks_web_fired" % (settings.STATSD_PREFIX)).increment()
requests.post(team.slack_incoming_webhook, verify=False, json=message)
except:
raise
finally: