Skip to content

Commit a3cf645

Browse files
MajesticFalconcimnine
authored andcommitted
fix webhook initializer yaml and webhook startup script to work with latest netbox release
1 parent d0c786e commit a3cf645

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

initializers/webhooks.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
## Examples:
1111

1212
# - name: device_creation
13-
# payload_url: 'https://github.com/netbox-community/netbox-docker'
14-
# object_types:
15-
# - device
16-
# - cable
17-
# type_create: True
13+
# payload_url: 'https://github.com/netbox-community/netbox-docker'
14+
# object_types:
15+
# - device
16+
# - cable
17+
# type_create: True
1818
# - name: device_update
19-
# payload_url: 'https://google.com'
20-
# object_types:
21-
# - device
22-
# type_update: True
23-
#- name: device_delete
24-
# payload_url: 'https://gitlab.com'
25-
# object_types:
26-
# - device
27-
# type_delete: True
19+
# payload_url: 'https://google.com'
20+
# object_types:
21+
# - device
22+
# type_update: True
23+
# - name: device_delete
24+
# payload_url: 'https://gitlab.com1'
25+
# object_types:
26+
# - device
27+
# type_delete: True
2828

2929

startup_scripts/290_webhooks.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
sys.exit()
1111

1212
def get_content_type_id(content_type_str):
13-
for type in ContentType.objects.all():
14-
if type.name == content_type_str:
15-
return type.id
13+
return ContentType.objects.get(model=content_type_str).id
1614

1715
for hook in webhooks:
1816
obj_types = hook.pop('object_types')
@@ -23,6 +21,9 @@ def get_content_type_id(content_type_str):
2321
print("⚠️ Error determining content type id for user declared var: {0}".format(obj_type))
2422
else:
2523
webhook = Webhook(**hook)
26-
webhook.save()
27-
webhook.obj_type.set(obj_type_ids)
28-
# webhook.save()
24+
if not Webhook.objects.filter(name=webhook.name):
25+
webhook.save()
26+
webhook.content_types.set(obj_type_ids)
27+
print(" Created Webhook {0}".format(webhook.name))
28+
else:
29+
print(" Skipping Webhook {0}, already exists".format(webhook.name))

0 commit comments

Comments
 (0)