Created
December 4, 2018 22:38
-
-
Save equick/2a3a64d4c51d9c94845feda1bcfd7cb6 to your computer and use it in GitHub Desktop.
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 python | |
import threading | |
import time | |
from flask import Flask | |
app = Flask(__name__) | |
def now(): | |
return int(time.time()) | |
alerts = {"splunk": now()} | |
@app.before_first_request | |
def activate_job(): | |
def run_job(): | |
while True: | |
print("diff = %s" % str(now() - alerts['splunk'])) | |
time.sleep(10) | |
thread = threading.Thread(target=run_job) | |
thread.start() | |
@app.route("/") | |
def snitch(): | |
lastsplunk = alerts['splunk'] | |
alerts['splunk'] = now() | |
return str(alerts['splunk'] - lastsplunk) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment