File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed 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: 'https://github.com/netbox-community/netbox-docker'
14
+ # object_types:
15
+ # - device
16
+ # - cable
17
+ # type_create: True
18
+ # - name: device_update
19
+ # payload_url: 'https://google.com'
20
+ # object_types:
21
+ # - device
22
+ # type_update: True
23
+ - name : device_dele1te
24
+ payload_url : ' https://gitlab.com'
25
+ object_types :
26
+ - device
27
+ type_delete : True
28
+
29
+
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
+ 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
16
+
17
+ for hook in webhooks :
18
+ obj_types = hook .pop ('object_types' )
19
+ obj_type_ids = []
20
+ for obj in obj_types :
21
+ obj_type_ids .append (get_content_type_id (obj ))
22
+ if obj_type_ids is None :
23
+ print ("⚠️ Error determining content type id for user declared var: {0}" .format (obj_type ))
24
+ else :
25
+ webhook = Webhook (** hook )
26
+ webhook .save ()
27
+ webhook .obj_type .set (obj_type_ids )
28
+ # webhook.save()
You can’t perform that action at this time.
0 commit comments