예제 #1
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."
예제 #2
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]
예제 #3
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**")
예제 #4
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."
예제 #5
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 ***")
예제 #6
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**")
예제 #7
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 ***")
예제 #8
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()