Created
April 25, 2020 18:57
-
-
Save droberson/e928d54420effe381249c4aa76ac29b5 to your computer and use it in GitHub Desktop.
very basic example to proxy splunk webhooks to discord channels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import requests | |
from twisted.web import server | |
from twisted.web.resource import Resource | |
from twisted.internet import reactor | |
def http_log(request): | |
print(request.method, request.uri, request.path, request.args, request.requestHeaders, request.getClientIP()) | |
class SplunkDiscordAPIPost(Resource): | |
@staticmethod | |
def render_POST(request): | |
body = request.content.read() | |
data = json.loads(body) | |
# change this | |
url = "https://discordapp.com/api/webhooks/asdfasdfasfasf" | |
r = requests.post(url=url, data={"content":data["result"]["_raw"]}) | |
http_log(request) | |
return "OK" | |
def main(): | |
wwwroot = Resource() | |
wwwroot.putChild(b"post", SplunkDiscordAPIPost()) | |
reactor.listenTCP(80, server.Site(wwwroot)) | |
reactor.run() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment