Skip to content

Instantly share code, notes, and snippets.

@Fitblip
Created June 24, 2017 06:17
Show Gist options
  • Save Fitblip/003a5b4b68d5c70661751a099a87734a to your computer and use it in GitHub Desktop.
Save Fitblip/003a5b4b68d5c70661751a099a87734a to your computer and use it in GitHub Desktop.
An example for certstream to send a slack notification.
import certstream
import json
import requests
# Set the webhook_url to the one provided by Slack when you create the webhook at https://my.slack.com/services/new/incoming-webhook/
WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"]
NEEDLE = "coinbase"
# Search for domains with a keyword in them and write the corresponding certificate to a file
def certstream_callback(message):
if message['message_type'] == "certificate_update":
all_domains = message['data']['leaf_cert']['all_domains']
if NEEDLE in " ".join(all_domains):
cn = all_domains[0]
slack_payload = {'text': ":fire: We've detected a new certificate that matches `{}`!:fire:\n```{}```".format(NEEDLE, all_domains)}
try:
response = requests.post(WEBHOOK_URL, json=slack_data)
print(reponse)
except Exception as e:
print("Error! {}".format(e))
certstream.listen_for_events(certstream_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment