fix webhook initializer yaml and webhook startup script to work with latest netbox release
This commit is contained in:
parent
d0c786e831
commit
a3cf645dc5
|
@ -10,18 +10,18 @@
|
||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
# - name: device_creation
|
# - name: device_creation
|
||||||
# payload_url: 'https://github.com/netbox-community/netbox-docker'
|
# payload_url: 'https://github.com/netbox-community/netbox-docker'
|
||||||
# object_types:
|
# object_types:
|
||||||
# - device
|
# - device
|
||||||
# - cable
|
# - cable
|
||||||
# type_create: True
|
# type_create: True
|
||||||
# - name: device_update
|
# - name: device_update
|
||||||
# payload_url: 'https://google.com'
|
# payload_url: 'https://google.com'
|
||||||
# object_types:
|
# object_types:
|
||||||
# - device
|
# - device
|
||||||
# type_update: True
|
# type_update: True
|
||||||
#- name: device_delete
|
# - name: device_delete
|
||||||
# payload_url: 'https://gitlab.com'
|
# payload_url: 'https://gitlab.com1'
|
||||||
# object_types:
|
# object_types:
|
||||||
# - device
|
# - device
|
||||||
# type_delete: True
|
# type_delete: True
|
||||||
|
|
|
@ -10,9 +10,7 @@ if webhooks is None:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def get_content_type_id(content_type_str):
|
def get_content_type_id(content_type_str):
|
||||||
for type in ContentType.objects.all():
|
return ContentType.objects.get(model=content_type_str).id
|
||||||
if type.name == content_type_str:
|
|
||||||
return type.id
|
|
||||||
|
|
||||||
for hook in webhooks:
|
for hook in webhooks:
|
||||||
obj_types = hook.pop('object_types')
|
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))
|
print("⚠️ Error determining content type id for user declared var: {0}".format(obj_type))
|
||||||
else:
|
else:
|
||||||
webhook = Webhook(**hook)
|
webhook = Webhook(**hook)
|
||||||
|
if not Webhook.objects.filter(name=webhook.name):
|
||||||
webhook.save()
|
webhook.save()
|
||||||
webhook.obj_type.set(obj_type_ids)
|
webhook.content_types.set(obj_type_ids)
|
||||||
# webhook.save()
|
print(" Created Webhook {0}".format(webhook.name))
|
||||||
|
else:
|
||||||
|
print(" Skipping Webhook {0}, already exists".format(webhook.name))
|
||||||
|
|
Loading…
Reference in New Issue