feat: add hostname api

This commit is contained in:
Aaron3S
2026-03-12 19:43:15 +08:00
parent e72177ce0b
commit 87926a8acd
3 changed files with 20 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
from .aggregate import *
from .dashboard import IndexApi
from .health import PrometheusMetricsApi, HealthCheckView
from .search import GlobalSearchView
from .search import GlobalSearchView
from .hostname import HostnameView

View File

@@ -0,0 +1,17 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from rest_framework.permissions import AllowAny
## 此 api 返回 /etc/hostname 的值, 可以匿名访问
class HostnameView(APIView):
permission_classes = (AllowAny,)
def get(self, request):
try:
with open('/etc/hostname', 'r') as f:
hostname = f.read().strip() or "Unknown"
return Response({"hostname": hostname})
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

View File

@@ -66,6 +66,7 @@ urlpatterns = [
path('api/v1/', include(api_v1)),
path('api/health/', api.HealthCheckView.as_view(), name="health"),
path('api/v1/health/', api.HealthCheckView.as_view(), name="health_v1"),
path('api/v1/hostname/', api.HostnameView.as_view(), name="hostname"),
# External apps url
path('core/auth/captcha/', include('captcha.urls')),
path('core/', include(app_view_patterns)),