Exemplo n.º 1
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)
Exemplo n.º 2
0
    def run(self):
        """
            Constructor.
        """

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

        # Preparing Logs
        crLog.configLog(Config.CR_CONFIG_ENABLE_DEBUG_MODE)

        crLog.writeInfo('CentralReport is starting...')

        CentralReport.startingDate = datetime.datetime.now()  # Starting date
        CentralReport.configuration = Config()  # Getting config object

        # Getting current OS...
        if (Config.HOST_CURRENT == Config.HOST_MAC) | (Config.HOST_CURRENT == Config.HOST_DEBIAN) | (
        Config.HOST_CURRENT == Config.HOST_UBUNTU):
            crLog.writeInfo(Config.HOST_CURRENT + ' detected. Starting ThreadChecks...')
            CentralReport.checks_thread = crThreads.Checks()  # Launching checks thread
        else:
            isError = True
            crLog.writeCritical('Sorry, but your OS is not supported yet...')

        # Is webserver enabled?
        if not isError & crUtilsText.textToBool(Config.getConfigValue('Webserver', 'enable')):
            crLog.writeInfo('Enabling the webserver')
            CentralReport.webserver_thread = WebServer()
        else:
            crLog.writeInfo('Webserver is disabled by configuration file')

        if not isError:
            crLog.writeInfo('CentralReport started!')

            while CentralReport.isRunning:
                try:

                    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:
                            crLog.writeError('Pid file is not found. CentralReport must stop itself.')
                            CentralReport.isRunning = False
                            self.stop()
                    time.sleep(1)

                except KeyboardInterrupt:
                    # Stopping CR
                    crLog.writeFatal('KeyboardInterrupt exception. Stopping CentralReport...')
                    CentralReport.isRunning = False
                    self.stop()
        else:
            crLog.writeError('Error launching CentralReport!')