コード例 #1
0
    def donation_to_msg(self, donation, twitter=True):
        """
        Converts donation to the message
        :param donation:
        :param twitter:
        :return:
        """
        to_del = ['MGR.', 's.r.o.', 'Ing.', 'a.s.', 'PhD.']

        tmp = donation.donor.upper()
        for s in to_del:
            tmp = tmp.replace(s.upper(), "")

        initials = ""
        for x in tmp.split():
            initials += x[0]

        money = "{}Kč".format(donation.amount).replace('.', ',')
        if twitter:
            if donation.message is None or len(donation.message) == 0:
                return money

            msg = "{}: {}".format(money, util.utf8ize(donation.message))
            return util.smart_truncate(msg, length=139)

        else:
            if donation.message is None or len(donation.message) == 0:
                return '%s: %s' % (util.utf8ize(donation.donor), money)

            msg = "{} ({}): {}".format(util.utf8ize(initials), money,
                                       util.utf8ize(donation.message))
            return msg
コード例 #2
0
ファイル: differ.py プロジェクト: brianr/lol-logwatcher
def process_completed_error(local_err_msg, lolfly_error, debug, db_inject):
    # parse out the error some more and gather data
    location, line_number, method, exception = util.parse_error_string(local_err_msg)

    # set the info inside our lolfly dictionary
    lolfly_error.error_msg = util.smart_truncate(local_err_msg, 
                                                 length=MAX_MSG_LENGTH,
                                                 suffix=MAX_MSG_SUFFIX)
    lolfly_error.exception = util.smart_truncate(exception, length=MAX_EXC_LENGTH,
                                                 suffix=MAX_EXC_SUFFIX)
    lolfly_error.line_number = line_number
    lolfly_error.location = util.smart_truncate(location,
                                                length=MAX_LOCATION_LENGTH,
                                                suffix=MAX_LOCATION_SUFFIX)
    lolfly_error.method = method

    if debug: lolfly_error.print_pretty()
    if db_inject: lolfly_error.differ_db_inject()

    return location, line_number, method, exception
コード例 #3
0
def truncate_error_message(error_message, length=146, suffix='...'):
    bug_title = util.smart_truncate(error_message)
    bug_title = bug_title.replace('\n', ' ').replace('\t', ' ')
    for fmt in util.DATE_FMT:
        bug_title = re.sub(fmt, '', bug_title)
    return bug_title
コード例 #4
0
ファイル: differ.py プロジェクト: brianr/lol-logwatcher
def scan_file(filename, differ_db, log_pos=0, debug=False, db_inject=False):
    error_msg = ''
    local_err_msg = ''

    # Check if we have permissions to even read the file
    # in question
    if not os.access(filename, os.R_OK):
        util.write_log('%s unable to read due to permissions' % filename)
        return log_pos, error_msg

    logfile = open(filename, 'r')
    logfile.seek(log_pos)

    tail = None
    gotmatch = False
    lolfly_error = differdb.LolflyError(filename, differ_db)

    for line in logfile:
        if ERROR_PATTERN.search(line) and util.check_valid_error(line):
            # We match, start outputting. 
            if tail is None:
                util.write_log('got match in file : %s' % filename)
                tail = MAX_LINES
            local_err_msg += util.smart_truncate(line, length=MAX_LINE_LENGTH, 
                                                 suffix=MAX_LINE_SUFFIX)
            log_pos = logfile.tell()
            tail -= 1
            gotmatch = True

        elif gotmatch and (re.match(PASTE_DATE_FORMAT, line) or 
                           END_PATTERN.search(line) or
                           re.match(PYLONS_DATE_FORMAT, line)):
            # add on to the local_err_msg
            # and then update the bigger message
            local_err_msg += util.smart_truncate(line, length=MAX_LINE_LENGTH,
                                                        suffix=MAX_LINE_SUFFIX)
            error_msg += local_err_msg

            process_completed_error(local_err_msg, lolfly_error, debug, db_inject)

            # reset variables
            lolfly_error.initialize()
            local_err_msg = ''
            tail = None
            gotmatch = False

        elif tail > 0:
            local_err_msg += util.smart_truncate(line, length=MAX_LINE_LENGTH,
                                                 suffix=MAX_LINE_SUFFIX)
            log_pos = logfile.tell()
            tail -= 1

        elif tail == 0:
            # add on to the local_err_msg
            # and then update the bigger message
            error_msg += local_err_msg

            process_completed_error(local_err_msg, lolfly_error, debug, db_inject)

            # reset variables
            lolfly_error.initialize()
            local_err_msg = ''
            tail = None
            gotmatch = False

        else:
            log_pos = logfile.tell()

    error_msg += local_err_msg

    if local_err_msg:
        process_completed_error(local_err_msg, lolfly_error, debug, db_inject)

    return log_pos, error_msg
