Skip to content

Instantly share code, notes, and snippets.

@Honestpuck
Created June 30, 2018 05:14
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 Honestpuck/cacbcc31d3f96e5647adca3ea09e2104 to your computer and use it in GitHub Desktop.
Save Honestpuck/cacbcc31d3f96e5647adca3ea09e2104 to your computer and use it in GitHub Desktop.
Minimal JAMF Webhook target in Flask
import flask
import jss_tools as tools
from threading import Thread
app = flask.Flask(__name__)
@app.route('/XWDemo', methods=['POST'])
def membership_changed():
changes = flask.request.get_json()
if not changes:
return '', 400
XWDemo(changes['event'])
return '', 200
def XWDemo(data)
thr = Thread(target=XWDemo_thread, args=[data])
thr.start()
def XWDemo_thread(data):
jss = open_jss()
for id in data['groupAddedDevicesIds']:
computer = jss.Computer(id)
attrs = tools.c_attributes(computer)
attrs['XWDemoDate'] = tools.Now()
c_attributes_write(attrs, computer)
for id in data['groupRemovedDevicesIds']:
computer = jss.Computer(id)
attrs = tools.c_attributes(computer)
attrs['XWDemoDate'] = ''
c_attributes_write(attrs, computer)
if __name__ == '__main__':
app.run('0.0.0.0', debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment