• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python logger.load_obj函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shinken.log.logger.load_obj函数的典型用法代码示例。如果您正苦于以下问题:Python load_obj函数的具体用法?Python load_obj怎么用?Python load_obj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了load_obj函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_human_timestamp_format

    def test_human_timestamp_format(self):
        "test output using the human timestamp format"
        shinken_logger.setLevel(INFO)
        self._collector = Collector()
        sys.stdout = StringIO()
        shinken_logger.handlers[0].stream = sys.stdout
        shinken_logger.load_obj(self._collector)
        shinken_logger.set_human_format(True)
        if isinstance(shinken_logger.handlers[0], ColorStreamHandler):
            loglist = self.generic_tst(shinken_logger.info, 'Some log-message',
                             [1, 1],
                             [r'^\[.+?\] INFO: \[Shinken\] Some log-message$',
                              r'^\x1b\[35m\[.+?\] INFO: \[Shinken\] Some log-message\x1b\[0m$'])
        else:
            loglist = self.generic_tst(shinken_logger.info, 'Some log-message',
                             [1, 1],
                             [r'^\[.+?\] INFO: \[Shinken\] Some log-message$',
                              r'^\[.+?\] INFO: \[Shinken\] Some log-message$'])


        times = loglist[1][0].split(' INFO: ', 1)[0]
        _, time2 = times.rsplit('[', 1)
        time.strptime(time2.rsplit(']')[0], '%a %b %d %H:%M:%S %Y')

        logger.set_human_format(False)
开发者ID:cedef,项目名称:shinken,代码行数:25,代码来源:test_logging.py


示例2: test_basic_logging_log

 def test_basic_logging_log(self):
     sys.stdout = StringIO()
     self._collector = Collector()
     sh = StreamHandler(sys.stdout)
     sh.setFormatter(defaultFormatter)
     shinken_logger.handlers = []
     shinken_logger.addHandler(sh)
     shinken_logger.load_obj(self._collector)
     shinken_logger.setLevel(DEBUG)
     self.generic_tst(lambda x: naglog_result('info', x), 'Some log-message',
                      [1, 1], [r'^\[\d+\] Some log-message\n$', r'^\[\d+\] Some log-message$'])
开发者ID:FlorianLudwig,项目名称:shinken,代码行数:11,代码来源:test_logging.py


示例3: __init__

    def __init__(self, file):

        logger.load_obj(Dummy())
        self.conf = Config()
        buf = self.conf.read_config([file])
        raw_objects = self.conf.read_config_buf(buf)
        self.conf.create_objects_for_type(raw_objects, 'arbiter')
        self.conf.create_objects_for_type(raw_objects, 'module')
        self.conf.early_arbiter_linking()
        self.conf.create_objects(raw_objects)
        for mod in self.conf.modules:
            if mod.module_type == 'logstore_sqlite':
                self.mod_sqlite = get_instance_sqlite(mod)
                self.mod_sqlite.init()
            if mod.module_type == 'logstore_mongodb':
                self.mod_mongodb = get_instance_mongodb(mod)
开发者ID:0pc0deFR,项目名称:shinken,代码行数:16,代码来源:sql2mdb.py


示例4: test_basic_logging_info_colored

 def test_basic_logging_info_colored(self):
     shinken_logger.setLevel(INFO)
     self._collector = Collector()
     sys.stdout = StringIO()
     shinken_logger.handlers[0].stream = sys.stdout
     shinken_logger.load_obj(self._collector)
     if isinstance(shinken_logger.handlers[0], ColorStreamHandler):
         self.generic_tst(shinken_logger.info, 'Some log-message',
                          [1, 1],
                          [r'^\[.+?\] INFO: \[Shinken\] Some log-message$',
                           r'^\x1b\[95m\[.+?\] INFO: \[Shinken\] Some log-message\x1b\[0m$'])
     else:
         self.generic_tst(shinken_logger.info, 'Some log-message',
                          [1, 1],
                          [r'^\[.+?\] INFO:\s+Some log-message$',
                           r'^\[.+?\] INFO:\s+Some log-message$'])
