36 lines
844 B
Python
Executable file
36 lines
844 B
Python
Executable file
#!/bin/python3
|
|
import threading
|
|
import subprocess
|
|
import logging
|
|
import time
|
|
|
|
import bottle
|
|
|
|
|
|
class HandlerThread(threading.Thread):
|
|
def __init__(self, **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.trigger = threading.Event()
|
|
self.trigger.set()
|
|
|
|
def run(self):
|
|
while True:
|
|
self.trigger.wait()
|
|
self.trigger.clear()
|
|
result = subprocess.run(['/etc/netbox_webhook_handler.sh'])
|
|
if result.returncode:
|
|
logging.warning(f'Handler exited with non-zero exit code {result.returncode}')
|
|
time.sleep(10)
|
|
|
|
|
|
handler_thread = HandlerThread(daemon=True)
|
|
|
|
|
|
@bottle.route('/webhook', method='POST')
|
|
def webhook():
|
|
handler_thread.trigger.set()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
handler_thread.start()
|
|
bottle.run(host='127.0.0.1', port=8433)
|