Skip to content

Commit

Permalink
add log_count
Browse files Browse the repository at this point in the history
  • Loading branch information
wang.wangqiang committed Apr 17, 2024
1 parent 68ae58f commit a5d2fb6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
Binary file modified cli_creator/cli_creator/__pycache__/settings.cpython-310.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions cli_creator/cli_creator/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'firewall',
]

MIDDLEWARE = [
Expand Down
9 changes: 9 additions & 0 deletions cli_creator/firewall/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
from django.db import models

# Create your models here.

class cli_logs(models.Model):
ip_address = models.TextField(max_length=30)
time = models.DateTimeField(max_length=30)
info = models.TextField(max_length=255)
def __str__(self):
return '%s %s %s'%( self.ip_address, self.time, self.info)
class Meta:
app_label = 'firewall'
3 changes: 2 additions & 1 deletion cli_creator/firewall/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

urlpatterns = [
path('forticli',views.forticli, name='forticli'),
path('forticli_modify',views.forticli_modify, name='forticli_modify')
path('forticli_modify',views.forticli_modify, name='forticli_modify'),
path('logs_count', views.logs_count, name='logs_count')
]
29 changes: 27 additions & 2 deletions cli_creator/firewall/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
from rest_framework.response import Response
from django.http import JsonResponse
from firewall.forti import FirewallConfigurator
from firewall.models import cli_logs
from django.db.models import Count
from datetime import datetime, timedelta

@api_view(['GET'])
def logs_count(request):
if request.method == 'GET':
today = datetime.now().date()
# 计算昨天的日期
data_count_list=[]
for i in range(0, 7):
# 计算当前日期的前 i 天日期
date = today - timedelta(days=6-i)

# 查询当天的数据量
data_count = cli_logs.objects.filter(time__date=date).count()

# 打印结果
print(f"前{i}天的数据量:", data_count)
data_count_list.append(data_count)

return Response(data_count_list)

@api_view(['GET', 'POST'])
def forticli(request):
Expand Down Expand Up @@ -30,8 +52,10 @@ def forticli(request):
'result': result_command_str,
'message': 'Success'
}

obj = cli_logs(ip_address="127.0.0.1", time="2024-04-17", info="forticli_create")
obj.save()
return Response(data)


else:
return Response({'message': 'Only POST requests are allowed'}, status=400)
Expand Down Expand Up @@ -60,7 +84,8 @@ def forticli_modify(request):
'result': result_command_str,
'message': 'Success'
}

obj = cli_logs(ip_address="127.0.0.1", time="2024-04-17", info="forticli_create")
obj.save()
return Response(data)

else:
Expand Down
Binary file modified cli_creator/requirements.txt
Binary file not shown.

0 comments on commit a5d2fb6

Please sign in to comment.