Ejemplo n.º 1
0
 def log():
     '''
     this method show all logs
     '''
     logs = Log.objects()
     print(
         tabulate(
             map(
                 lambda x: [
                     str(x[0].id),
                     Client.objects(id=str(x[0].id), name__ne=None).first(),
                     x[1], x[2], x[3]
                 ],
                 logs.all().no_dereference().values_list(
                     'client', 'date', 'item', 'type')),
             ['Client', 'Date', 'Item']))
Ejemplo n.º 2
0
    def log(self, type_log, item='0'):
        log = Log(client=self.id, type=type_log, item=item)
        logging.debug(f'type: {type_log} files: {item}')
        # change this time if you want to receive repeated log more often
        interval_min = datetime.now() - timedelta(minutes=INTERVAL_LOG)

        previous_log = Log.objects(
            client=self.id, type=type_log, item=str(
                ','.join(item)), date__gte=interval_min)

        if not previous_log:
            new_log = Log.objects.create(client=self.id,
                                         type=type_log,
                                         item=str(','.join(item)))

            attrs = [self.mail, self.hostname, str(
                type_log), str(','.join(item))]
            logging.debug(attrs)
            launcher(attrs, remote=self.remote)