开发者ID:andyxning,项目名称:shinken,代码行数:16,代码来源:test_logging.py


示例5: _prepare_logging

 def _prepare_logging(self):
     self._collector = Collector()
     logger.load_obj(self._collector, 'Tiroler Schinken')
     self._stdout = sys.stdout
     sys.stdout = StringIO()
开发者ID:adenir2202,项目名称:shinken,代码行数:5,代码来源:test_logging.py


示例6: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.cur_conf = conf
        # Got our name from the globals
        g_conf = conf['global']
        if 'broker_name' in g_conf:
            name = g_conf['broker_name']
        else:
            name = 'Unnamed broker'
        self.name = name
        props_to_get = ['broks_batch', 'api_key', 'secret', 'http_proxy',
                        'statsd_host', 'statsd_port', 'statsd_prefix',
                        'statsd_enabled', 'statsd_interval', 'statsd_types',
                        'statsd_pattern']
        for prop in props_to_get:
            v = g_conf[prop]
            setattr(self, prop, v)
        self.harakiri_threshold = parse_memory_expr(g_conf['harakiri_threshold'])

        if self.harakiri_threshold is not None:
            self.raw_conf = self.new_conf
        else:
            self.raw_conf = None
        self.new_conf = None
        if self.aggressive_memory_management:
            free_memory()
        # We got a name so we can update the logger and the stats global objects
        logger.load_obj(self, name)
        statsmgr.register(self, name, 'broker',
                          api_key=self.api_key,
                          secret=self.secret,
                          http_proxy=self.http_proxy,
                          statsd_host=self.statsd_host,
                          statsd_port=self.statsd_port,
                          statsd_prefix=self.statsd_prefix,
                          statsd_enabled=self.statsd_enabled,
                          statsd_interval=self.statsd_interval,
                          statsd_types=self.statsd_types,
                          statsd_pattern=self.statsd_pattern)

        logger.debug("[%s] Sending us configuration %s", self.name, conf)
        # If we've got something in the schedulers, we do not
        # want it anymore
        # self.schedulers.clear()
        for sched_id in conf['schedulers']:
            # Must look if we already have it to do not overdie our broks
            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf['schedulers'][sched_id]['address']
                old_addr = self.schedulers[sched_id]['address']
                new_port = conf['schedulers'][sched_id]['port']
                old_port = self.schedulers[sched_id]['port']
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                broks = self.schedulers[sched_id]['broks']
                running_id = self.schedulers[sched_id]['running_id']
            else:
                broks = []
                running_id = 0
            s = conf['schedulers'][sched_id]
            self.schedulers[sched_id] = s

            # replacing scheduler address and port by those defined in satellitemap
            if s['name'] in g_conf['satellitemap']:
                s = dict(s)  # make a copy
                s.update(g_conf['satellitemap'][s['name']])
            proto = 'http'
            if s['use_ssl']:
                proto = 'https'
            uri = '%s://%s:%s/' % (proto, s['address'], s['port'])
            self.schedulers[sched_id]['uri'] = uri

            self.schedulers[sched_id]['broks'] = broks
            self.schedulers[sched_id]['instance_id'] = s['instance_id']
            self.schedulers[sched_id]['running_id'] = running_id
            self.schedulers[sched_id]['active'] = s['active']
            self.schedulers[sched_id]['last_connection'] = 0
            self.schedulers[sched_id]['timeout'] = s['timeout']
            self.schedulers[sched_id]['data_timeout'] = s['data_timeout']

        logger.info("We have our schedulers: %s ", self.schedulers)

        # Now get arbiter
        for arb_id in conf['arbiters']:
            # Must look if we already have it
            already_got = arb_id in self.arbiters
            if already_got:
                broks = self.arbiters[arb_id]['broks']
            else:
                broks = []
            a = conf['arbiters'][arb_id]
            self.arbiters[arb_id] = a

            # replacing arbiter address and port by those defined in satellitemap
            if a['name'] in g_conf['satellitemap']:
