fix webhook initializer yaml and webhook startup script to work with latest netbox release

This commit is contained in:
Schylar Utleye 2021-01-15 22:12:57 -06:00 committed by Christian Mäder
parent d0c786e831
commit a3cf645dc5
2 changed files with 21 additions and 20 deletions

View File

@ -21,7 +21,7 @@
# - device
# type_update: True
# - name: device_delete
# payload_url: 'https://gitlab.com'
# payload_url: 'https://gitlab.com1'
# object_types:
# - device
# type_delete: True

View File

@ -10,9 +10,7 @@ if webhooks is None:
sys.exit()
def get_content_type_id(content_type_str):
for type in ContentType.objects.all():
if type.name == content_type_str:
return type.id
return ContentType.objects.get(model=content_type_str).id
for hook in webhooks:
obj_types = hook.pop('object_types')
@ -23,6 +21,9 @@ for hook in webhooks:
print("⚠️ Error determining content type id for user declared var: {0}".format(obj_type))
else:
webhook = Webhook(**hook)
if not Webhook.objects.filter(name=webhook.name):
webhook.save()
webhook.obj_type.set(obj_type_ids)
# webhook.save()
webhook.content_types.set(obj_type_ids)
print(" Created Webhook {0}".format(webhook.name))
else:
print(" Skipping Webhook {0}, already exists".format(webhook.name))