提交 0954f6d7 编写于 作者: baltery's avatar baltery

Add audits api

上级 59727656
# ~*~ coding: utf-8 ~*~
#
from rest_framework import generics
import serializers
class ProxyLogCreateApi(generics.CreateAPIView):
serializer_class = serializers.ProxyLogSerializer
class CommandLogCreateApi(generics.CreateAPIView):
serializer_class = serializers.CommandLogSerializer
......@@ -23,7 +23,7 @@ class LoginLog(models.Model):
date_logout = models.DateTimeField(null=True, verbose_name=_('Date logout'))
class Meta:
db_table = 'loginlog'
db_table = 'login_log'
ordering = ['-date_login', 'username']
......@@ -44,10 +44,24 @@ class ProxyLog(models.Model):
date_start = models.DateTimeField(auto_now=True, verbose_name=_('Date start'))
date_finished = models.DateTimeField(null=True, verbose_name=_('Date finished'))
def __unicode__(self):
return '%s-%s-%s-%s' % (self.username, self.hostname, self.system_user, self.id)
class Meta:
db_table = 'proxy_log'
ordering = ['-date_start', 'username']
class CommandLog(models.Model):
proxy_log = models.ForeignKey(ProxyLog, on_delete=models.CASCADE, related_name='proxy_log')
proxy_log = models.ForeignKey(ProxyLog, on_delete=models.CASCADE, related_name='command_log')
command = models.CharField(max_length=1000, blank=True)
output = models.TextField(blank=True)
date_start = models.DateTimeField(null=True)
date_finished = models.DateTimeField(null=True)
def __unicode__(self):
return '%s: %s' % (self.id, self.command)
class Meta:
db_table = 'command_log'
ordering = ['-date_start', 'command']
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from rest_framework import serializers
import models
class ProxyLogSerializer(serializers.ModelSerializer):
class Meta:
model = models.ProxyLog
class CommandLogSerializer(serializers.ModelSerializer):
class Meta:
model = models.CommandLog
if __name__ == '__main__':
pass
from django.conf.urls import url
import api
import views
app_name = 'audits'
urlpatterns = [
]
urlpatterns += [
url(r'^v1/proxy-log$', api.ProxyLogCreateApi.as_view(), name='proxy-log-create-api'),
url(r'^v1/command-log$', api.CommandLogCreateApi.as_view(), name='command-log-create-api'),
]
......@@ -25,6 +25,7 @@ urlpatterns = [
url(r'^(api/)?users/', include('users.urls')),
url(r'^assets/', include('assets.urls')),
url(r'^perms/', include('perms.urls')),
url(r'^(api/)?audits/', include('audits.urls')),
]
......
# ~*~ coding: utf-8 ~*~
#
import logging
from django.shortcuts import get_object_or_404
from rest_framework import generics, status
......@@ -12,7 +10,8 @@ from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
from .models import User, UserGroup
from .serializers import UserDetailSerializer, UserAndGroupSerializer, \
GroupDetailSerializer, UserPKUpdateSerializer, UserBulkUpdateSerializer, GroupBulkUpdateSerializer
from common.mixins import BulkDeleteApiMixin, get_logger
from common.mixins import BulkDeleteApiMixin
from common.utils import get_logger
logger = get_logger(__name__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册