#.........这里部分代码省略.........
开发者ID:geektophe,项目名称:shinken,代码行数:101,代码来源:brokerdaemon.py


示例7: add

from shinken.daemons.arbiterdaemon import Arbiter
from shinken.daemons.receiverdaemon import Receiver
from logging import ERROR

# Modules are by default on the ../modules
myself = os.path.abspath(__file__)

global modules_dir
modules_dir = os.environ.get('SHINKEN_MODULES_DIR', "modules")


class __DUMMY:
    def add(self, obj):
        pass

logger.load_obj(__DUMMY())
logger.setLevel(ERROR)

#############################################################################

def guess_sys_stdout_encoding():
    ''' Return the best guessed encoding to be used for printing on sys.stdout. '''
    return (
           getattr(sys.stdout, 'encoding', None)
        or getattr(__stdout__, 'encoding', None)
        or locale.getpreferredencoding()
        or sys.getdefaultencoding()
        or 'ascii'
    )

开发者ID:Aimage,项目名称:shinken,代码行数:29,代码来源:shinken_test.py


示例8: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.new_conf = None
        self.cur_conf = conf
        # Got our name from the globals
        if 'receiver_name' in conf['global']:
            name = conf['global']['receiver_name']
        else:
            name = 'Unnamed receiver'
        self.name = name
        self.api_key = conf['global']['api_key']
        self.secret = conf['global']['secret']
        self.http_proxy = conf['global']['http_proxy']
        self.statsd_host = conf['global']['statsd_host']
        self.statsd_port = conf['global']['statsd_port']
        self.statsd_prefix = conf['global']['statsd_prefix']
        self.statsd_enabled = conf['global']['statsd_enabled']

        statsmgr.register(self, self.name, 'receiver',
                          api_key=self.api_key, secret=self.secret, http_proxy=self.http_proxy,
                          statsd_host=self.statsd_host, statsd_port=self.statsd_port,
                          statsd_prefix=self.statsd_prefix, statsd_enabled=self.statsd_enabled)
        logger.load_obj(self, name)
        self.direct_routing = conf['global']['direct_routing']
        self.accept_passive_unknown_check_results = \
            conf['global']['accept_passive_unknown_check_results']

        g_conf = conf['global']

        # If we've got something in the schedulers, we do not want it anymore
        for sched_id in conf['schedulers']:

            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf['schedulers'][sched_id]['address']
                old_addr = self.schedulers[sched_id]['address']
                new_port = conf['schedulers'][sched_id]['port']
                old_port = self.schedulers[sched_id]['port']
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                logger.info("[%s] We already got the conf %d (%s)",
                            self.name, sched_id, conf['schedulers'][sched_id]['name'])
                wait_homerun = self.schedulers[sched_id]['wait_homerun']
                actions = self.schedulers[sched_id]['actions']
                external_commands = self.schedulers[sched_id]['external_commands']
                con = self.schedulers[sched_id]['con']

            s = conf['schedulers'][sched_id]
            self.schedulers[sched_id] = s

            if s['name'] in g_conf['satellitemap']:
                s.update(g_conf['satellitemap'][s['name']])

            proto = 'http'
            if s['use_ssl']:
                proto = 'https'
            uri = '%s://%s:%s/' % (proto, s['address'], s['port'])

            self.schedulers[sched_id]['uri'] = uri
            if already_got:
                self.schedulers[sched_id]['wait_homerun'] = wait_homerun
                self.schedulers[sched_id]['actions'] = actions
                self.schedulers[sched_id]['external_commands'] = external_commands
                self.schedulers[sched_id]['con'] = con
            else:
                self.schedulers[sched_id]['wait_homerun'] = {}
                self.schedulers[sched_id]['actions'] = {}
                self.schedulers[sched_id]['external_commands'] = []
                self.schedulers[sched_id]['con'] = None
            self.schedulers[sched_id]['running_id'] = 0
            self.schedulers[sched_id]['active'] = s['active']
            self.schedulers[sched_id]['timeout'] = s['timeout']
            self.schedulers[sched_id]['data_timeout'] = s['data_timeout']

            # Do not connect if we are a passive satellite
            if self.direct_routing and not already_got:
                # And then we connect to it :)
                self.pynag_con_init(sched_id)



        logger.debug("[%s] Sending us configuration %s", self.name, conf)

        if not self.have_modules:
            self.modules = mods = conf['global']['modules']
            self.have_modules = True
            logger.info("We received modules %s ", mods)

        # Set our giving timezone from arbiter
        use_timezone = conf['global']['use_timezone']
        if use_timezone != 'NOTSET':
            logger.info("Setting our timezone to %s", use_timezone)
            os.environ['TZ'] = use_timezone
            time.tzset()
