mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-18 23:20:02 +02:00
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import platform
|
||||
|
||||
from django import __version__ as DJANGO_VERSION
|
||||
from django import __version__ as django_version
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
@@ -23,7 +23,7 @@ from rq.worker_registration import clean_worker_registry
|
||||
from core.utils import delete_rq_job, enqueue_rq_job, get_rq_jobs_from_status, requeue_rq_job, stop_rq_job
|
||||
from netbox.config import get_config, PARAMS
|
||||
from netbox.object_actions import AddObject, BulkDelete, BulkExport, DeleteObject
|
||||
from netbox.registry import registry
|
||||
from netbox.plugins.utils import get_installed_plugins
|
||||
from netbox.views import generic
|
||||
from netbox.views.generic.base import BaseObjectView
|
||||
from netbox.views.generic.mixins import TableMixin
|
||||
@@ -546,7 +546,7 @@ class SystemView(UserPassesTestMixin, View):
|
||||
|
||||
def get(self, request):
|
||||
|
||||
# System stats
|
||||
# System status
|
||||
psql_version = db_name = db_size = None
|
||||
try:
|
||||
with connection.cursor() as cursor:
|
||||
@@ -561,7 +561,7 @@ class SystemView(UserPassesTestMixin, View):
|
||||
pass
|
||||
stats = {
|
||||
'netbox_release': settings.RELEASE,
|
||||
'django_version': DJANGO_VERSION,
|
||||
'django_version': django_version,
|
||||
'python_version': platform.python_version(),
|
||||
'postgresql_version': psql_version,
|
||||
'database_name': db_name,
|
||||
@@ -572,16 +572,28 @@ class SystemView(UserPassesTestMixin, View):
|
||||
# Configuration
|
||||
config = get_config()
|
||||
|
||||
# Plugins
|
||||
plugins = get_installed_plugins()
|
||||
|
||||
# Object counts
|
||||
objects = {}
|
||||
for ot in ObjectType.objects.public().order_by('app_label', 'model'):
|
||||
if model := ot.model_class():
|
||||
objects[ot] = model.objects.count()
|
||||
|
||||
# Raw data export
|
||||
if 'export' in request.GET:
|
||||
stats['netbox_release'] = stats['netbox_release'].asdict()
|
||||
params = [param.name for param in PARAMS]
|
||||
data = {
|
||||
**stats,
|
||||
'plugins': registry['plugins']['installed'],
|
||||
'plugins': plugins,
|
||||
'config': {
|
||||
k: getattr(config, k) for k in sorted(params)
|
||||
},
|
||||
'objects': {
|
||||
f'{ot.app_label}.{ot.model}': count for ot, count in objects.items()
|
||||
},
|
||||
}
|
||||
response = HttpResponse(json.dumps(data, cls=ConfigJSONEncoder, indent=4), content_type='text/json')
|
||||
response['Content-Disposition'] = 'attachment; filename="netbox.json"'
|
||||
@@ -595,6 +607,8 @@ class SystemView(UserPassesTestMixin, View):
|
||||
return render(request, 'core/system.html', {
|
||||
'stats': stats,
|
||||
'config': config,
|
||||
'plugins': plugins,
|
||||
'objects': objects,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user