예제 #1
0
    def write_config_file(self):
        """
            Writes the actual configuration into the config file.
        """

        log.log_info('Writing the config file...')

        # Generating uuid if empty
        if '' == Config.get_config_value('General', 'uuid'):
            Config.set_config_value('General', 'uuid', str(uuid.uuid1()))

        # Writing conf file. Reading all sections defined in the config...
        for config_section in Config._CR_CONFIG_VALUES:
            try:
                Config.config.add_section(config_section)
            except ConfigParser.DuplicateSectionError:
                log.log_debug('Section already exist: %s' % config_section)
            except:
                log.log_error('Error creating new section: %s:%s' % (config_section, Exception.message))

            # Reading all values in this section
            config_section_vars = Config._CR_CONFIG_VALUES[config_section]

            for config_value in config_section_vars:
                try:
                    Config.config.set(config_section, config_value,
                                      Config._CR_CONFIG_VALUES[config_section][config_value])
                except:
                    log.log_error('Error writing config value: %s/%s' % (config_section, config_value))

        try:
            Config.config.write(open(Config.CR_CONFIG_FULL_PATH, 'w'))  # Writing the config file on filesystem...

        except IOError:
            log.log_error('/!\ Error writing config file. Using the default config')
예제 #2
0
 def __init__(self):
     """
         Constructor
     """
     # Managing config file
     if os.path.isfile(Config.CR_CONFIG_FULL_PATH):
         log.log_debug('Configuration file: Found. Reading it.')
         self.read_config_file()
     else:
         log.log_info('Configuration file: Not found. Creating it.')
         self.write_config_file()
예제 #3
0
    def signal_handler(self, signum, frame):
        """
            Receives signals from the OS.
        """

        if signum == signal.SIGTERM:
            # In this case, we must stop CentralReport immediatly!
            if not self.SIGTERM_SENT:
                self.SIGTERM_SENT = True  # Prevents if SIGTERM is received twice.

                log.log_info('SIGTERM signal received (%s). Shutting Down...' %
                             signum)
                log.log_info('Shutting down sub-processes...')
                os.killpg(0, signal.SIGTERM)

                self.stop()

        elif signum == signal.SIGINT:
            # Keyboard interruption (CTRL + C)
            log.log_info(
                'SIGINT signal received (%s). Stopping CentralReport...' %
                signum)
            self.stop()

        else:
            log.log_debug('Unknown signal number: %s' % signum)
예제 #4
0
    def stop(self):
        """
            Stops all threads, Daemon and kill CentralReport instance.
        """

        log.log_info("Stopping CentralReport...")
        self.is_running = False

        if CentralReport.checks_thread is not None:
            log.log_info("Stopping checks thread...")
            threads.Checks.performChecks = False

        log.log_info("A last word from the daemon: Bye!")

        # Killing the current processus...
        # (This command send the "SIGKILL" signal)
        os.system("kill -9 %d" % os.getpid())
예제 #5
0
    def stop(self):
        """
            Stops all threads, Daemon and kill CentralReport instance.
        """

        log.log_info('Stopping CentralReport...')
        self.is_running = False

        if CentralReport.checks_thread is not None:
            log.log_info('Stopping checks thread...')
            threads.Checks.performChecks = False

        log.log_info('A last word from the daemon: Bye!')

        # Killing the current processus...
        # (This command send the "SIGKILL" signal)
        os.system('kill -9 %d' % os.getpid())
예제 #6
0
    def signal_handler(self, signum, frame):
        """
            Receives signals from the OS.
        """

        if signum == signal.SIGTERM:
            # In this case, we must stop CentralReport immediatly!
            if not self.SIGTERM_SENT:
                self.SIGTERM_SENT = True  # Prevents if SIGTERM is received twice.

                log.log_info("SIGTERM signal received (%s). Shutting Down..." % signum)
                log.log_info("Shutting down sub-processes...")
                os.killpg(0, signal.SIGTERM)

                self.stop()

        elif signum == signal.SIGINT:
            # Keyboard interruption (CTRL + C)
            log.log_info("SIGINT signal received (%s). Stopping CentralReport..." % signum)
            self.stop()

        else:
            log.log_debug("Unknown signal number: %s" % signum)
