Beispiel #1
0
 def handle(self, *args, **options):
     pyas2init.logger.info(_(u'Retrying all failed outbound messages'))
     failed_msgs = models.Message.objects.filter(status='R',
                                                 direction='OUT')
     for failed_msg in failed_msgs:
         if not failed_msg.retries:
             failed_msg.retries = 1
         else:
             failed_msg.retries = failed_msg.retries + 1
         if failed_msg.retries > pyas2init.gsettings['max_retries']:
             failed_msg.status = 'E'
             models.Log.objects.create(
                 message=failed_msg,
                 status='E',
                 text=_(
                     u'Message exceeded maximum retries, marked as error'))
             failed_msg.save()
             continue
         pyas2init.logger.info(
             _(u'Retrying send of message with ID %s' % failed_msg))
         try:
             payload = as2lib.build_message(failed_msg)
             as2lib.send_message(failed_msg, payload)
         except Exception, e:
             failed_msg.status = 'E'
             models.Log.objects.create(
                 message=failed_msg,
                 status='E',
                 text=_(u'Failed to send message, error is %s' % e))
             failed_msg.save()
             ### Send mail here
             as2utils.senderrorreport(
                 failed_msg, _(u'Failed to send message, error is %s' % e))
Beispiel #2
0
 def handle(self, *args, **options):
     if len(args) != 3:
         raise CommandError(
             _(u'Insufficient number of arguments specified, please check help for correct usage'
               ))
     try:
         org = models.Organization.objects.get(as2_name=args[0])
     except models.Organization.DoesNotExist:
         raise CommandError(_(u'Organization "%s" does not exist' %
                              args[0]))
     try:
         partner = models.Partner.objects.get(as2_name=args[1])
     except models.Partner.DoesNotExist:
         raise CommandError(_(u'Partner "%s" does not exist' % args[1]))
     if not os.path.isfile(args[2]):
         raise CommandError(
             _(u'Payload at location "%s" does not exist' % args[2]))
     if options['delete'] and not os.access(args[2], os.W_OK):
         raise CommandError('Insufficient file permission for payload %s' %
                            args[2])
     outdir = as2utils.join(pyas2init.gsettings['payload_send_store'],
                            time.strftime('%Y%m%d'))
     as2utils.dirshouldbethere(outdir)
     outfile = as2utils.join(outdir, os.path.basename(args[2]))
     shutil.copy2(args[2], outfile)
     if options['delete']:
         os.remove(args[2])
     payload = models.Payload.objects.create(
         name=os.path.basename(args[2]),
         file=outfile,
         content_type=partner.content_type)
     message = models.Message.objects.create(
         message_id=email.utils.make_msgid().strip('<>'),
         partner=partner,
         organization=org,
         direction='OUT',
         status='IP',
         payload=payload)
     try:
         payload = as2lib.build_message(message)
         as2lib.send_message(message, payload)
     except Exception, e:
         txt = as2utils.txtexc()
         reporttxt = _(u'Failed to send message, error:\n%(txt)s') % {
             'txt': txt
         }
         pyas2init.logger.error(reporttxt)
         message.status = 'E'
         models.Log.objects.create(
             message=message,
             status='E',
             text=_(u'Failed to send message, error is %s' % e))
         message.save()
         ### Send mail here
         as2utils.senderrorreport(
             message, _(u'Failed to send message, error is %s' % e))
         sys.exit(2)
Beispiel #3
0
 def handle(self, *args, **options):
     if len(args) != 3:
         raise CommandError(
             _(u'Insufficient number of arguments specified, please check help for correct usage'
               ))
     try:
         org = models.Organization.objects.get(as2_name=args[0])
     except models.Organization.DoesNotExist:
         raise CommandError(
             _(u'Organization "%s" does not exist' % args[0]))
     try:
         partner = models.Partner.objects.get(as2_name=args[1])
     except models.Partner.DoesNotExist:
         raise CommandError(_(u'Partner "%s" does not exist' % args[1]))
     if not os.path.isfile(args[2]):
         raise CommandError(
             _(u'Payload at location "%s" does not exist' % args[2]))
     if options['delete'] and not os.access(args[2], os.W_OK):
         raise CommandError(
             'Insufficient file permission for payload %s' % args[2])
     outdir = as2utils.join(pyas2init.gsettings['payload_send_store'],
                            time.strftime('%Y%m%d'))
     as2utils.dirshouldbethere(outdir)
     outfile = as2utils.join(outdir, os.path.basename(args[2]))
     shutil.copy2(args[2], outfile)
     if options['delete']:
         os.remove(args[2])
     payload = models.Payload.objects.create(
         name=os.path.basename(args[2]),
         file=outfile,
         content_type=partner.content_type)
     message = models.Message.objects.create(
         message_id=email.utils.make_msgid().strip('<>'),
         partner=partner,
         organization=org,
         direction='OUT',
         status='IP',
         payload=payload)
     try:
         payload = as2lib.build_message(message)
         as2lib.send_message(message, payload)
     except Exception, e:
         txt = as2utils.txtexc()
         reporttxt = _(u'Failed to send message, error:\n%(txt)s') % {
             'txt': txt
         }
         pyas2init.logger.error(reporttxt)
         message.status = 'E'
         models.Log.objects.create(
             message=message,
             status='E',
             text=_(u'Failed to send message, error is %s' % e))
         message.save()
         ### Send mail here
         as2utils.senderrorreport(
             message, _(u'Failed to send message, error is %s' % e))
         sys.exit(2)