开发者ID:Omega-Cube,项目名称:shinken,代码行数:99,代码来源:receiverdaemon.py


示例9: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.new_conf = None
        self.cur_conf = conf
        # Got our name from the globals
        g_conf = conf['global']
        if 'broker_name' in g_conf:
            name = g_conf['broker_name']
        else:
            name = 'Unnamed broker'
        self.name = name
        logger.load_obj(self, name)

        logger.debug("[%s] Sending us configuration %s" % (self.name, conf))
        # If we've got something in the schedulers, we do not
        # want it anymore
        # self.schedulers.clear()
        for sched_id in conf['schedulers']:
            # Must look if we already have it to do not overdie our broks
            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf['schedulers'][sched_id]['address']
                old_addr = self.schedulers[sched_id]['address']
                new_port = conf['schedulers'][sched_id]['port']
                old_port = self.schedulers[sched_id]['port']
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                broks = self.schedulers[sched_id]['broks']
                running_id = self.schedulers[sched_id]['running_id']
            else:
                broks = {}
                running_id = 0
            s = conf['schedulers'][sched_id]
            self.schedulers[sched_id] = s

            # replacing scheduler address and port by those defined in satellitemap
            if s['name'] in g_conf['satellitemap']:
                s = dict(s)  # make a copy
                s.update(g_conf['satellitemap'][s['name']])
            uri = pyro.create_uri(s['address'], s['port'], 'Broks', self.use_ssl)
            self.schedulers[sched_id]['uri'] = uri

            self.schedulers[sched_id]['broks'] = broks
            self.schedulers[sched_id]['instance_id'] = s['instance_id']
            self.schedulers[sched_id]['running_id'] = running_id
            self.schedulers[sched_id]['active'] = s['active']
            self.schedulers[sched_id]['last_connection'] = 0

        logger.info("We have our schedulers: %s " % self.schedulers)

        # Now get arbiter
        for arb_id in conf['arbiters']:
            # Must look if we already have it
            already_got = arb_id in self.arbiters
            if already_got:
                broks = self.arbiters[arb_id]['broks']
            else:
                broks = {}
            a = conf['arbiters'][arb_id]
            self.arbiters[arb_id] = a

            # replacing arbiter address and port by those defined in satellitemap
            if a['name'] in g_conf['satellitemap']:
                a = dict(a)  # make a copy
                a.update(g_conf['satellitemap'][a['name']])
            uri = pyro.create_uri(a['address'], a['port'], 'Broks', self.use_ssl)
            self.arbiters[arb_id]['uri'] = uri

            self.arbiters[arb_id]['broks'] = broks
            self.arbiters[arb_id]['instance_id'] = 0  # No use so all to 0
            self.arbiters[arb_id]['running_id'] = 0
            self.arbiters[arb_id]['last_connection'] = 0

            # We do not connect to the arbiter. Connection hangs

        logger.info("We have our arbiters: %s " % self.arbiters)

        # Now for pollers
        for pol_id in conf['pollers']:
            # Must look if we already have it
            already_got = pol_id in self.pollers
            if already_got:
                broks = self.pollers[pol_id]['broks']
                running_id = self.schedulers[sched_id]['running_id']
            else:
                broks = {}
                running_id = 0
            p = conf['pollers'][pol_id]
            self.pollers[pol_id] = p

            # replacing poller address and port by those defined in satellitemap
            if p['name'] in g_conf['satellitemap']:
                p = dict(p)  # make a copy
                p.update(g_conf['satellitemap'][p['name']])
            uri = pyro.create_uri(p['address'], p['port'], 'Broks', self.use_ssl)
