Example #1
0
def drop_audit(init_date=None, end_date=None):
    """Delete all Documents in Audit database.
    """
    if not init_date and not end_date:
        ModelAction.drop_collection()
        Access.drop_collection()
        Process.drop_collection()
    else:
        ModelAction.objects.filter(timestamp__gte=init_date,
                                   timestamp__lte=end_date).delete()
        Access.objects.filter(time__request__gte=init_date,
                              time__request__lte=end_date).delete()
        Process.objects.filter(creation_time__gte=init_date,
                               creation_time__lte=end_date).delete()
Example #2
0
    def test_verbose_str(self):
        process = Process(
            interlink_id=None,
            name=self.name,
            args=None,
            machine=self.machine,
            user=self.user,
            pid=self.pid,
            creation_time=self.creation_time,
        )

        expected = 'Process {} with pid {:d} run by {} on {} ({})'.format(
            self.name, self.pid, self.user, self.machine, self.creation_time)
        self.assertEqual(expected, process.verbose_str())
Example #3
0
    def test_verbose_str(self):
        process = Process(
            interlink_id=None,
            name=self.name,
            args=None,
            machine=self.machine,
            user=self.user,
            pid=self.pid,
            creation_time=self.creation_time,
        )

        expected = "Process {} with pid {:d} run by {} on {} ({})".format(
            self.name, self.pid, self.user, self.machine, self.creation_time
        )
        self.assertEqual(expected, process.verbose_str())
Example #4
0
    def test_items(self):
        items = [('name', self.name), ('machine', self.machine),
                 ('user', self.user), ('pid', self.pid),
                 ('creation_time', self.creation_time)]
        process = Process(
            interlink_id=None,
            name=self.name,
            args=None,
            machine=self.machine,
            user=self.user,
            pid=self.pid,
            creation_time=self.creation_time,
        )

        result = process.items()

        self.assertEqual(items, result)
Example #5
0
    def test_items(self):
        items = [
            ("name", self.name),
            ("machine", self.machine),
            ("user", self.user),
            ("pid", self.pid),
            ("creation_time", self.creation_time),
        ]
        process = Process(
            interlink_id=None,
            name=self.name,
            args=None,
            machine=self.machine,
            user=self.user,
            pid=self.pid,
            creation_time=self.creation_time,
        )

        result = process.items()

        self.assertEqual(items, result)
Example #6
0
    def get_process(self, process):
        """
        Get current process. If not exists, create it.

        :param process: Process data.
        :type process: dict.
        :return: Process
        :rtype: :class:`audit_tools.audit.Process`
        """
        from audit_tools.audit.models import Process

        p = getattr(self.namespace, "audit_current_process", None)
        if p is None:
            try:
                p = Process.objects.get(pid=process['pid'], machine=process['machine'],
                                        creation_time=process['creation_time'])
            except DoesNotExist:
                p = Process(**process)
                p.save()

            self.set_process(p)

        return p
Example #7
0
    def test_str(self):
        process = Process(
            interlink_id=None,
            name=self.name,
            args=None,
            machine=self.machine,
            user=self.user,
            pid=self.pid,
            creation_time=self.creation_time,
        )

        expected = 'Process{{{}, pid:{:d}, user:{}, machine:{}, creation_time:{}}}'.format(
            self.name, self.pid, self.user, self.machine, self.creation_time)
        self.assertEqual(expected, str(process))
Example #8
0
    def get_process(self, process):
        """
        Get current process. If not exists, create it.

        :param process: Process data.
        :type process: dict.
        :return: Process
        :rtype: :class:`audit_tools.audit.Process`
        """
        from audit_tools.audit.models import Process

        p = getattr(self.namespace, "audit_current_process", None)
        if p is None:
            try:
                p = Process.objects.get(pid=process['pid'],
                                        machine=process['machine'],
                                        creation_time=process['creation_time'])
            except DoesNotExist:
                p = Process(**process)
                p.save()

            self.set_process(p)

        return p
Example #9
0
 def setUpClass(cls):
     cls.cache = cache
     cls.process = Process()
     cls.access = Access()