Beispiel #4
0
 def handle(self, *args, **options):
     pyas2init.logger.info(_(u'Retrying all failed outbound messages'))
     failed_msgs = models.Message.objects.filter(status='R',direction='OUT')
     for failed_msg in failed_msgs:
         if not failed_msg.retries:
             failed_msg.retries = 1
         else:
             failed_msg.retries = failed_msg.retries + 1
         if failed_msg.retries > pyas2init.gsettings['max_retries']:
             failed_msg.status = 'E'
             models.Log.objects.create(message=failed_msg, status='E', text = _(u'Message exceeded maximum retries, marked as error'))
             failed_msg.save()
             continue
         pyas2init.logger.info(_(u'Retrying send of message with ID %s'%failed_msg))
         try:
             payload = as2lib.build_message(failed_msg)
             as2lib.send_message(failed_msg,payload)
         except Exception,e:
             failed_msg.status = 'E'
             models.Log.objects.create(message=failed_msg, status='E', text = _(u'Failed to send message, error is %s' %e))
             failed_msg.save()
             ### Send mail here 
             as2utils.senderrorreport(failed_msg,_(u'Failed to send message, error is %s' %e))
Beispiel #5
0
    def handle(self, *args, **options):
        pyas2init.logger.info(_(u'Retrying all failed outbound messages'))

        # Get the list of all messages with status retry
        failed_msgs = models.Message.objects.filter(status='R', direction='OUT')

        for failed_msg in failed_msgs:
            # Increase the retry count
            if not failed_msg.retries:
                failed_msg.retries = 1
            else:
                failed_msg.retries += failed_msg.retries

            # if max retries has exceeded then mark message status as error
            if failed_msg.retries > pyas2init.gsettings['max_retries']:
                failed_msg.status = 'E'
                models.Log.objects.create(message=failed_msg,
                                          status='E',
                                          text=_(u'Message exceeded maximum retries, marked as error'))
                failed_msg.save()
                continue

            pyas2init.logger.info(_(u'Retrying send of message with ID %s' % failed_msg))
            try:
                # Build and resend the AS2 message
                payload = as2lib.build_message(failed_msg)
                as2lib.send_message(failed_msg, payload)
            except Exception, e:
                # In case of any errors mark message as failed and send email if enabled
                failed_msg.status = 'E'
                models.Log.objects.create(message=failed_msg,
                                          status='E',
                                          text=_(u'Failed to send message, error is %s' % e))
                failed_msg.save()
                # Send mail here
                as2utils.senderrorreport(failed_msg, _(u'Failed to send message, error is %s' % e))
Beispiel #6
0
    def handle(self, *args, **options):
        # Check if organization and partner exists
        try:
            org = models.Organization.objects.get(
                as2_name=options['organization_as2name'])
        except models.Organization.DoesNotExist:
            raise CommandError(
                _(u'Organization "%s" does not exist' %
                  options['organization_as2name']))
        try:
            partner = models.Partner.objects.get(
                as2_name=options['partner_as2name'])
        except models.Partner.DoesNotExist:
            raise CommandError(
                _(u'Partner "%s" does not exist' % options['partner_as2name']))

        # Check if file exists and we have the right permissions
        if not os.path.isfile(options['path_to_payload']):
            raise CommandError(
                _(u'Payload at location "%s" does not exist' %
                  options['path_to_payload']))
        if options['delete'] and not os.access(options['path_to_payload'],
                                               os.W_OK):
            raise CommandError('Insufficient file permission for payload %s' %
                               options['path_to_payload'])

        # Copy the file to the store
        output_dir = as2utils.join(pyas2init.gsettings['payload_send_store'],
                                   time.strftime('%Y%m%d'))
        as2utils.dirshouldbethere(output_dir)
        outfile = as2utils.join(output_dir,
                                os.path.basename(options['path_to_payload']))
        shutil.copy2(options['path_to_payload'], outfile)

        # Delete original file if option is set
        if options['delete']:
            os.remove(options['path_to_payload'])

        # Create the payload and message objects
        payload = models.Payload.objects.create(
            name=os.path.basename(options['path_to_payload']),
            file=outfile,
            content_type=partner.content_type)
        message = models.Message.objects.create(
            message_id=email.utils.make_msgid().strip('<>'),
            partner=partner,
            organization=org,
            direction='OUT',
            status='IP',
            payload=payload)

        # Build and send the AS2 message
        try:
            payload = as2lib.build_message(message)
            as2lib.send_message(message, payload)
        except Exception:
            message.status = 'E'
            txt = traceback.format_exc(None).decode('utf-8', 'ignore')
            message.adv_status = \
                _(u'Failed to send message, error:\n%(txt)s') % {'txt': txt}
            pyas2init.logger.error(message.adv_status)

            models.Log.objects.create(message=message,
                                      status='E',
                                      text=message.adv_status)
            message.save()

            # Send mail here
            as2utils.senderrorreport(message, message.adv_status)
            sys.exit(2)

        sys.exit(0)