#.........这里部分代码省略.........
开发者ID:Thibautg16,项目名称:shinken,代码行数:101,代码来源:brokerdaemon.py


示例10: test_load_obj_must_not_change_level

 def test_load_obj_must_not_change_level(self):
     # argl, load_obj() unsets the level! save and restore it
     logger.set_level(logger.CRITICAL)
     logger.load_obj(Dummy())
     self.assertEqual(logger._level, logger.CRITICAL)
开发者ID:adenir2202,项目名称:shinken,代码行数:5,代码来源:test_logging.py


示例11: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.new_conf = None
        self.cur_conf = conf
        # Got our name from the globals
        if 'receiver_name' in conf['global']:
            name = conf['global']['receiver_name']
        else:
            name = 'Unnamed receiver'
        self.name = name
        logger.load_obj(self, name)
        self.direct_routing = conf['global']['direct_routing']

        g_conf = conf['global']

        # If we've got something in the schedulers, we do not want it anymore
        for sched_id in conf['schedulers']:

            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf['schedulers'][sched_id]['address']
                old_addr = self.schedulers[sched_id]['address']
                new_port = conf['schedulers'][sched_id]['port']
                old_port = self.schedulers[sched_id]['port']
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                logger.info("[%s] We already got the conf %d (%s)" % (self.name, sched_id, conf['schedulers'][sched_id]['name']))
                wait_homerun = self.schedulers[sched_id]['wait_homerun']
                actions = self.schedulers[sched_id]['actions']
                external_commands = self.schedulers[sched_id]['external_commands']
                con = self.schedulers[sched_id]['con']

            s = conf['schedulers'][sched_id]
            self.schedulers[sched_id] = s

            if s['name'] in g_conf['satellitemap']:
                s.update(g_conf['satellitemap'][s['name']])
            uri = 'http://%s:%s/' % (s['address'], s['port'])

            self.schedulers[sched_id]['uri'] = uri
            if already_got:
                self.schedulers[sched_id]['wait_homerun'] = wait_homerun
                self.schedulers[sched_id]['actions'] = actions
                self.schedulers[sched_id]['external_commands'] = external_commands
                self.schedulers[sched_id]['con'] = con
            else:
                self.schedulers[sched_id]['wait_homerun'] = {}
                self.schedulers[sched_id]['actions'] = {}
                self.schedulers[sched_id]['external_commands'] = []
                self.schedulers[sched_id]['con'] = None
            self.schedulers[sched_id]['running_id'] = 0
            self.schedulers[sched_id]['active'] = s['active']

            # Do not connect if we are a passive satellite
            if self.direct_routing and not already_got:
                # And then we connect to it :)
                self.pynag_con_init(sched_id)



        logger.debug("[%s] Sending us configuration %s" % (self.name, conf))

        if not self.have_modules:
            self.modules = mods = conf['global']['modules']
            self.have_modules = True
            logger.info("We received modules %s " % mods)

        # Set our giving timezone from arbiter
        use_timezone = conf['global']['use_timezone']
        if use_timezone != 'NOTSET':
            logger.info("Setting our timezone to %s" % use_timezone)
            os.environ['TZ'] = use_timezone
            time.tzset()


        # Now create the external commander. It's just here to dispatch
        # the commands to schedulers
        e = ExternalCommandManager(None, 'receiver')
        e.load_receiver(self)
        self.external_command = e
