Exemple #1
0
    def run(self):
        while not self.stop_event.is_set():
            try:
                if self.initializer_module.is_registered:
                    report = self.get_report()

                    if self.initializer_module.is_registered and not Utils.are_dicts_equal(
                            report,
                            self.last_report,
                            keys_to_skip=["agentTimeStampAtReporting"]):
                        self.initializer_module.connection.send(
                            message=report,
                            destination=Constants.HOST_STATUS_REPORTS_ENDPOINT)
                        self.last_report = report

                # don't use else to avoid race condition
                if not self.initializer_module.is_registered:
                    self.last_report = {}
            except ConnectionIsAlreadyClosed:  # server and agent disconnected during sending data. Not an issue
                pass
            except:
                logger.exception(
                    "Exception in HostStatusReporter. Re-running it")

            self.stop_event.wait(self.report_interval)

        logger.info("HostStatusReporter has successfully finished")
    def discard_stale_reports(self, cluster_reports):
        """
    Remove reports which are already stale (meaning other process has already updated status to something different)
    """
        with self.reports_to_discard_lock:
            # nothing to discard
            if not self.reports_to_discard:
                return cluster_reports

            reports_to_discard = self.reports_to_discard[:]

        new_cluster_reports = defaultdict(lambda: [])
        for cluster_id, cluster_reports in cluster_reports.iteritems():
            for cluster_report in cluster_reports:
                for discarded_report in reports_to_discard:
                    if Utils.are_dicts_equal(cluster_report,
                                             discarded_report,
                                             keys_to_skip=['status']):
                        self.logger.info(
                            "Discarding outdated status {0} before sending".
                            format(cluster_report))
                        break
                else:
                    new_cluster_reports[cluster_id].append(cluster_report)

        return new_cluster_reports
Exemple #3
0
    def run(self):
        while not self.stop_event.is_set():
            try:
                if self.initializer_module.is_registered:
                    report = self.get_report()

                    if self.initializer_module.is_registered and not Utils.are_dicts_equal(
                            report,
                            self.last_report,
                            keys_to_skip=["agentTimeStampAtReporting"]):
                        correlation_id = self.initializer_module.connection.send(
                            message=report,
                            destination=Constants.HOST_STATUS_REPORTS_ENDPOINT)
                        self.server_responses_listener.listener_functions_on_success[
                            correlation_id] = lambda headers, message: self.save_last_report(
                                report)

            except ConnectionIsAlreadyClosed:  # server and agent disconnected during sending data. Not an issue
                pass
            except:
                logger.exception(
                    "Exception in HostStatusReporter. Re-running it")

            self.stop_event.wait(self.report_interval)

        logger.info("HostStatusReporter has successfully finished")