コード例 #5
0
ファイル: lolfly.py プロジェクト: brianr/lol-logwatcher
def file_errors(limit=1):
    case_count = 0
    case_list = []
    product_list = []
    yearmonth = time.strftime("%Y%m")
    msg = ""

    differ = differdb.DifferDB()

    # Sometimes, fogbugz ain't the happiest, so let's try handling some
    # of the exceptions that can arise from it
    try:
        fbz = fbz_filer.FBZ()
    except fogbugz.FogBugzLogonError:
        msg += util.write_log("unable to login to fogbugz, exiting...")
        return case_count, case_list, product_list, msg
    except:
        # General exception catch-all. It appears some of the vendor libraries don't import things
        # in a friendly way for things like pychecker
        msg += util.write_log("problems talking to fogbugz, exiting...")
        return case_count, case_list, product_list, msg

    # First section, get the errors that have exceptions
    for i in differ.get_grouped_unfiled_exceptions():
        code_location = i.code_location
        code_method = i.code_method
        exception = i.exception
        bug_count = i.count
        error_message = i.error_message
        host = i.host
        logfile = i.logfile

        log_location = "%s:%s" % (host, logfile)

        if exception == "pkg_resources.ExtractionError" and code_method == "extraction_error":
            product = "IGNORE_THIS_ERROR"
        elif exception == "socket.error" and code_method == "bind":
            product = "IGNORE_THIS_ERROR"
        elif code_location and code_location.startswith("/var/www/"):
            product = code_location.split("/")[3]
        elif code_location and code_location.startswith("/usr"):
            product = "ops"
        else:
            product = None

        # Sometimes there's an error that happens and you're going
        # to ignore it, so let's just keep on looping
        if product == "IGNORE_THIS_ERROR":
            differ.update_group_case_id(-1, code_location, code_method, exception)
            differ.update_group_product(product, -1, code_location, code_method, exception)
            msg += util.write_log("IGNORED: %s %s on %s" % (code_method, exception, host))
            continue

        error_message = util.smart_truncate(error_message, length=MAX_BODY_LEN)

        # might as well strip the /var/www/ in the fbz title
        fbz_code_location = code_location
        if fbz_code_location and fbz_code_location.startswith("/var/www/"):
            fbz_code_location = fbz_code_location[9:]

        bug_title = "%s %s:%s" % (exception, fbz_code_location, code_method)
        bug_text = "%s error(s)\n---- %s ----\n%s" % (bug_count, log_location, error_message)

        # There is still some debugging to do as to why some output isn't getting submitted
        # properly. Until then, wrap the case section in a try/except so that the general
        # automation still works
        try:
            case, priority = fbz.file_case(product, bug_title, bug_text)
            differ.update_group_case_id(case, code_location, code_method, exception)
            differ.update_group_product(product, case, code_location, code_method, exception)

            log_output = "%sx p%s %s %s %s:%s:%s" % (
                bug_count,
                priority,
                product,
                exception,
                host,
                code_location,
                code_method,
            )
            util.write_log(log_output)

            if priority <= 5:
                email_output = "%s\n%s/?%s\n\n" % (log_output, FBZ_URL, case)
                msg += email_output
                case_count += 1
                case_list.append(case)
                product_list.append(product)

        except fogbugz.FogBugzConnectionError:
            # We've been seeing that with this error, if we truncate off some of the text after
            # WSGI variables, we're good
            bug_text = bug_text.split("WSGI Variables")[0]

            case, priority = fbz.file_case(product, bug_title, bug_text)
            differ.update_group_case_id(case, code_location, code_method, exception)
            differ.update_group_product(product, case, code_location, code_method, exception)

            log_output = "%sx p%s %s %s %s:%s:%s" % (
                bug_count,
                priority,
                product,
                exception,
                host,
                code_location,
                code_method,
            )
            util.write_log(log_output)

            if priority <= 5:
                email_output = "%s\n%s/?%s\n\n" % (log_output, FBZ_URL, case)
                msg += email_output
                case_count += 1
                case_list.append(case)
                product_list.append(product)

        except:
            traceback.print_exc(sys.stdout)
            msg += util.write_log(
                "LOLFLY ERROR: submitting info for %s %s %s" % (code_location, code_method, exception)
            )
            util.mail_it(ERROR_TO, MAIL_FROM, "DIFFER GOT AN ERROR", msg, REPLY_TO)

    # second section, get the errors without exceptions
    for i in differ.get_unfiled_nonexceptions(limit=limit):
        errorid = i.id
        timestamp = i.timestamp
        host = i.host
        logfile = i.logfile
        error_message = i.error_message

        log_location = "%s:%s" % (host, logfile)
        error_message = util.smart_truncate(error_message, length=MAX_BODY_LEN)

        # the message isn't formatted in any way we recognize, so just grab the first line
        bug_title = error_message.split("\n")[0]
        bug_title = util.smart_truncate(bug_title, length=MAX_TITLE_LEN)

        if logfile.startswith("/var/log/mysql"):
            product = "ops"
        elif LOL_ERROR.search(bug_title):
            product = LOL_ERROR.search(bug_title).group(1)
        else:
            product = None

        # attempt to strip out date information at the beginning of the title
        for fmt in util.DATE_FMT:
            bug_title = re.sub(fmt, "", bug_title)

        bug_text = "1 error(s)\n--%s--\n%s" % (log_location, error_message)

        try:
            case, priority = fbz.file_case(product, bug_title, bug_text)
            util.write_log("update_case_id(%s, %s)" % (errorid, case))
            differ.update_case_id(errorid, case)

            log_output = '1x p%s %s %s:"%s"' % (priority, product, host, bug_title)
            util.write_log(log_output)

            if priority <= 5:
                email_output = "%s\n%s/?%s\n\n" % (log_output, FBZ_URL, case)
                msg += email_output
                case_count += 1
                case_list.append(case)
                product_list.append(product)

        except fogbugz.FogBugzConnectionError:
            bug_text = util.smart_truncate(bug_text, length=MAX_BODY_LEN)
            case, priority = fbz.file_case(product, bug_title, bug_text)
            differ.update_case_id(errorid, case)

            log_output = '1x p%s %s %s:"%s"' % (priority, product, host, bug_title)
            util.write_log(log_output)

            if priority <= 5:
                email_output = "%s\n%s/?%s\n\n" % (log_output, FBZ_URL, case)
                msg += email_output
                case_count += 1
                case_list.append(case)
                product_list.append(product)

        except fogbugz.FogBugzAPIError, exc:
            traceback.print_exc(sys.stdout)
            errmsg = "LOLFLY ERROR: got %r when filing a case for (%r, %r, %s)" % (
                exc,
                product,
                bug_title,
                repr(bug_text)[:40] + "...",
            )
            util.write_log(errmsg)
            msg += errmsg
            msg += "\n\n"