开发者ID:adenir2202,项目名称:shinken,代码行数:85,代码来源:receiverdaemon.py


示例12: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.new_conf = None
        self.cur_conf = conf
        # Got our name from the globals
        if "receiver_name" in conf["global"]:
            name = conf["global"]["receiver_name"]
        else:
            name = "Unnamed receiver"
        self.name = name
        self.api_key = conf["global"]["api_key"]
        self.secret = conf["global"]["secret"]
        self.http_proxy = conf["global"]["http_proxy"]
        self.statsd_host = conf["global"]["statsd_host"]
        self.statsd_port = conf["global"]["statsd_port"]
        self.statsd_prefix = conf["global"]["statsd_prefix"]
        self.statsd_enabled = conf["global"]["statsd_enabled"]

        statsmgr.register(
            self,
            self.name,
            "receiver",
            api_key=self.api_key,
            secret=self.secret,
            http_proxy=self.http_proxy,
            statsd_host=self.statsd_host,
            statsd_port=self.statsd_port,
            statsd_prefix=self.statsd_prefix,
            statsd_enabled=self.statsd_enabled,
        )
        logger.load_obj(self, name)
        self.direct_routing = conf["global"]["direct_routing"]
        self.accept_passive_unknown_check_results = conf["global"]["accept_passive_unknown_check_results"]

        g_conf = conf["global"]

        # If we've got something in the schedulers, we do not want it anymore
        for sched_id in conf["schedulers"]:

            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf["schedulers"][sched_id]["address"]
                old_addr = self.schedulers[sched_id]["address"]
                new_port = conf["schedulers"][sched_id]["port"]
                old_port = self.schedulers[sched_id]["port"]
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                logger.info(
                    "[%s] We already got the conf %d (%s)", self.name, sched_id, conf["schedulers"][sched_id]["name"]
                )
                wait_homerun = self.schedulers[sched_id]["wait_homerun"]
                actions = self.schedulers[sched_id]["actions"]
                external_commands = self.schedulers[sched_id]["external_commands"]
                con = self.schedulers[sched_id]["con"]

            s = conf["schedulers"][sched_id]
            self.schedulers[sched_id] = s

            if s["name"] in g_conf["satellitemap"]:
                s.update(g_conf["satellitemap"][s["name"]])

            proto = "http"
            if s["use_ssl"]:
                proto = "https"
            uri = "%s://%s:%s/" % (proto, s["address"], s["port"])

            self.schedulers[sched_id]["uri"] = uri
            if already_got:
                self.schedulers[sched_id]["wait_homerun"] = wait_homerun
                self.schedulers[sched_id]["actions"] = actions
                self.schedulers[sched_id]["external_commands"] = external_commands
                self.schedulers[sched_id]["con"] = con
            else:
                self.schedulers[sched_id]["wait_homerun"] = {}
                self.schedulers[sched_id]["actions"] = {}
                self.schedulers[sched_id]["external_commands"] = []
                self.schedulers[sched_id]["con"] = None
            self.schedulers[sched_id]["running_id"] = 0
            self.schedulers[sched_id]["active"] = s["active"]
            self.schedulers[sched_id]["timeout"] = s["timeout"]
            self.schedulers[sched_id]["data_timeout"] = s["data_timeout"]

            # Do not connect if we are a passive satellite
            if self.direct_routing and not already_got:
                # And then we connect to it :)
                self.pynag_con_init(sched_id)

        logger.debug("[%s] Sending us configuration %s", self.name, conf)

        if not self.have_modules:
            self.modules = mods = conf["global"]["modules"]
            self.have_modules = True
            logger.info("We received modules %s ", mods)

        # Set our giving timezone from arbiter
