Example #1
0
    def writeConfigFile(self):
        """
            Writes the actual configuration into the config file.
        """

        crLog.writeInfo('Writing the config file...')

        # Generating uuid if empty
        if '' == Config.getConfigValue('General', 'uuid'):
            Config.setConfigValue('General', 'uuid', 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:
                crLog.writeDebug('Section already exist: ' + config_section)
            except:
                crLog.writeError('Error creating new section: ' + 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:
                    crLog.writeError('Error writing config value: ' + config_section + '/' + config_value)

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

        except IOError:
            crLog.writeError('/!\ Error writing config file. Using the default config')
Example #2
0
    def readConfigFile(self):
        """
            Reads the configuration file.
        """

        crLog.writeDebug('Reading the config file...')

        # Using Python ConfigParser module to read the file
        Config.config.read(Config.CR_CONFIG_FULL_PATH)

        # False = all sections and options are found.
        # True = config must be updated: some options or sections are mising (outdated config file?)
        config_must_be_updated = False

        # Getting all values...
        for config_section in Config._CR_CONFIG_VALUES:
            for config_value in Config._CR_CONFIG_VALUES[config_section]:
                try:
                    Config._CR_CONFIG_VALUES[config_section][config_value] = Config.config.get(config_section, config_value)

                except ConfigParser.NoSectionError:
                    config_must_be_updated = True
                    crLog.writeError('Config section does not exist in the file: ' + config_section)

                except ConfigParser.NoOptionError:
                    config_must_be_updated = True
                    crLog.writeError('Config value does not exist in the file: ' + config_value)

                except:
                    config_must_be_updated = True
                    crLog.writeError('Error getting a config value: ' + config_section + '/' + config_value)

        # In this case, config file have been written by a last version of CR. We must update it to include new sections or options.
        if config_must_be_updated:
            self.writeConfigFile()
Example #3
0
    def __init__(self):
        threading.Thread.__init__(self)
        crLog.writeDebug('ThreadChecks is starting...')  # Standard output

        # What is the current os?

        if Config.HOST_CURRENT == Config.HOST_MAC:
            self.MyCollector = crCollectors.MacCollector()
        elif (Config.HOST_CURRENT == Config.HOST_DEBIAN) \
            | (Config.HOST_CURRENT == Config.HOST_UBUNTU):
            self.MyCollector = crCollectors.DebianCollector()

        # Perform a check every xx ticks (1 tick = 1 second)

        try:
            self.tickPerformCheck = int(Config.getConfigValue('Checks', 'interval'))
        except:
            self.tickPerformCheck = 60

        crLog.writeDebug('Interval between two checks: ' + str(self.tickPerformCheck) + ' seconds')

        self.start()
Example #4
0
    def __init__(self):
        """
            Constructor
        """

        Config.determine_current_host()

        if Config.HOST_CURRENT == Config.HOST_MAC:
            crLog.writeDebug('Mac config')
        else:
            crLog.writeDebug('Linux config')

        # Managing config file
        if os.path.isfile(Config.CR_CONFIG_FULL_PATH):
            crLog.writeDebug('Configuration file: Found. Reading it.')
            self.readConfigFile()
        else:
            crLog.writeInfo('Configuration file: Not found. Creating it.')
            self.writeConfigFile()
Example #5
0
    def run(self):
        """
            Executes checks.
        """

        # Getting informations about the current host

        Checks.hostEntity = self.MyCollector.get_infos()

        while Checks.performChecks:
            if self.tickPerformCheck <= self.tickCount:
                crLog.writeDebug('---- New check -----')

                # Checking CPU
                if crUtilsText.textToBool(Config.getConfigValue('Checks', 'enable_cpu_check')):
                    crLog.writeDebug('Doing a CPU check...')
                    Checks.last_check_cpu = self.MyCollector.get_cpu()

                # Checking memory
                if crUtilsText.textToBool(Config.getConfigValue('Checks', 'enable_memory_check')):
                    crLog.writeDebug('Doing a memory check...')
                    Checks.last_check_memory = self.MyCollector.get_memory()

                # Checking Load Average
                if crUtilsText.textToBool(Config.getConfigValue('Checks', 'enable_load_check')):
                    crLog.writeDebug('Doing a load average check...')
                    Checks.last_check_loadAverage = self.MyCollector.get_loadaverage()

                # Checking disks informations
                if crUtilsText.textToBool(Config.getConfigValue('Checks', 'enable_disks_check')):
                    crLog.writeDebug('Doing a disk check....')
                    Checks.last_check_disk = self.MyCollector.get_disks()

                # Updating last check date...

                Checks.last_check_date = datetime.datetime.now()  # Update the last check date

                # Wait 60 seconds before next checks...

                crLog.writeDebug('All checks are done')
                crLog.writeDebug('Next checks in ' + str(self.tickPerformCheck) + ' seconds...')

                self.tickCount = 0

            # new tick

            self.tickCount += 1
            time.sleep(1)