예제 #7
0
    def run(self):
        """
            Constructor.
        """

        is_error = False  # If True, there are one or more errors when CentralReport is trying to start

        log.log_info("------------------------------------------------")
        log.log_info("CentralReport is starting...")
        log.log_info("Current user: "******"Debug", "log_level")
            except:
                log_level = "INFO"

            log.change_log_level(log_level)

        # Starting the check thread...
        if host.get_current_host().os != host.OS_UNKNOWN:
            log.log_info("%s detected. Starting ThreadChecks..." % host.get_current_host().os)
            CentralReport.checks_thread = threads.Checks()  # Launching checks thread
        else:
            is_error = True
            log.log_critical("Sorry, but your OS is not supported yet...")

        # Starting the internal webserver...
        if not is_error and text.convert_text_to_bool(Config.get_config_value("Webserver", "enable")):
            local_web_port = int(Config.get_config_value("Webserver", "port"))

            if not utils_web.check_port("127.0.0.1", local_web_port):
                log.log_info("Starting the webserver...")

                # Importing the module here improve the memory usage
                import cr.web

                CentralReport.webserver_thread = cr.web.server.WebServer()
            else:
                log.log_error("Error launching the webserver: port %s is already in use on this host!" % local_web_port)
        else:
            log.log_info("Webserver is disabled by configuration file!")

        if not is_error:
            log.log_info("CentralReport started!")

            while CentralReport.is_running:
                if not Config.CR_CONFIG_ENABLE_DEBUG_MODE:
                    # If .pid file is not found, we must stop CR (only in production environment)
                    try:
                        pf = file(self.pidfile, "r")
                        pf.close()
                    except IOError:
                        log.log_error("Pid file is not found. CentralReport must stop itself.")
                        CentralReport.is_running = False
                        self.stop()
                time.sleep(1)

        else:
            log.log_error("Error launching CentralReport!")
예제 #8
0
        """
        standalone = StandaloneCli()
        standalone.display()

        cr.cli.quit()


if __name__ == '__main__':
    if os.path.isfile('/usr/local/bin/centralreport') is False:
        print 'CentralReport must be installed on this host to run the CLI Manager!'
        exit(2)
    elif getpass.getuser() != 'root':
        print 'You must execute this manager as root to perform administrative operations!'
        exit(3)

    log.log_info('CLI Manager is starting...')

    cr_config = Config()
    cr_config.read_config_file()

    if len(sys.argv) == 1:
        cr.cli.init_screen()
        main_screen = MainCli()
        main_screen.display()
    else:
        if sys.argv[1] == 'wizard':
            cr.cli.init_screen()
            wizard_screen = WizardCli()
            wizard_screen.display()
        else:
            print 'CentralReport CLI Manager - Usage: \n' \
예제 #9
0
    def run(self):
        """
            Constructor.
        """

        is_error = False  # If True, there are one or more errors when CentralReport is trying to start

        log.log_info('------------------------------------------------')
        log.log_info('CentralReport is starting...')
        log.log_info('Current user: '******'Debug', 'log_level')
            except:
                log_level = 'INFO'

            log.change_log_level(log_level)

        # Starting the check thread...
        if host.get_current_host().os != host.OS_UNKNOWN:
            log.log_info('%s detected. Starting ThreadChecks...' %
                         host.get_current_host().os)
            CentralReport.checks_thread = threads.Checks(
            )  # Launching checks thread
        else:
            is_error = True
            log.log_critical('Sorry, but your OS is not supported yet...')

        # Starting the internal webserver...
        if not is_error and text.convert_text_to_bool(
                Config.get_config_value('Webserver', 'enable')):
            local_web_port = int(Config.get_config_value('Webserver', 'port'))

            if not utils_web.check_port('127.0.0.1', local_web_port):
                log.log_info('Starting the webserver...')

                # Importing the module here improve the memory usage
                import cr.web

                CentralReport.webserver_thread = cr.web.server.WebServer()
            else:
                log.log_error(
                    'Error launching the webserver: port %s is already in use on this host!'
                    % local_web_port)
        else:
            log.log_info('Webserver is disabled by configuration file!')

        if not is_error:
            log.log_info('CentralReport started!')

            while CentralReport.is_running:
                if not Config.CR_CONFIG_ENABLE_DEBUG_MODE:
                    # If .pid file is not found, we must stop CR (only in production environment)
                    try:
                        pf = file(self.pidfile, 'r')
                        pf.close()
                    except IOError:
                        log.log_error(
                            'Pid file is not found. CentralReport must stop itself.'
                        )
                        CentralReport.is_running = False
                        self.stop()
                time.sleep(1)

        else:
            log.log_error('Error launching CentralReport!')
예제 #10
0
        """
        standalone = StandaloneCli()
        standalone.display()

        cr.cli.quit()


if __name__ == '__main__':
    if os.path.isfile('/usr/local/bin/centralreport') is False:
        print 'CentralReport must be installed on this host to run the CLI Manager!'
        exit(2)
    elif getpass.getuser() != 'root':
        print 'You must execute this manager as root to perform administrative operations!'
        exit(3)

    log.log_info('CLI Manager is starting...')

    cr_config = Config()
    cr_config.read_config_file()

    if len(sys.argv) == 1:
        cr.cli.init_screen()
        main_screen = MainCli()
        main_screen.display()
    else:
        if sys.argv[1] == 'wizard':
            cr.cli.init_screen()
            wizard_screen = WizardCli()
            wizard_screen.display()
        else:
            print 'CentralReport CLI Manager - Usage: \n' \