24 lines
722 B
Python
24 lines
722 B
Python
|
|
from django.shortcuts import render
|
||
|
|
from django.http import JsonResponse
|
||
|
|
from .models import Service
|
||
|
|
|
||
|
|
# 主页视图
|
||
|
|
def home(request):
|
||
|
|
return render(request, 'status/index.html')
|
||
|
|
|
||
|
|
# API视图 - 获取所有服务状态
|
||
|
|
def get_services(request):
|
||
|
|
services = Service.objects.all()
|
||
|
|
data = []
|
||
|
|
for service in services:
|
||
|
|
data.append({
|
||
|
|
'name': service.name,
|
||
|
|
'status': service.status,
|
||
|
|
'description': service.description,
|
||
|
|
'ip_address': service.ip_address,
|
||
|
|
'port': service.port,
|
||
|
|
'reliability': float(service.reliability),
|
||
|
|
'last_updated': service.last_updated.isoformat()
|
||
|
|
})
|
||
|
|
return JsonResponse(data, safe=False)
|