netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Public demo: https://demo.netbox.dev
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.34k stars 2.49k forks source link

Webhooks: Query RQ queue for job status via API #7848

Open netgab opened 2 years ago

netgab commented 2 years ago

NetBox version

v3.0.10

Feature type

New functionality

Proposed functionality

The webhook job status (Admin UI > Background Jobs) should be queried over the netbox API.

Use case

The goal is to make webhooks more reliable in terms of failed jobs. For example if the webhook receiver is not available for any reason (e.g. downtime), the failed jobs are not retried. To make it more reliable, it should be possible to query netbox for failed jobs and filter based on the date/time and/or webhook name. Basically all the information in Kwargs in the RQ queue should be returned.

A webhook receiver (or any other monitoring system) may query netbox in regular intervals for these failed webhook events to:

Database changes

not sure - sorry

External dependencies

No response

jeremystretch commented 2 years ago

@netgab can you provide an example of what you'd expect the API endpoint and response to look like?

netgab commented 2 years ago

@jeremystretch: Sure - but I'm not a developer ... so it's just a rough / best effort guess. For a generic approach (not focussing on webhooks in particular, instead focus on queues): API endpoint: api/extras/background-tasks/<QUEUE-NAME>/{failed|finished|...}/ For my purpose (failed webhook stuff): api/extras/background-tasks/default/failed/

Response: (in YAML, because I'm lazy)

count: <NUMBER-OF-ITEMS-IN-QUEUE>
results:
  - id: "<JOB-ID>"   # example: dbcd6415-af03-4366-8d8e-7f891c0ccb3b
    queue: "<QUEUE-NAME>"    # example: default
    callable: "<CALL-NAME>"   # example: extras.webhooks_worker.process_webhook
    kwargs:    # dictionary of kwargs 

To be more use case centric (failed webhooks): API endpoint: api/extras/webhook-status/

Response: (in YAML, because I'm lazy)

count: <NUMBER-OF-ITEMS-IN-QUEUE>
results:
  - id: "<JOB-ID>"   # example: dbcd6415-af03-4366-8d8e-7f891c0ccb3b
    webhook: "<WEBHOOK-NAME>"   # Link to the webhook object (/apt/extras/webhook)
    event: "{create|delete| ...}
    data: <DICTIONARY-OF-WEBHOOK-DATA>
    snapshots: <PRE-POST-CHANGE-DICTIONARY>
    timestamp: <TIMESTAMP>

Personally I'm for the use case centric approach.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.