Feature Request: Editable Webhook POST format #2180

Closed
opened 2025-12-29 17:23:04 +01:00 by adam · 2 comments
Owner

Originally created by @berahtlv on GitHub (Dec 7, 2018).

Environment

  • Python version: 3.5.4 ->
  • NetBox version: 2.5.1 ->

Proposed Functionality

Editable Webhook POST format to ensure compatibility with different REST APIs. At the moment direct API to API calls are not possible because of JSON keys incompatibility.

Use Case

Netbox object change triggers defined webhook which sends POST request to some API for configuration synchronization or informative message generation.

Database Changes

Minor additions.

External Dependencies

No additional.

Originally created by @berahtlv on GitHub (Dec 7, 2018). ### Environment * Python version: 3.5.4 -> * NetBox version: 2.5.1 -> ### Proposed Functionality Editable Webhook POST format to ensure compatibility with different REST APIs. At the moment direct API to API calls are not possible because of JSON keys incompatibility. ### Use Case Netbox object change triggers defined webhook which sends POST request to some API for configuration synchronization or informative message generation. ### Database Changes Minor additions. ### External Dependencies No additional.
adam closed this issue 2025-12-29 17:23:04 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 7, 2018):

Webhooks are not intended to be exported directly to another API. Some intermediary processing will be needed to adapt the data, and this is well outside the scope of NetBox. We just send as much information as we have with the request.

@jeremystretch commented on GitHub (Dec 7, 2018): Webhooks are not intended to be exported directly to another API. Some intermediary processing will be needed to adapt the data, and this is well outside the scope of NetBox. We just send as much information as we have with the request.
Author
Owner

@berahtlv commented on GitHub (Dec 13, 2018):

... Some intermediary processing will be needed to adapt the data, and this is well outside the scope of NetBox. ...

If feature will be requested as PR you accept it?

Idea is to add to admin/webhook page check like 'API to API' which will activate raw mapping template area, something like Contexts area, so users by themselves can edit output format. Output definition can have some templating syntax or JSON which defines mapping of the keys.

Addition to netbox/netbox/extras/webhooks_worker.py and frontend will be needed.
Can look something like that.

Mappings:

from string import Template
key_map = {'default':Template('{"text":"$r_model is $r_event at $r_timestamp"}'),
           'prefix':Template('{"text":"$r_model $prefix is $r_event at $r_timestamp"}'),
}

Renaming to flatten sent object dictionary:

payload = json.loads(params.pop('data'))
obj_event = {'r_model':payload['model'].title(),
            'r_event':payload['event'],
            'r_timestamp':payload['timestamp']
}

Mapping of the data according to template:

payload['data'].update(**obj_event)
params['data'] = key_map.get(payload['model'], key_map['default']).substitute(**payload['data'])
@berahtlv commented on GitHub (Dec 13, 2018): > ... Some intermediary processing will be needed to adapt the data, and this is well outside the scope of NetBox. ... If feature will be requested as PR you accept it? Idea is to add to admin/webhook page check like 'API to API' which will activate raw mapping template area, something like Contexts area, so users by themselves can edit output format. Output definition can have some templating syntax or JSON which defines mapping of the keys. Addition to netbox/netbox/extras/webhooks_worker.py and frontend will be needed. Can look something like that. Mappings: ``` from string import Template key_map = {'default':Template('{"text":"$r_model is $r_event at $r_timestamp"}'), 'prefix':Template('{"text":"$r_model $prefix is $r_event at $r_timestamp"}'), } ``` Renaming to flatten sent object dictionary: ``` payload = json.loads(params.pop('data')) obj_event = {'r_model':payload['model'].title(), 'r_event':payload['event'], 'r_timestamp':payload['timestamp'] } ``` Mapping of the data according to template: ``` payload['data'].update(**obj_event) params['data'] = key_map.get(payload['model'], key_map['default']).substitute(**payload['data']) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2180