fix webhook initializer yaml and webhook startup script to work with latest netbox release
This commit is contained in:
parent
d0c786e831
commit
a3cf645dc5
@ -10,20 +10,20 @@
|
||||
## Examples:
|
||||
|
||||
# - name: device_creation
|
||||
# payload_url: 'https://github.com/netbox-community/netbox-docker'
|
||||
# object_types:
|
||||
# - device
|
||||
# - cable
|
||||
# type_create: True
|
||||
# payload_url: 'https://github.com/netbox-community/netbox-docker'
|
||||
# object_types:
|
||||
# - device
|
||||
# - cable
|
||||
# type_create: True
|
||||
# - name: device_update
|
||||
# payload_url: 'https://google.com'
|
||||
# object_types:
|
||||
# - device
|
||||
# type_update: True
|
||||
#- name: device_delete
|
||||
# payload_url: 'https://gitlab.com'
|
||||
# object_types:
|
||||
# - device
|
||||
# type_delete: True
|
||||
# payload_url: 'https://google.com'
|
||||
# object_types:
|
||||
# - device
|
||||
# type_update: True
|
||||
# - name: device_delete
|
||||
# payload_url: 'https://gitlab.com1'
|
||||
# object_types:
|
||||
# - device
|
||||
# type_delete: True
|
||||
|
||||
|
||||
|
@ -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)
|
||||
webhook.save()
|
||||
webhook.obj_type.set(obj_type_ids)
|
||||
# webhook.save()
|
||||
if not Webhook.objects.filter(name=webhook.name):
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user