Adjust to repository standards
This commit is contained in:
parent
e4e2c788a9
commit
16ae063321
@ -10,12 +10,12 @@
|
|||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
# - name: link_to_repo
|
# - name: link_to_repo
|
||||||
# text: 'Link to docker repository'
|
# text: 'Link to Netbox Docker'
|
||||||
# url: 'https://github.com/netbox-community/netbox-docker'
|
# url: 'https://github.com/netbox-community/netbox-docker'
|
||||||
# new_window: False
|
# new_window: False
|
||||||
# content_type: device
|
# content_type: device
|
||||||
# - name: link_to_localhost
|
# - name: link_to_localhost
|
||||||
# text: 'Link to the users localhost'
|
# text: 'Link to localhost'
|
||||||
# url: 'http://localhost'
|
# url: 'http://localhost'
|
||||||
# new_window: True
|
# new_window: True
|
||||||
# content_type: device
|
# content_type: device
|
||||||
|
@ -10,18 +10,18 @@
|
|||||||
## Examples:
|
## Examples:
|
||||||
|
|
||||||
# - name: device_creation
|
# - name: device_creation
|
||||||
# payload_url: 'https://github.com/netbox-community/netbox-docker'
|
# payload_url: 'http://localhost:8080'
|
||||||
# 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: 'http://localhost:8080'
|
||||||
# object_types:
|
# object_types:
|
||||||
# - device
|
# - device
|
||||||
# type_update: True
|
# type_update: True
|
||||||
# - name: device_delete
|
# - name: device_delete
|
||||||
# payload_url: 'https://gitlab.com1'
|
# payload_url: 'http://localhost:8080'
|
||||||
# object_types:
|
# object_types:
|
||||||
# - device
|
# - device
|
||||||
# type_delete: True
|
# type_delete: True
|
||||||
|
@ -9,17 +9,21 @@ custom_links = load_yaml('/opt/netbox/initializers/custom_links.yml')
|
|||||||
if custom_links is None:
|
if custom_links is None:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def get_content_type_id(content_type_str):
|
|
||||||
|
def get_content_type_id(content_type):
|
||||||
try:
|
try:
|
||||||
return ContentType.objects.get(model=content_type_str).id
|
return ContentType.objects.get(model=content_type).id
|
||||||
except ContentType.DoesNotExist:
|
except ContentType.DoesNotExist:
|
||||||
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
|
pass
|
||||||
|
|
||||||
|
|
||||||
for link in custom_links:
|
for link in custom_links:
|
||||||
content_type = link.pop('content_type')
|
content_type = link.pop('content_type')
|
||||||
link['content_type_id'] = get_content_type_id(content_type)
|
link['content_type_id'] = get_content_type_id(content_type)
|
||||||
if link['content_type_id'] is not None:
|
if link['content_type_id'] is None:
|
||||||
custom_link = CustomLink(**link)
|
print("⚠️ Unable to create Custom Link '{0}': The content_type '{1}' is unknown".format(link.name, content_type))
|
||||||
if not CustomLink.objects.filter(name=custom_link.name):
|
continue
|
||||||
custom_link.save()
|
|
||||||
print("🖥️ Created Custom Link {0}".format(custom_link.name))
|
custom_link, created = CustomLink.objects.get_or_create(**link)
|
||||||
|
if created:
|
||||||
|
print("🔗 Created Custom Link '{0}'".format(custom_link.name))
|
||||||
|
@ -9,18 +9,26 @@ webhooks = load_yaml('/opt/netbox/initializers/webhooks.yml')
|
|||||||
if webhooks is None:
|
if webhooks is None:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def get_content_type_id(content_type_str):
|
|
||||||
|
def get_content_type_id(hook_name, content_type):
|
||||||
try:
|
try:
|
||||||
id = ContentType.objects.get(model=content_type_str).id
|
return ContentType.objects.get(model=content_type).id
|
||||||
return id
|
except ContentType.DoesNotExist as ex:
|
||||||
except ContentType.DoesNotExist:
|
print("⚠️ Webhook '{0}': The object_type '{1}' is unknown.".format(hook_name, content_type))
|
||||||
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
|
raise ex
|
||||||
|
|
||||||
|
|
||||||
for hook in webhooks:
|
for hook in webhooks:
|
||||||
obj_types = hook.pop('object_types')
|
obj_types = hook.pop('object_types')
|
||||||
obj_type_ids = [ get_content_type_id(obj) for obj in obj_types ]
|
|
||||||
if obj_type_ids is not None:
|
try:
|
||||||
|
obj_type_ids = [get_content_type_id(hook['name'], obj) for obj in obj_types]
|
||||||
|
except ContentType.DoesNotExist:
|
||||||
|
continue
|
||||||
|
|
||||||
webhook, created = Webhook.objects.get_or_create(**hook)
|
webhook, created = Webhook.objects.get_or_create(**hook)
|
||||||
if created:
|
if created:
|
||||||
webhook.content_types.set(obj_type_ids)
|
webhook.content_types.set(obj_type_ids)
|
||||||
print("🖥️ Created Webhook {0}".format(webhook.name))
|
webhook.save()
|
||||||
|
|
||||||
|
print("🪝 Created Webhook {0}".format(webhook.name))
|
||||||
|
Loading…
Reference in New Issue
Block a user