Ejemplo n.º 1
0
    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,
        )
Ejemplo n.º 2
0
    def _process_node_compute_result(
        self, results: List[NodeComputeResult],
        computation_options: BIAggregationComputationOptions
    ) -> NodeComputeResult:
        # TODO: resolve int casting, bypasses float/int type conflict
        state = int(
            self.aggregation_function.aggregate(
                [result.state for result in results]))

        downtime_state = int(
            self.aggregation_function.aggregate(
                [result.downtime_state for result in results]))
        if downtime_state > 0:
            downtime_state = 2 if computation_options.escalate_downtimes_as_warn else 1

        is_acknowledged = False
        if state != 0:
            is_acknowledged = self.aggregation_function.aggregate([
                0 if result.acknowledged else result.state
                for result in results
            ]) == 0

        in_service_period = self.aggregation_function.aggregate(
            [0 if result.in_service_period else 2 for result in results]) == 0

        return NodeComputeResult(
            state,
            downtime_state,
            is_acknowledged,
            self.properties.state_messages.get(state, ""),
            in_service_period,
            self.properties.state_messages,
        )
Ejemplo n.º 3
0
    def _process_node_compute_result(
        self, results: List[NodeComputeResult],
        computation_options: BIAggregationComputationOptions
    ) -> NodeComputeResult:
        state = self.aggregation_function.aggregate(
            [result.state for result in results])

        downtime_state = self.aggregation_function.aggregate(
            [result.downtime_state for result in results])
        if downtime_state > 0:
            downtime_state = 2 if computation_options.escalate_downtimes_as_warn else 1

        is_acknowledged = False
        if state != 0:
            is_acknowledged = (self.aggregation_function.aggregate([
                0 if result.acknowledged else result.state
                for result in results
            ]) == 0)

        in_service_period = (self.aggregation_function.aggregate(
            [0 if result.in_service_period else 2 for result in results]) == 0)

        return NodeComputeResult(
            state,
            downtime_state,
            is_acknowledged,
            # TODO: fix str casting in later commit
            self.properties.state_messages.get(str(state), ""),
            in_service_period,
            self.properties.state_messages,
            {},
        )
Ejemplo n.º 4
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)