forked from RocketMap/RocketMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.py
44 lines (35 loc) · 1.12 KB
/
webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import requests
from .utils import get_args
log = logging.getLogger(__name__)
def send_to_webhook(message_type, message):
args = get_args()
if not args.webhooks:
# what are you even doing here...
return
data = {
'type': message_type,
'message': message
}
for w in args.webhooks:
try:
requests.post(w, json=data, timeout=(None, 1))
except requests.exceptions.ReadTimeout:
log.debug('Response timeout on webhook endpoint %s', w)
except requests.exceptions.RequestException as e:
log.debug(e)
def wh_updater(args, q):
# The forever loop
while True:
try:
# Loop the queue
while True:
whtype, message = q.get()
send_to_webhook(whtype, message)
if q.qsize() > 50:
log.warning("Webhook queue is > 50 (@%d); try increasing --wh-threads", q.qsize())
q.task_done()
except Exception as e:
log.exception('Exception in wh_updater: %s', e)