コード例 #1
0
def handleTraceback(object):
    context = object.context
    entry_url = object.entry_url

    if entry_url is None:
        return

    log("handle traceback [%s]" % entry_url)
    try:
        cleanup_lock.acquire()
        # we don't want to produce any errors here, thus, we'll be nice and die
        # silently if an error occurs here
        try:
            transaction.begin()
            # get our logbook view to use the api
            logbook = context.unrestrictedTraverse('@@logbook')
            # get the generated error url from Products.SiteErrorLog
            err_id = urllib.splitvalue(entry_url)[1]
            # save error
            logbook.save_error(err_id, context=aq_base(aq_parent(context)))
            transaction.get().note('collective.logbook traceback [%s]' %
                                   entry_url)
            transaction.commit()
        finally:
            cleanup_lock.release()
    # only warning
    except Exception, e:
        log("An error occured while handling the traceback", level="warning")
        log("%s" % e, level="warning")
        LOGGER.exception(e)
コード例 #2
0
 def run(self):
     try:
         self.data = urllib.urlencode(self.data)
         r = urllib2.urlopen(self.url, self.data)
         r.read()
     except Exception as e:
         LOGGER.error(e)
         LOGGER.exception(e)
コード例 #3
0
def uninstall_storages(portal):
    annotations = IAnnotations(portal)
    if annotations.get(STORAGE_KEY):
        LOGGER.info("*** UNINSTALL collective.logbook Logstorage ***")
        del annotations[STORAGE_KEY]

    if annotations.get(INDEX_KEY):
        LOGGER.info("*** UNINSTALL collective.logbook Indexstorage ***")
        del annotations[INDEX_KEY]
コード例 #4
0
def install(portal):
    setup_tool = getToolByName(portal, 'portal_setup')
    setup_tool.runAllImportStepsFromProfile('profile-collective.logbook:default')

    # install monkey
    install_monkey()

    LOGGER.info("*** INSTALLED collective.logbook ***")
    return "Ran all import steps."
コード例 #5
0
def initialize(context):
    """ Initializer called when used as a Zope 2 product. """
    from Zope2 import bobo_application
    app = bobo_application()

    enabled = app is not None and app.getProperty("logbook_enabled", False)

    if enabled:
        monkey.install_monkey()
        LOGGER.info(">>> logging **enabled**")
    else:
        LOGGER.info(">>> logging **disabled**")
コード例 #6
0
def uninstall(portal):
    setup_tool = getToolByName(portal, 'portal_setup')
    setup_tool.runAllImportStepsFromProfile('profile-collective.logbook:uninstall')

    # remove monkey
    uninstall_monkey()

    # remove storages
    uninstall_storages(portal)

    LOGGER.info("*** UNINSTALLED collective.logbook ***")
    return "Ran all uninstall steps."
コード例 #7
0
 def run(self):
     orignal_timeout = socket.getdefaulttimeout()
     try:
         self.data = urllib.urlencode(self.data)
         socket.setdefaulttimeout(WEBHOOK_HTTP_TIMEOUT)
         r = urllib2.urlopen(self.url, self.data)
         r.read()
     except Exception as e:
         logger.error(e)
         logger.exception(e)
     finally:
         socket.setdefaulttimeout(orignal_timeout)
コード例 #8
0
def uninstall_properties(portal):
    """ uninstall logbook properties to the Zope root
    """

    app = portal.getParentNode()

    # remove logbook properties
    if PROP_KEY_LOG_ENABLED in app.propertyIds():
        app.manage_delProperties([PROP_KEY_LOG_ENABLED, ])

    if PROP_KEY_LOG_MAILS in app.propertyIds():
        app.manage_delProperties([PROP_KEY_LOG_MAILS, ])

    LOGGER.info("*** UNINSTALL collective.logbook properties ***")
コード例 #9
0
def initialize(context):
    """ Initializer called when used as a Zope 2 product. """

    # The registry isn't available at that time, so for
    # now assume it's always enabled.
    
    #registry = getUtility(IRegistry)
    #enabled = registry.get('logbook.logbook_enabled')
    enabled = True

    if enabled:
        monkey.install_monkey()
        LOGGER.info(">>> logging **enabled**")
    else:
        LOGGER.info(">>> logging **disabled**")
コード例 #10
0
def install_properties(portal):
    """ install logbook properties to the Zope root
    """

    app = portal.getParentNode()

    # add logbook log enabled property
    if PROP_KEY_LOG_ENABLED not in app.propertyIds():
        app.manage_addProperty(PROP_KEY_LOG_ENABLED, True, 'boolean')

    # add logbook log mails property
    if PROP_KEY_LOG_MAILS not in app.propertyIds():
        app.manage_addProperty(PROP_KEY_LOG_MAILS, (), 'lines')

    LOGGER.info("*** INSTALL collective.logbook properties ***")
コード例 #11
0
    def __call__(self, event):
        error = event.error
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        registry = getUtility(IRegistry)
        urls = registry.get('logbook.logbook_webhook_urls')

        if not urls:
            return

        subject = "[collective.logbook] NEW TRACEBACK: '%s'" % (
            error.get("value"))
        date = error.get("time").strftime("%Y-%m-%d %H:%M:%S"),
        traceback = "\n".join(error.get("tb_text").split("\n")[-3:])
        # error_number = error.get("id")
        error_url = error.get("url")
        logbook_url = (
            portal.absolute_url() + "/@@logbook?errornumber=%s" %
            error.get("id"))
        # req_html = error.get("req_html")

        message = "%s\n%s\n%s\n%s\n%s\n" % (
            subject, date, traceback,
            error_url, logbook_url)

        LOGGER.info("Calling webhooks")
        LOGGER.info("Webhook urls:\n%s" % ("\n".join(urls)))

        for url in urls:

            url = url.strip()

            # Emptry url
            if not url:
                continue

            t = UrlThread(url, {'data': message})
            t.start()
コード例 #12
0
def log(msg, level=LOGLEVEL):
    """Log the message
    """
    # get the numeric value of the level. defaults to 0 (NOTSET)
    level = logging._levelNames.get(level.upper(), 0)
    LOGGER.log(level, msg)