Skip to content

Instantly share code, notes, and snippets.

@Srijancse-zz
Last active July 5, 2018 16:16
Show Gist options
  • Save Srijancse-zz/b91953ba623d3fcfb231cc0a8579741f to your computer and use it in GitHub Desktop.
Save Srijancse-zz/b91953ba623d3fcfb231cc0a8579741f to your computer and use it in GitHub Desktop.
creates a python webserver, checks if a post data has been recevied at specific time and if not alert the slack group
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import SocketServer
from datetime import datetime, time
from slackclient import SlackClient
test=0
now=datetime.now()
now_time= now.time()
SLACK_TOKEN = ""
sc = SlackClient(SLACK_TOKEN)
class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_POST(self):
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data
data = self.rfile.read(content_length) # <--- Gets the data itself # <-- adds post data
global test
test = 1
self._set_headers()
def run(server_class=HTTPServer, handler_class=S, port=80):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd...'
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()
if now_time >= time(10,00) and test != 1 :
#do slack
sc.api_call(
"chat.postMessage",
channel="growth-lab",
text="ZAPS ARE DOWN!!!!"
)
else
test=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment