Add webhook post support in yara and regex trackers

This commit is contained in:
TonyJabbour 2021-09-28 22:53:01 +02:00
parent 2319b34dcc
commit 2e880c79ca
3 changed files with 15 additions and 3 deletions

View file

@ -107,7 +107,7 @@ def get_tracker_mails(tracker_uuid):
return list(r_serv_tracker.smembers('tracker:mail:{}'.format(tracker_uuid))) return list(r_serv_tracker.smembers('tracker:mail:{}'.format(tracker_uuid)))
def get_tracker_webhook(tracker_uuid): def get_tracker_webhook(tracker_uuid):
return r_serv_tracker.hget('tracker:webhook:{}'.format(tracker_uuid)) return r_serv_tracker.hget('tracker:{}'.format(tracker_uuid), 'webhook')
def get_tracker_uuid_sources(tracker_uuid): def get_tracker_uuid_sources(tracker_uuid):
return list(r_serv_tracker.smembers(f'tracker:sources:{tracker_uuid}')) return list(r_serv_tracker.smembers(f'tracker:sources:{tracker_uuid}'))

View file

@ -12,6 +12,7 @@ import os
import re import re
import sys import sys
import time import time
import requests
sys.path.append(os.environ['AIL_BIN']) sys.path.append(os.environ['AIL_BIN'])
################################## ##################################
@ -92,7 +93,12 @@ class Tracker_Regex(AbstractModule):
mail_body = Tracker_Regex.mail_body_template.format(tracker, item_id, self.full_item_url, item_id) mail_body = Tracker_Regex.mail_body_template.format(tracker, item_id, self.full_item_url, item_id)
for mail in mail_to_notify: for mail in mail_to_notify:
NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body) NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body)
webhook_to_post = Term.get_term_webhook(tracker_uuid)
if webhook_to_post:
request_body = dict({"itemId": item_id, "url": self.full_item_url, "type": "REGEX"})
r = requests.post(webhook_to_post, data=request_body)
if (r.status_code >= 400):
raise Exception(f"Webhook request failed for {webhook_to_post}\nReason: {r.reason}")
if __name__ == "__main__": if __name__ == "__main__":
module = Tracker_Regex() module = Tracker_Regex()

View file

@ -14,6 +14,7 @@ import re
import sys import sys
import time import time
import yara import yara
import requests
sys.path.append(os.environ['AIL_BIN']) sys.path.append(os.environ['AIL_BIN'])
################################## ##################################
@ -95,7 +96,12 @@ class Tracker_Yara(AbstractModule):
self.redis_logger.debug(f'Send Mail {mail_subject}') self.redis_logger.debug(f'Send Mail {mail_subject}')
print(f'Send Mail {mail_subject}') print(f'Send Mail {mail_subject}')
NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body) NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body)
webhook_to_post = Term.get_term_webhook(tracker_uuid)
if webhook_to_post:
request_body = dict({"itemId": item_id, "url": self.full_item_url, "type": "YARA"})
r = requests.post(webhook_to_post, data=request_body)
if (r.status_code >= 400):
raise Exception(f"Webhook request failed for {webhook_to_post}\nReason: {r.reason}")
return yara.CALLBACK_CONTINUE return yara.CALLBACK_CONTINUE