Skip to content

Instantly share code, notes, and snippets.

@equick
Created December 4, 2018 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equick/2a3a64d4c51d9c94845feda1bcfd7cb6 to your computer and use it in GitHub Desktop.
Save equick/2a3a64d4c51d9c94845feda1bcfd7cb6 to your computer and use it in GitHub Desktop.
#!/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