diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 0994bc66f..6aed2d032 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -273,7 +273,7 @@ class BaseScript(object): def __init__(self): self._results = {} self.failed = False - self._current_method = 'main' + self._current_method = 'total' # Initiate the log self.logger = logging.getLogger(f"netbox.scripts.{self.__module__}.{self.__class__.__name__}") @@ -283,7 +283,7 @@ class BaseScript(object): self.request = None # Compile test methods and initialize results skeleton - self._results['main'] = { + self._results['total'] = { 'success': 0, 'info': 0, 'warning': 0, @@ -454,8 +454,8 @@ class BaseScript(object): if log_level != LogLevelChoices.LOG_DEFAULT: self._results[self._current_method][log_level] += 1 - if self._current_method != 'main': - self._results['main'][log_level] += 1 + if self._current_method != 'total': + self._results['total'][log_level] += 1 if obj: self.logger.log(level, f"{log_level.capitalize()} | {obj}: {message}") diff --git a/netbox/templates/extras/htmx/script_result.html b/netbox/templates/extras/htmx/script_result.html index 2fb0de468..f79fb8e48 100644 --- a/netbox/templates/extras/htmx/script_result.html +++ b/netbox/templates/extras/htmx/script_result.html @@ -1,6 +1,5 @@ {% load humanize %} {% load helpers %} -{% load log_levels %} {% load i18n %}

@@ -17,40 +16,62 @@ {% badge job.get_status_display job.get_status_color %}

{% if job.completed %} -
-
{% trans "Script Log" %}
+
+
{% trans "Script Methods" %}
- - - - - - {% for log in job.data.log %} + {% for method, data in job.data.items %} - - - - - {% empty %} - - + {% endfor %}
{% trans "Line" %}{% trans "Level" %}{% trans "Message" %}
{{ forloop.counter }}{% log_level log.status %}{{ log.message|markdown }}
- {% trans "No log output" %} + {{ method }} + {{ data.success }} + {{ data.info }} + {{ data.warning }} + {{ data.failure }}
- {% if execution_time %} - - {% endif %}
-

{% trans "Output" %}

- {% if job.data.output %} -
{{ job.data.output }}
- {% else %} -

{% trans "None" %}

- {% endif %} +
+
{% trans "Script Results" %}
+ + + + + + + + + + + {% for method, data in job.data.items %} + + + + {% for time, level, obj, url, message in data.log %} + + + + + + + {% endfor %} + {% endfor %} + +
{% trans "Time" %}{% trans "Level" %}{% trans "Object" %}{% trans "Message" %}
+ {{ method }} +
{{ time }} + + + {% if obj and url %} + {{ obj }} + {% elif obj %} + {{ obj }} + {% else %} + {{ ''|placeholder }} + {% endif %} + {{ message|markdown }}
+
{% elif job.started %} {% include 'extras/inc/result_pending.html' %} {% endif %} diff --git a/netbox/templates/extras/script_list.html b/netbox/templates/extras/script_list.html index bb91f7522..afc4e5888 100644 --- a/netbox/templates/extras/script_list.html +++ b/netbox/templates/extras/script_list.html @@ -1,14 +1,11 @@ {% extends 'generic/_base.html' %} {% load buttons %} {% load helpers %} +{% load perms %} {% load i18n %} {% block title %}{% trans "Scripts" %}{% endblock %} -{% block controls %} - {% add_button model %} -{% endblock controls %} - {% block tabs %} {% endblock tabs %} +{% block controls %} + {% add_button model %} +{% endblock controls %} + {% block content %} {% for module in script_modules %}
@@ -25,65 +26,96 @@ {{ module }}
{% if perms.extras.delete_scriptmodule %} -
- - {% trans "Delete" %} - -
+ + {% trans "Delete" %} + {% endif %}
{% include 'inc/sync_warning.html' with object=module %} - {% if not module.scripts %} - - {% else %} - + {% if module.scripts %} +
- + + {% with jobs=module.get_latest_jobs %} - {% for script_name, script_class in module.scripts.items %} - - - - {% with last_result=jobs|get_key:script_class.class_name %} - {% if last_result %} + {% for script_name, script in module.scripts.items %} + {% with last_job=jobs|get_key:script.class_name %} + + + + {% if last_job %} - {% else %} - + {% endif %} - {% endwith %} - + + + {% for method, stats in last_job.data.items %} + + + + + {% endfor %} + {% endwith %} {% endfor %} {% endwith %}
{% trans "Name" %} {% trans "Description" %} {% trans "Last Run" %}{% trans "Status" %}{% trans "Status" %}
- {{ script_class.name }} - - {{ script_class.Meta.description|markdown|placeholder }} -
+ {{ script.name }} + {{ script.description|markdown|placeholder }} - {{ last_result.created|annotated_date }} + {{ last_job.created|annotated_date }} - {% badge last_result.get_status_display last_result.get_status_color %} + + {% badge last_job.get_status_display last_job.get_status_color %} {% trans "Never" %}{{ ''|placeholder }} + {% if script.is_valid %} + {{ ''|placeholder }} + {% else %} + + {% trans "Invalid" %} + + {% endif %} +
+ {% if perms.extras.run_script and script.is_valid %} +
+
+ {% csrf_token %} + +
+
+ {% endif %} +
+ {{ method }} + + {{ stats.success }} + {{ stats.info }} + {{ stats.warning }} + {{ stats.failure }} +
+ {% else %} + {% endif %}
{% empty %} -
+