コード例 #1
0
    def compute(self,
                computation_options: BIAggregationComputationOptions,
                use_assumed=False) -> Optional[NodeResultBundle]:
        bundled_results = [
            bundle for bundle in [
                node.compute(computation_options, use_assumed)
                for node in self.nodes
            ] if bundle is not None
        ]
        if not bundled_results:
            return None
        actual_result = self._process_node_compute_result(
            [x.actual_result for x in bundled_results], computation_options)

        if not use_assumed:
            return NodeResultBundle(actual_result, None, bundled_results, self)

        assumed_result_items = []
        for bundle in bundled_results:
            assumed_result_items.append(
                bundle.assumed_result if bundle.
                assumed_result is not None else bundle.actual_result)
        assumed_result = self._process_node_compute_result(
            assumed_result_items, computation_options)
        return NodeResultBundle(actual_result, assumed_result, bundled_results,
                                self)
コード例 #2
0
ファイル: bi_trees.py プロジェクト: troelsarvin/checkmk
    def compute(
        self,
        computation_options: BIAggregationComputationOptions,
        bi_status_fetcher: ABCBIStatusFetcher,
        use_assumed=False,
    ) -> Optional[NodeResultBundle]:
        entity = self._get_entity(bi_status_fetcher)
        if not entity or entity.state is None or entity.hard_state is None:
            # Note: An entity state of None may be generated by the availability
            #       There might be service information, but no host information available
            #       A state of None will be treated as "missing"
            return None

        # Downtime
        downtime_state = 0
        if entity.scheduled_downtime_depth != 0:
            downtime_state = 1 if computation_options.escalate_downtimes_as_warn else 2

        # State
        if entity.has_been_checked:
            state = entity.hard_state if computation_options.use_hard_states else entity.state
            # Since we need an equalized state mapping, map host state DOWN to CRIT
            if self.service_description is None:
                state = self._map_hoststate_to_bistate(state)
        else:
            state = BIStates.PENDING

        # Assumed
        assumed_result = None
        if use_assumed:
            assumed_state = bi_status_fetcher.assumed_states.get(
                (self.site_id, self.host_name, self.service_description))
            if assumed_state is not None:
                assumed_result = NodeComputeResult(
                    int(assumed_state),
                    downtime_state,
                    bool(entity.acknowledged),
                    _("Assumed to be %s") %
                    self._get_state_name(assumed_state),
                    entity.in_service_period,
                    {},
                    {},
                )

        return NodeResultBundle(
            NodeComputeResult(
                state,
                downtime_state,
                bool(entity.acknowledged),
                entity.plugin_output,
                bool(entity.in_service_period),
                {},
                {},
            ),
            assumed_result,
            [],
            self,
        )
コード例 #3
0
    def compute(self,
                computation_options: BIAggregationComputationOptions,
                use_assumed=False) -> Optional[NodeResultBundle]:
        entity = self._get_entity()
        if not entity or entity.state is None or entity.hard_state is None:
            # Note: An entity state of None may be generated by the availability
            #       There might be service information, but not host information available
            #       A state of None will be treated as "missing"
            return None

        # Downtime
        downtime_state = 0
        if entity.scheduled_downtime_depth != 0:
            downtime_state = 1 if computation_options.escalate_downtimes_as_warn else 2

        # State
        state = entity.hard_state if computation_options.use_hard_states else entity.state

        # Assumed
        assumed_result = None
        if use_assumed:
            assumed_state = bi_status_fetcher.assumed_states.get(
                (self.site_id, self.host_name, self.service_description))
            if assumed_state is not None:
                assumed_result = NodeComputeResult(
                    int(assumed_state), downtime_state,
                    bool(entity.acknowledged),
                    _("Assumed to be %s" %
                      self._get_state_name(assumed_state)),
                    entity.in_service_period, {})

        return NodeResultBundle(
            NodeComputeResult(
                state,
                downtime_state,
                bool(entity.acknowledged),
                entity.plugin_output,
                bool(entity.in_service_period),
                {},
            ), assumed_result, [], self)