コード例 #1
0
def mail_admins(subject, message='', trace=True):
    if trace:
        exc_info = sys.exc_info()
        if exc_info:
            message += ("\n\n" if message else '') + ''.join(
                traceback.format_exception(*exc_info))
    django_mail_admins(subject, message, fail_silently=True)
コード例 #2
0
ファイル: admin_utils.py プロジェクト: cnzhuran/mdcom
def mail_admins(subject,
                message,
                fail_silently=False,
                connection=None,
                html_message=None,
                send_sms=False,
                include_stack=True):
    """ Helper wrapper to send mail to admins.  If there are problems sending
	mail to admins a critical notification is logged as well as notifification
	via sms.  If the caller wishes they can also forward an sms message."""
    try:
        if include_stack:  # Typically true except in ExceptionDumpMiddleware
            tracemsg = '\n'.join(
                '...%s:%d in %s() %s' %
                (fname[-32:], lnum, fn, line.strip() if line else '')
                for fname, lnum, fn, line in extract_stack())
            message = "%s\n\n\nTraceback:\n%s" % (message, tracemsg)

            if html_message:
                html_message = "%s<br/><br/><br/>Traceback:<br/>%s" % \
                 (html_message, '<br/>'.join(tracemsg.split('\n')))

        django_mail_admins(subject, message, fail_silently, connection,
                           html_message)
        if send_sms:
            sms_admins(message)
    except (Exception), e:
        exception_msg = "Failure in mail_admins, exception: %s" % (repr(e))
        msg = "mail_admins failure, exception details in previous log. %s" % str(
            message)
        logger.critical(exception_msg)
        logger.critical(msg)
        sms_admins(exception_msg)
コード例 #3
0
ファイル: mail.py プロジェクト: WillianPaiva/sparks
def mail_admins(*args, **kwargs):
    """ Wraps the Django :func:`mail_admins` function into a parallel thread
        for immediate reactivity on the web-front side.

        .. versionadded:: 1.17
    """

    parallel = kwargs.pop("parallel", False)

    if parallel:
        BatcherThread(django_mail_admins, args=args, kwargs=kwargs, parallel=True).start()

    else:
        django_mail_admins(*args, **kwargs)
コード例 #4
0
ファイル: models.py プロジェクト: olivergs/django-sitelog
    def log(tag,message,data=None,level=INFO,content_object=None,request=None,ip=None,user=None,site=None,mail_admins=False,callback=None):
        """
        Logs a message into site log
        """
        # Set IP value
        if ip is None:
            if not request is None:
                if 'HTTP_X_FORWARDED_FOR' in request.META:
                    ip=request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip()
                else:
                    ip=request.META['REMOTE_ADDR']
            else:
                ip='0.0.0.0'
                
        # Set user value
        if user is None:
            if not request is None:    
                if request.user.is_authenticated():
                    user=request.user
        
        # Set site value
        if site is None:
            if not request is None:
                site=get_current_site(request)
            else:
                site=Site.objects.get_current()
        # Check exceptions    
        if sys.exc_info() != (None,None,None):
            if data is not None:
                data=unicode(data) + '\n\n---\n' + traceback.format_exc()
            else:
                data=traceback.format_exc()

        # Save log object
        log=SiteLog(tag=tag,message=u'%s' % message,level=level,data=u'%s' % data,ip=ip,user=user,site=site)
        log.content_object=content_object
        log.save()
        
        # Mail admins if specified or needed
        if mail_admins or log.level <= SITELOG_MAIL_ADMINS_LEVEL:
            print log
            body=render_to_string('sitelog/mail_admins.html', {'log': log})
            django_mail_admins(message,body,fail_silently=True)

        # Callback execution
        if callback is not None:
            return callback(log)
コード例 #5
0
ファイル: mail.py プロジェクト: WillianPaiva/sparks
def mail_admins(*args, **kwargs):
    """ Wraps the Django :func:`mail_admins` function into a parallel thread
        for immediate reactivity on the web-front side.

        .. versionadded:: 1.17
    """

    parallel = kwargs.pop('parallel', False)

    if parallel:
        BatcherThread(django_mail_admins,
                      args=args,
                      kwargs=kwargs,
                      parallel=True).start()

    else:
        django_mail_admins(*args, **kwargs)
コード例 #6
0
ファイル: admin_utils.py プロジェクト: DongHuaLu/mdcom
def mail_admins(subject, message, fail_silently=False, connection=None,
			html_message=None, send_sms=False, include_stack=True):
	""" Helper wrapper to send mail to admins.  If there are problems sending
	mail to admins a critical notification is logged as well as notifification
	via sms.  If the caller wishes they can also forward an sms message."""
	try:
		if include_stack:  # Typically true except in ExceptionDumpMiddleware
			tracemsg = '\n'.join('...%s:%d in %s() %s' % (fname[-32:], lnum, fn, line.strip()
					if line else '') for fname, lnum, fn, line in extract_stack())
			message = "%s\n\n\nTraceback:\n%s" % (message, tracemsg)

			if html_message:
				html_message = "%s<br/><br/><br/>Traceback:<br/>%s" % \
					(html_message, '<br/>'.join(tracemsg.split('\n')))

		django_mail_admins(subject, message, fail_silently, connection, html_message)
		if send_sms:
			sms_admins(message)
	except (Exception), e:
		exception_msg = "Failure in mail_admins, exception: %s" % (repr(e))
		msg = "mail_admins failure, exception details in previous log. %s" % str(message)
		logger.critical(exception_msg)
		logger.critical(msg)
		sms_admins(exception_msg)
コード例 #7
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def mail_admins(subject, message='', trace=True):
    if trace:
        exc_info = sys.exc_info()
        if exc_info:
            message += ("\n\n" if message else '') + ''.join(traceback.format_exception(*exc_info))
    django_mail_admins(subject, message, fail_silently=True)
コード例 #8
0
ファイル: utils.py プロジェクト: iQuISE/iquise-website
def mail_admins(subj, msg, user=None, **kwargs):
    if settings.DEBUG: # We'll use the standard debugging logic in send_mail
        return send_mail(subj, msg,  ADMIN_EMAILS, user=user, **kwargs)
    return django_mail_admins(subj, msg, **kwargs)