diff --git a/netbox/extras/views.py b/netbox/extras/views.py index ae9337779..ff365e6de 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -1479,6 +1479,16 @@ class ScriptResultView(TableMixin, generic.ObjectView): if job.completed: table = self.get_table(job, request, bulk_actions=False) + if job.completed and job.data and job.data.get('output'): + # If a direct export has been requested, return the job data content as a + # downloadable file. + if request.GET.get('export'): + content = job.data.get('output') + response = HttpResponse(content, content_type='text') + filename = f"{job.object.name or 'script-output'}_{job.completed.strftime('%Y-%m-%d-%H-%M-%S')}.txt" + response['Content-Disposition'] = f'attachment; filename="{filename}"' + return response + log_threshold = request.GET.get('log_threshold', LogLevelChoices.LOG_INFO) if log_threshold not in LOG_LEVEL_RANK: log_threshold = LogLevelChoices.LOG_INFO diff --git a/netbox/templates/extras/htmx/script_result.html b/netbox/templates/extras/htmx/script_result.html index 3a5964823..8811ca6ba 100644 --- a/netbox/templates/extras/htmx/script_result.html +++ b/netbox/templates/extras/htmx/script_result.html @@ -53,7 +53,16 @@ {# Script output. Legacy reports will not have this. #} {% if 'output' in job.data %}
{{ job.data.output }}{% else %}