File tree Expand file tree Collapse file tree 4 files changed +111
-0
lines changed Expand file tree Collapse file tree 4 files changed +111
-0
lines changed Original file line number Diff line number Diff line change
1
+ # # Possible Choices:
2
+ # # new_window:
3
+ # # - True
4
+ # # - False
5
+ # # content_type:
6
+ # # - device
7
+ # # - site
8
+ # # - any-other-content-type
9
+ # #
10
+ # # Examples:
11
+
12
+ # - name: link_to_repo
13
+ # text: 'Link to Netbox Docker'
14
+ # url: 'https://github.com/netbox-community/netbox-docker'
15
+ # new_window: False
16
+ # content_type: device
17
+ # - name: link_to_localhost
18
+ # text: 'Link to localhost'
19
+ # url: 'http://localhost'
20
+ # new_window: True
21
+ # content_type: device
Original file line number Diff line number Diff line change
1
+ # # Possible Choices:
2
+ # # object_types:
3
+ # # - device
4
+ # # - site
5
+ # # - any-other-content-type
6
+ # # types:
7
+ # # - type_create
8
+ # # - type_update
9
+ # # - type_delete
10
+ # # Examples:
11
+
12
+ # - name: device_creation
13
+ # payload_url: 'http://localhost:8080'
14
+ # object_types:
15
+ # - device
16
+ # - cable
17
+ # type_create: True
18
+ # - name: device_update
19
+ # payload_url: 'http://localhost:8080'
20
+ # object_types:
21
+ # - device
22
+ # type_update: True
23
+ # - name: device_delete
24
+ # payload_url: 'http://localhost:8080'
25
+ # object_types:
26
+ # - device
27
+ # type_delete: True
Original file line number Diff line number Diff line change
1
+ from django .contrib .contenttypes .models import ContentType
2
+ from extras .models import CustomLink
3
+ from startup_script_utils import load_yaml
4
+ import sys
5
+
6
+
7
+ custom_links = load_yaml ('/opt/netbox/initializers/custom_links.yml' )
8
+
9
+ if custom_links is None :
10
+ sys .exit ()
11
+
12
+
13
+ def get_content_type_id (content_type ):
14
+ try :
15
+ return ContentType .objects .get (model = content_type ).id
16
+ except ContentType .DoesNotExist :
17
+ pass
18
+
19
+
20
+ for link in custom_links :
21
+ content_type = link .pop ('content_type' )
22
+ link ['content_type_id' ] = get_content_type_id (content_type )
23
+ if link ['content_type_id' ] is None :
24
+ print ("⚠️ Unable to create Custom Link '{0}': The content_type '{1}' is unknown" .format (link .name , content_type ))
25
+ continue
26
+
27
+ custom_link , created = CustomLink .objects .get_or_create (** link )
28
+ if created :
29
+ print ("🔗 Created Custom Link '{0}'" .format (custom_link .name ))
Original file line number Diff line number Diff line change
1
+ from django .contrib .contenttypes .models import ContentType
2
+ from extras .models import Webhook
3
+ from startup_script_utils import load_yaml
4
+ import sys
5
+
6
+
7
+ webhooks = load_yaml ('/opt/netbox/initializers/webhooks.yml' )
8
+
9
+ if webhooks is None :
10
+ sys .exit ()
11
+
12
+
13
+ def get_content_type_id (hook_name , content_type ):
14
+ try :
15
+ return ContentType .objects .get (model = content_type ).id
16
+ except ContentType .DoesNotExist as ex :
17
+ print ("⚠️ Webhook '{0}': The object_type '{1}' is unknown." .format (hook_name , content_type ))
18
+ raise ex
19
+
20
+
21
+ for hook in webhooks :
22
+ obj_types = hook .pop ('object_types' )
23
+
24
+ try :
25
+ obj_type_ids = [get_content_type_id (hook ['name' ], obj ) for obj in obj_types ]
26
+ except ContentType .DoesNotExist :
27
+ continue
28
+
29
+ webhook , created = Webhook .objects .get_or_create (** hook )
30
+ if created :
31
+ webhook .content_types .set (obj_type_ids )
32
+ webhook .save ()
33
+
34
+ print ("🪝 Created Webhook {0}" .format (webhook .name ))
You can’t perform that action at this time.
0 commit comments