#.........这里部分代码省略.........
开发者ID:hlsolutions,项目名称:shinken,代码行数:101,代码来源:receiverdaemon.py


示例13: __init__

class Collector:
    """Dummy class for collecting broks"""
    def __init__(self):
        self.list = []

    def add(self, o):
        self.list.append(o)


class NoSetup:
    def setUp(self):
        pass



logger.load_obj(Dummy())



class TestLevels(NoSetup, ShinkenTest):

    def test_get_level_id(self):
        for name , level in (
            ('NOTSET',   logger.NOTSET),
            ('DEBUG',    logger.DEBUG),
            ('INFO',     logger.INFO),
            ('WARNING',  logger.WARNING),
            ('ERROR',    logger.ERROR),
            ('CRITICAL', logger.CRITICAL),
            ):
            self.assertEqual(logger.get_level_id(level), name)
开发者ID:adenir2202,项目名称:shinken,代码行数:31,代码来源:test_logging.py


示例14: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.new_conf = None
        self.cur_conf = conf
        # Got our name from the globals
        if "receiver_name" in conf["global"]:
            name = conf["global"]["receiver_name"]
        else:
            name = "Unnamed receiver"
        self.name = name
        logger.load_obj(self, name)
        self.direct_routing = conf["global"]["direct_routing"]

        g_conf = conf["global"]

        # If we've got something in the schedulers, we do not want it anymore
        for sched_id in conf["schedulers"]:

            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf["schedulers"][sched_id]["address"]
                old_addr = self.schedulers[sched_id]["address"]
                new_port = conf["schedulers"][sched_id]["port"]
                old_port = self.schedulers[sched_id]["port"]
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                logger.info(
                    "[%s] We already got the conf %d (%s)" % (self.name, sched_id, conf["schedulers"][sched_id]["name"])
                )
                wait_homerun = self.schedulers[sched_id]["wait_homerun"]
                actions = self.schedulers[sched_id]["actions"]
                external_commands = self.schedulers[sched_id]["external_commands"]
                con = self.schedulers[sched_id]["con"]

            s = conf["schedulers"][sched_id]
            self.schedulers[sched_id] = s

            if s["name"] in g_conf["satellitemap"]:
                s.update(g_conf["satellitemap"][s["name"]])
            uri = "http://%s:%s/" % (s["address"], s["port"])

            self.schedulers[sched_id]["uri"] = uri
            if already_got:
                self.schedulers[sched_id]["wait_homerun"] = wait_homerun
                self.schedulers[sched_id]["actions"] = actions
                self.schedulers[sched_id]["external_commands"] = external_commands
                self.schedulers[sched_id]["con"] = con
            else:
                self.schedulers[sched_id]["wait_homerun"] = {}
                self.schedulers[sched_id]["actions"] = {}
                self.schedulers[sched_id]["external_commands"] = []
                self.schedulers[sched_id]["con"] = None
            self.schedulers[sched_id]["running_id"] = 0
            self.schedulers[sched_id]["active"] = s["active"]

            # Do not connect if we are a passive satellite
            if self.direct_routing and not already_got:
                # And then we connect to it :)
                self.pynag_con_init(sched_id)

        logger.debug("[%s] Sending us configuration %s" % (self.name, conf))

        if not self.have_modules:
            self.modules = mods = conf["global"]["modules"]
            self.have_modules = True
            logger.info("We received modules %s " % mods)

        # Set our giving timezone from arbiter
        use_timezone = conf["global"]["use_timezone"]
        if use_timezone != "NOTSET":
            logger.info("Setting our timezone to %s" % use_timezone)
            os.environ["TZ"] = use_timezone
            time.tzset()

        # Now create the external commander. It's just here to dispatch
        # the commands to schedulers
        e = ExternalCommandManager(None, "receiver")
        e.load_receiver(self)
        self.external_command = e
开发者ID:asteven,项目名称:shinken,代码行数:84,代码来源:receiverdaemon.py


示例15: setup_new_conf

    def setup_new_conf(self):
        conf = self.new_conf
        self.new_conf = None
        self.cur_conf = conf
        # Got our name from the globals
        g_conf = conf["global"]
        if "broker_name" in g_conf:
            name = g_conf["broker_name"]
        else:
            name = "Unnamed broker"
        self.name = name
        logger.load_obj(self, name)

        logger.debug("[%s] Sending us configuration %s" % (self.name, conf))
        # If we've got something in the schedulers, we do not
        # want it anymore
        # self.schedulers.clear()
        for sched_id in conf["schedulers"]:
            # Must look if we already have it to do not overdie our broks
            already_got = False

            # We can already got this conf id, but with another address
            if sched_id in self.schedulers:
                new_addr = conf["schedulers"][sched_id]["address"]
                old_addr = self.schedulers[sched_id]["address"]
                new_port = conf["schedulers"][sched_id]["port"]
                old_port = self.schedulers[sched_id]["port"]
                # Should got all the same to be ok :)
                if new_addr == old_addr and new_port == old_port:
                    already_got = True

            if already_got:
                broks = self.schedulers[sched_id]["broks"]
                running_id = self.schedulers[sched_id]["running_id"]
            else:
                broks = {}
                running_id = 0
            s = conf["schedulers"][sched_id]
            self.schedulers[sched_id] = s

            # replacing scheduler address and port by those defined in satellitemap
            if s["name"] in g_conf["satellitemap"]:
                s = dict(s)  # make a copy
                s.update(g_conf["satellitemap"][s["name"]])
            proto = "http"
            if s["use_ssl"]:
                proto = "https"
            uri = "%s://%s:%s/" % (proto, s["address"], s["port"])
            self.schedulers[sched_id]["uri"] = uri

            self.schedulers[sched_id]["broks"] = broks
            self.schedulers[sched_id]["instance_id"] = s["instance_id"]
            self.schedulers[sched_id]["running_id"] = running_id
            self.schedulers[sched_id]["active"] = s["active"]
            self.schedulers[sched_id]["last_connection"] = 0

        logger.info("We have our schedulers: %s " % self.schedulers)

        # Now get arbiter
        for arb_id in conf["arbiters"]:
            # Must look if we already have it
            already_got = arb_id in self.arbiters
            if already_got:
                broks = self.arbiters[arb_id]["broks"]
            else:
                broks = {}
            a = conf["arbiters"][arb_id]
            self.arbiters[arb_id] = a

            # replacing arbiter address and port by those defined in satellitemap
            if a["name"] in g_conf["satellitemap"]:
                a = dict(a)  # make a copy
                a.update(g_conf["satellitemap"][a["name"]])

            proto = "http"
            if a["use_ssl"]:
                proto = "https"
            uri = "%s://%s:%s/" % (proto, a["address"], a["port"])
            self.arbiters[arb_id]["uri"] = uri

            self.arbiters[arb_id]["broks"] = broks
            self.arbiters[arb_id]["instance_id"] = 0  # No use so all to 0
            self.arbiters[arb_id]["running_id"] = 0
            self.arbiters[arb_id]["last_connection"] = 0

            # We do not connect to the arbiter. Connection hangs

        logger.info("We have our arbiters: %s " % self.arbiters)

        # Now for pollers
        for pol_id in conf["pollers"]:
            # Must look if we already have it
            already_got = pol_id in self.pollers
            if already_got:
                broks = self.pollers[pol_id]["broks"]
                running_id = self.schedulers[sched_id]["running_id"]
            else:
                broks = {}
                running_id = 0
            p = conf["pollers"][pol_id]
#.........这里部分代码省略.........
开发者ID:ppepos,项目名称:shinken,代码行数:101,代码来源:brokerdaemon.py



注:本文中的shinken.log.logger.load_obj函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python logger.log函数代码示例发布时间:2022-05-27
下一篇:
Python logger.info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap