Пример #1
0
    def main(self):
        """Main function for Scheduler, launch after the init::

        * Init daemon
        * Load module manager
        * Launch main loop
        * Catch any Exception that occurs

        :return: None
        """
        try:
            self.load_config_file()
            # Setting log level
            logger.setLevel(self.log_level)
            # Force the debug level if the daemon is said to start with such level
            if self.debug:
                logger.setLevel('DEBUG')

            self.look_for_early_exit()
            self.do_daemon_init_and_start()
            self.load_modules_manager()

            self.uri = self.http_daemon.uri
            logger.info("[scheduler] General interface is at: %s", self.uri)
            self.do_mainloop()
        except Exception, exp:
            self.print_unrecoverable(traceback.format_exc())
            raise
Пример #2
0
    def test_human_timestamp_format(self):
        """test output using the human timestamp format"""
        alignak_logger.setLevel(INFO)
        self._collector = Collector()
        sys.stdout = StringIO()
        alignak_logger.handlers[0].stream = sys.stdout
        alignak_logger.load_obj(self._collector)
        alignak_logger.set_human_format(True)
        if isinstance(alignak_logger.handlers[0], ColorStreamHandler):
            loglist = self.generic_tst(alignak_logger.info, 'Some log-message', [
                1, 1
            ], [
                r'^\[.+?\] INFO: \[Alignak\] Some log-message$',
                r'^\x1b\[35m\[.+?\] INFO: \[Alignak\] Some log-message\x1b\[0m$'
            ])
        else:
            loglist = self.generic_tst(
                alignak_logger.info, 'Some log-message', [1, 1], [
                    r'^\[.+?\] INFO: \[Alignak\] Some log-message$',
                    r'^\[.+?\] INFO: \[Alignak\] 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)
Пример #3
0
    def main(self):
        """Main function for Scheduler, launch after the init::

        * Init daemon
        * Load module manager
        * Launch main loop
        * Catch any Exception that occurs

        :return: None
        """
        try:
            self.load_config_file()
            # Setting log level
            logger.setLevel(self.log_level)
            # Force the debug level if the daemon is said to start with such level
            if self.debug:
                logger.setLevel('DEBUG')

            self.look_for_early_exit()
            self.do_daemon_init_and_start()
            self.load_modules_manager()

            self.uri = self.http_daemon.uri
            logger.info("[scheduler] General interface is at: %s", self.uri)
            self.do_mainloop()
        except Exception, exp:
            self.print_unrecoverable(traceback.format_exc())
            raise
Пример #4
0
    def test_human_timestamp_format(self):
        """test output using the human timestamp format"""
        alignak_logger.setLevel(INFO)
        self._collector = Collector()
        sys.stdout = StringIO()
        alignak_logger.handlers[0].stream = sys.stdout
        alignak_logger.load_obj(self._collector)
        alignak_logger.set_human_format(True)
        if isinstance(alignak_logger.handlers[0], ColorStreamHandler):
            loglist = self.generic_tst(alignak_logger.info, 'Some log-message',
                             [1, 1],
                             [r'^\[.+?\] INFO: \[Alignak\] Some log-message$',
                              r'^\x1b\[35m\[.+?\] INFO: \[Alignak\] Some log-message\x1b\[0m$'])
        else:
            loglist = self.generic_tst(alignak_logger.info, 'Some log-message',
                             [1, 1],
                             [r'^\[.+?\] INFO: \[Alignak\] Some log-message$',
                              r'^\[.+?\] INFO: \[Alignak\] 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)
Пример #5
0
    def main(self):
        """Main satellite function. Do init and then mainloop

        :return: None
        """
        try:
            for line in self.get_header():
                logger.info(line)

            self.load_config_file()

            # Setting log level
            logger.setLevel(self.log_level)
            # Force the debug level if the daemon is said to start with such level
            if self.debug:
                logger.setLevel('DEBUG')

            # Look if we are enabled or not. If ok, start the daemon mode
            self.look_for_early_exit()
            self.do_daemon_init_and_start()

            self.do_post_daemon_init()

            self.load_modules_manager()

            # We wait for initial conf
            self.wait_for_initial_conf()
            if not self.new_conf:  # we must have either big problem or was requested to shutdown
                return
            self.setup_new_conf()

            # We can load our modules now
            self.modules_manager.set_modules(self.modules_manager.modules)
            self.do_load_modules()
            # And even start external ones
            self.modules_manager.start_external_instances()

            # Allocate Mortal Threads
            for _ in xrange(1, self.min_workers):
                to_del = []
                for mod in self.q_by_mod:
                    try:
                        self.create_and_launch_worker(module_name=mod)
                    # Maybe this modules is not a true worker one.
                    # if so, just delete if from q_by_mod
                    except NotWorkerMod:
                        to_del.append(mod)

                for mod in to_del:
                    logger.debug("The module %s is not a worker one, "
                                 "I remove it from the worker list", mod)
                    del self.q_by_mod[mod]

            # Now main loop
            self.do_mainloop()
        except Exception:
            self.print_unrecoverable(traceback.format_exc())
            raise
Пример #6
0
    def main(self):
        """Main satellite function. Do init and then mainloop

        :return: None
        """
        try:
            for line in self.get_header():
                logger.info(line)

            self.load_config_file()

            # Setting log level
            logger.setLevel(self.log_level)
            # Force the debug level if the daemon is said to start with such level
            if self.debug:
                logger.setLevel('DEBUG')

            # Look if we are enabled or not. If ok, start the daemon mode
            self.look_for_early_exit()
            self.do_daemon_init_and_start()

            self.do_post_daemon_init()

            self.load_modules_manager()

            # We wait for initial conf
            self.wait_for_initial_conf()
            if not self.new_conf:  # we must have either big problem or was requested to shutdown
                return
            self.setup_new_conf()

            # We can load our modules now
            self.do_load_modules(self.new_modules_conf)
            # And even start external ones
            self.modules_manager.start_external_instances()

            # Allocate Mortal Threads
            for _ in xrange(1, self.min_workers):
                to_del = []
                for mod in self.q_by_mod:
                    try:
                        self.create_and_launch_worker(module_name=mod)
                    # Maybe this modules is not a true worker one.
                    # if so, just delete if from q_by_mod
                    except NotWorkerMod:
                        to_del.append(mod)

                for mod in to_del:
                    logger.debug(
                        "The module %s is not a worker one, "
                        "I remove it from the worker list", mod)
                    del self.q_by_mod[mod]

            # Now main loop
            self.do_mainloop()
        except Exception:
            self.print_unrecoverable(traceback.format_exc())
            raise
Пример #7
0
 def test_basic_logging_log(self):
     sys.stdout = StringIO()
     self._collector = Collector()
     sh = StreamHandler(sys.stdout)
     sh.setFormatter(DEFAULT_FORMATTER)
     alignak_logger.handlers = []
     alignak_logger.addHandler(sh)
     alignak_logger.load_obj(self._collector)
     alignak_logger.log_set = True
     alignak_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$'])
Пример #8
0
 def test_basic_logging_log(self):
     sys.stdout = StringIO()
     self._collector = Collector()
     sh = StreamHandler(sys.stdout)
     sh.setFormatter(DEFAULT_FORMATTER)
     alignak_logger.handlers = []
     alignak_logger.addHandler(sh)
     alignak_logger.load_obj(self._collector)
     alignak_logger.log_set = True
     alignak_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$'])
Пример #9
0
 def test_basic_logging_info_colored(self):
     alignak_logger.setLevel(INFO)
     self._collector = Collector()
     sys.stdout = StringIO()
     alignak_logger.handlers[0].stream = sys.stdout
     alignak_logger.load_obj(self._collector)
     if isinstance(alignak_logger.handlers[0], ColorStreamHandler):
         self.generic_tst(alignak_logger.info, 'Some log-message',
                          [1, 1],
                          [r'^\[.+?\] INFO: \[Alignak\] Some log-message$',
                           r'^\x1b\[35m\[.+?\] INFO: \[Alignak\] Some log-message\x1b\[0m$'])
     else:
         self.generic_tst(alignak_logger.info, 'Some log-message',
                          [1, 1],
                          [r'^\[.+?\] INFO:\s+Some log-message$',
                           r'^\[.+?\] INFO:\s+Some log-message$'])
Пример #10
0
 def test_basic_logging_info_colored(self):
     alignak_logger.setLevel(INFO)
     self._collector = Collector()
     sys.stdout = StringIO()
     alignak_logger.handlers[0].stream = sys.stdout
     alignak_logger.load_obj(self._collector)
     if isinstance(alignak_logger.handlers[0], ColorStreamHandler):
         self.generic_tst(alignak_logger.info, 'Some log-message', [1, 1], [
             r'^\[.+?\] INFO: \[Alignak\] Some log-message$',
             r'^\x1b\[35m\[.+?\] INFO: \[Alignak\] Some log-message\x1b\[0m$'
         ])
     else:
         self.generic_tst(alignak_logger.info, 'Some log-message', [1, 1], [
             r'^\[.+?\] INFO:\s+Some log-message$',
             r'^\[.+?\] INFO:\s+Some log-message$'
         ])
Пример #11
0
 def test_basic_logging_log(self):
     sys.stdout = StringIO()
     self._collector = Collector()
     sh = StreamHandler(sys.stdout)
     sh.setFormatter(DEFAULT_FORMATTER)
     alignak_logger.handlers = []
     alignak_logger.addHandler(sh)
     alignak_logger.load_obj(self._collector)
     alignak_logger.log_set = True
     logfile = NamedTemporaryFile("w", delete=False)
     logfile.close()
     self.logfile_name = logfile.name
     alignak_logger.register_local_log(logfile.name, purge_buffer=False)
     alignak_logger.setLevel(DEBUG)
     self.generic_tst(lambda x: naglog_result('info', x), 'Some log-message',
                      [1, 1, 1], ['', r'^\[\d+\] Some log-message$', r'^\[\d+\] Some log-message$'])
Пример #12
0
    def main(self):
        """Main receiver function
        Init daemon and loop forever

        :return: None
        """
        try:
            self.load_config_file()

            # Setting log level
            logger.setLevel(self.log_level)
            # Force the debug level if the daemon is said to start with such level
            if self.debug:
                logger.setLevel('DEBUG')

            # Look if we are enabled or not. If ok, start the daemon mode
            self.look_for_early_exit()

            for line in self.get_header():
                logger.info(line)

            logger.info("[Receiver] Using working directory: %s", os.path.abspath(self.workdir))

            self.do_daemon_init_and_start()

            self.load_modules_manager()

            #  We wait for initial conf
            self.wait_for_initial_conf()
            if not self.new_conf:
                return

            self.setup_new_conf()
            self.modules_manager.set_modules(self.modules)
            self.do_load_modules()
            # and start external modules too
            self.modules_manager.start_external_instances()

            # Do the modules part, we have our modules in self.modules
            # REF: doc/receiver-modules.png (1)

            # Now the main loop
            self.do_mainloop()

        except Exception, exp:
            self.print_unrecoverable(traceback.format_exc())
            raise
Пример #13
0
    def main(self):
        """Main receiver function
        Init daemon and loop forever

        :return: None
        """
        try:
            self.load_config_file()

            # Setting log level
            logger.setLevel(self.log_level)
            # Force the debug level if the daemon is said to start with such level
            if self.debug:
                logger.setLevel('DEBUG')

            # Look if we are enabled or not. If ok, start the daemon mode
            self.look_for_early_exit()

            for line in self.get_header():
                logger.info(line)

            logger.info("[Receiver] Using working directory: %s",
                        os.path.abspath(self.workdir))

            self.do_daemon_init_and_start()

            self.load_modules_manager()

            #  We wait for initial conf
            self.wait_for_initial_conf()
            if not self.new_conf:
                return

            self.setup_new_conf()
            self.do_load_modules(self.modules)
            # and start external modules too
            self.modules_manager.start_external_instances()

            # Do the modules part, we have our modules in self.modules
            # REF: doc/receiver-modules.png (1)

            # Now the main loop
            self.do_mainloop()

        except Exception, exp:
            self.print_unrecoverable(traceback.format_exc())
            raise
Пример #14
0
 def test_basic_logging_log(self):
     sys.stdout = StringIO()
     self._collector = Collector()
     sh = StreamHandler(sys.stdout)
     sh.setFormatter(DEFAULT_FORMATTER)
     alignak_logger.handlers = []
     alignak_logger.addHandler(sh)
     alignak_logger.load_obj(self._collector)
     alignak_logger.log_set = True
     logfile = NamedTemporaryFile("w", delete=False)
     logfile.close()
     self.logfile_name = logfile.name
     alignak_logger.register_local_log(logfile.name, purge_buffer=False)
     alignak_logger.setLevel(DEBUG)
     self.generic_tst(
         lambda x: naglog_result('info', x), 'Some log-message', [1, 1, 1],
         ['', r'^\[\d+\] Some log-message$', r'^\[\d+\] Some log-message$'])
Пример #15
0
    def set_log_level(self, loglevel):
        """Set the current log level in [NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL, UNKNOWN]

        :param loglevel: a value in one of the above
        :type loglevel: str
        :return: None
        """
        return logger.setLevel(loglevel)
Пример #16
0
    def set_log_level(self, loglevel):
        """Set the current log level in [NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL, UNKNOWN]

        :param loglevel: a value in one of the above
        :type loglevel: str
        :return: None
        """
        return logger.setLevel(loglevel)
Пример #17
0
from alignak_tst_utils import safe_print

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

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


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

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

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

# We overwrite the functions time() and sleep()
# This way we can modify sleep() so that it immediately returns although
# for a following time() it looks like thee was actually a delay.
# This massively speeds up the tests.
class TimeHacker(object):

    def __init__(self):
        self.my_offset = 0
        self.my_starttime = time.time()
        self.my_oldtime = time.time
        self.original_time_time = time.time
        self.original_time_sleep = time.sleep
Пример #18
0
from alignak.daemons.arbiterdaemon import Arbiter
from alignak.daemons.receiverdaemon import Receiver
from logging import ERROR

from alignak_tst_utils import safe_print

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


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

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

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

# We overwrite the functions time() and sleep()
# This way we can modify sleep() so that it immediately returns although
# for a following time() it looks like thee was actually a delay.
# This massively speeds up the tests.
class TimeHacker(object):

    def __init__(self):
        self.my_offset = 0
        self.my_starttime = time.time()
        self.my_oldtime = time.time
        self.original_time_time = time.time
        self.original_time_sleep = time.sleep