mirror of
https://github.com/netbox-community/netbox-docker.git
synced 2024-12-01 20:34:11 +01:00
add webhook initializer
This commit is contained in:
parent
187ae4b2a1
commit
7112a88359
29
initializers/webhooks.yml
Normal file
29
initializers/webhooks.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
## Possible Choices:
|
||||||
|
## object_types:
|
||||||
|
## - device
|
||||||
|
## - site
|
||||||
|
## - any-other-content-type
|
||||||
|
## types:
|
||||||
|
## - type_create
|
||||||
|
## - type_update
|
||||||
|
## - type_delete
|
||||||
|
## Examples:
|
||||||
|
|
||||||
|
# - name: device_creation
|
||||||
|
# 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_dele1te
|
||||||
|
payload_url: 'https://gitlab.com'
|
||||||
|
object_types:
|
||||||
|
- device
|
||||||
|
type_delete: True
|
||||||
|
|
||||||
|
|
28
startup_scripts/290_webhooks.py
Normal file
28
startup_scripts/290_webhooks.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from extras.models import Webhook
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
webhooks = load_yaml('/opt/netbox/initializers/webhooks.yml')
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
for hook in webhooks:
|
||||||
|
obj_types = hook.pop('object_types')
|
||||||
|
obj_type_ids = []
|
||||||
|
for obj in obj_types:
|
||||||
|
obj_type_ids.append(get_content_type_id(obj))
|
||||||
|
if obj_type_ids is None:
|
||||||
|
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()
|
Loading…
Reference in New Issue
Block a user