def log_import(integration_or_setting):
    log.info("CREATED: %r" % integration_or_setting)


try:
    Configuration.load()
    _db = production_session()

    # Import CDN configuration.
    cdn_conf = Configuration.integration(u'CDN')

    if cdn_conf and isinstance(cdn_conf, dict):
        for k, v in cdn_conf.items():
            cdn = EI(protocol=EI.CDN, goal=EI.CDN_GOAL)
            _db.add(cdn)
            cdn.url = unicode(v)
            cdn.setting(
                Configuration.CDN_MIRRORED_DOMAIN_KEY).value = unicode(k)
            log_import(cdn)

    # Import Elasticsearch configuration.
    elasticsearch_conf = Configuration.integration(u'Elasticsearch')
    if elasticsearch_conf:
        url = elasticsearch_conf.get('url')
        works_index = elasticsearch_conf.get(
            ExternalSearchIndex.WORKS_INDEX_KEY)

        integration = EI(protocol=EI.ELASTICSEARCH, goal=EI.SEARCH_GOAL)
        _db.add(integration)

        if url:
Ejemplo n.º 2
0
"""Move log details from the Configuration file into the
database as ExternalIntegrations
"""

import os
import sys
import logging
from nose.tools import set_trace

bin_dir = os.path.split(__file__)[0]
package_dir = os.path.join(bin_dir, "..")
sys.path.append(os.path.abspath(package_dir))

from config import Configuration
from model import (
    ExternalIntegration as EI,
    production_session,
)

_db = production_session()
log = logging.getLogger(name="Log configuration import")
loggly_conf = Configuration.integration(u'loggly')

if loggly_conf:
    integration = EI(goal=EI.LOGGING_GOAL, protocol=EI.LOGGLY)
    _db.add(integration)
    integration.url = loggly_conf.get(
        'url', 'https://logs-01.loggly.com/inputs/%(token)s/tag/python/')
    integration.password = loggly_conf.get('token')
_db.commit()
database as ExternalIntegrations
"""

import os
import sys
import logging
from nose.tools import set_trace

bin_dir = os.path.split(__file__)[0]
package_dir = os.path.join(bin_dir, "..")
sys.path.append(os.path.abspath(package_dir))

from config import Configuration
from model import (
    ExternalIntegration as EI,
    production_session,
)
_db = production_session()
log = logging.getLogger(name="Log configuration import")
loggly_conf = Configuration.integration(u'loggly')

if loggly_conf:
    integration = EI(goal=EI.LOGGING_GOAL, protocol=EI.LOGGLY)
    _db.add(integration)
    integration.url = loggly_conf.get(
        'url', 'https://logs-01.loggly.com/inputs/%(token)s/tag/python/'
    )
    integration.password = loggly_conf.get('token')
_db.commit()

def log_import(integration_or_setting):
    log.info("CREATED: %r" % integration_or_setting)

try:
    Configuration.load()
    _db = production_session()

    # Import CDN configuration.
    cdn_conf = Configuration.integration(u'CDN')

    if cdn_conf and isinstance(cdn_conf, dict):
        for k, v in cdn_conf.items():
            cdn = EI(protocol=EI.CDN, goal=EI.CDN_GOAL)
            _db.add(cdn)
            cdn.url = unicode(v)
            cdn.setting(Configuration.CDN_MIRRORED_DOMAIN_KEY).value = unicode(k)
            log_import(cdn)

    # Import Elasticsearch configuration.
    elasticsearch_conf = Configuration.integration(u'Elasticsearch')
    if elasticsearch_conf:
        url = elasticsearch_conf.get('url')
        works_index = elasticsearch_conf.get(ExternalSearchIndex.WORKS_INDEX_KEY)

        integration = EI(protocol=EI.ELASTICSEARCH, goal=EI.SEARCH_GOAL)
        _db.add(integration)

        if url:
            integration.url = unicode(url)
        if works_index: