Exemplo n.º 1
0
    def execute(self):
        local_connection = LocalConnection()
        row = local_connection.query_row(
            "GET status\nColumns: helper_usage_generic average_latency_generic\n"
        )

        helper_usage_perc = 100 * row[0]
        check_latency_generic = row[1]

        usage_warn, usage_crit = 85, 95
        if helper_usage_perc >= usage_crit:
            cls = ACResultCRIT
        elif helper_usage_perc >= usage_warn:
            cls = ACResultWARN
        else:
            cls = ACResultOK
        yield cls(
            _("The current check helper usage is %.2f%%") % helper_usage_perc)

        if check_latency_generic > 1:
            cls = ACResultCRIT
        else:
            cls = ACResultOK
        yield cls(
            _("The active check services have an average check latency of %.3fs."
              ) % (check_latency_generic))
Exemplo n.º 2
0
    def execute(self):
        local_connection = LocalConnection()
        site_status = local_connection.query_row(
            "GET status\n"
            "Columns: livestatus_usage livestatus_threads livestatus_active_connections livestatus_overflows_rate"
        )

        usage, threads, active_connections, overflows_rate = site_status

        # Microcore has an averaged usage pre-calculated. The Nagios core does not have this column.
        # Calculate a non averaged usage instead
        if usage is None:
            usage = float(active_connections) / float(threads)

        usage_perc = 100 * usage

        usage_warn, usage_crit = 80, 95
        if usage_perc >= usage_crit:
            cls = ACResultCRIT
        elif usage_perc >= usage_warn:
            cls = ACResultWARN
        else:
            cls = ACResultOK

        yield cls(_("The current livestatus usage is %.2f%%") % usage_perc)
        yield cls(
            _("%d of %d connections used") % (active_connections, threads))

        # Only available with Microcore
        if overflows_rate is not None:
            yield cls(
                _("You have a connection overflow rate of %.2f/s") %
                overflows_rate)
Exemplo n.º 3
0
    def execute(self):
        local_connection = LocalConnection()
        row = local_connection.query_row(
            "GET status\nColumns: helper_usage_cmk average_latency_cmk\n")

        helper_usage_perc = 100 * row[0]
        check_latecy_cmk = row[1]

        usage_warn, usage_crit = 85, 95
        if helper_usage_perc >= usage_crit:
            cls = ACResultCRIT
        elif helper_usage_perc >= usage_warn:
            cls = ACResultWARN
        else:
            cls = ACResultOK

        yield cls(
            _("The current Check_MK helper usage is %.2f%%. The Check_MK services have an "
              "average check latency of %.3fs.") %
            (helper_usage_perc, check_latecy_cmk))

        # Only report this as warning in case the user increased the default helper configuration
        default_values = watolib.ABCConfigDomain.get_all_default_globals()
        if self._get_effective_global_setting(
                "cmc_cmk_helpers"
        ) > default_values["cmc_cmk_helpers"] and helper_usage_perc < 50:
            yield ACResultWARN(
                _("The helper usage is below 50%, you may decrease the number of "
                  "Check_MK helpers to reduce the memory consumption."))
Exemplo n.º 4
0
 def _uses_microcore(self):
     # type: () -> bool
     """Whether or not the local site is using the CMC"""
     local_connection = LocalConnection()
     version = local_connection.query_value(
         "GET status\nColumns: program_version\n", deflt="")
     return version.startswith("Check_MK")
Exemplo n.º 5
0
    def execute(self) -> Iterator[ACResult]:
        local_connection = LocalConnection()
        row = local_connection.query_row(
            "GET status\nColumns: helper_usage_checker average_latency_fetcher\n"
        )

        checker_usage_perc = 100 * row[0]
        fetcher_latency = row[1]

        usage_warn, usage_crit = 85, 95
        if checker_usage_perc >= usage_crit:
            cls: Type[ACResult] = ACResultCRIT
        elif checker_usage_perc >= usage_warn:
            cls = ACResultWARN
        else:
            cls = ACResultOK

        yield cls(
            _("The current checker usage is %.2f%%,"
              " The checks have an average check latency of %.3fs.") %
            (checker_usage_perc, fetcher_latency))

        # Only report this as warning in case the user increased the default helper configuration
        default_values = watolib.ABCConfigDomain.get_all_default_globals()
        if self._get_effective_global_setting(
                "cmc_checker_helpers"
        ) > default_values["cmc_checker_helpers"] and checker_usage_perc < 50:
            yield ACResultWARN(
                _("The checker usage is below 50%, you may decrease the number of "
                  "checkers to reduce the memory consumption."))
Exemplo n.º 6
0
def query_hosts_infos() -> Sequence[HostInfo]:
    return [
        _create_host_info(row)  #
        for row in LocalConnection().query_table_assoc(
            "GET hosts\n"
            "Columns: name alias address custom_variables contacts contact_groups")
    ]
Exemplo n.º 7
0
    def execute(self) -> Iterator[ACResult]:
        local_connection = LocalConnection()
        row = local_connection.query_row(
            "GET status\nColumns: helper_usage_cmk average_latency_cmk\n")

        helper_usage_perc = 100 * row[0]
        check_latecy_cmk = row[1]

        usage_warn, usage_crit = 85, 95
        if helper_usage_perc >= usage_crit:
            cls: Type[ACResult] = ACResultCRIT
        elif helper_usage_perc >= usage_warn:
            cls = ACResultWARN
        else:
            cls = ACResultOK

        yield cls(
            _("The current Checkmk helper usage is %.2f%%. The Checkmk services have an "
              "average check latency of %.3fs.") %
            (helper_usage_perc, check_latecy_cmk))
Exemplo n.º 8
0
def query_contactgroups_members(group_names: Iterable[ContactgroupName]) -> set[UserId]:
    query = "GET contactgroups\nColumns: members"
    num_group_names = 0
    for group_name in group_names:
        query += f"\nFilter: name = {group_name}"
        num_group_names += 1
    query += f"\nOr: {num_group_names}"
    contact_lists: list[list[str]] = (
        LocalConnection().query_column(query) if num_group_names else []
    )
    return {UserId(contact) for contact_list in contact_lists for contact in contact_list}
Exemplo n.º 9
0
def query_status_enable_notifications() -> bool:
    return bool(LocalConnection().query_value("GET status\n"  #
                                              "Columns: enable_notifications"))
Exemplo n.º 10
0
def query_status_program_start() -> Timestamp:
    return LocalConnection().query_value("GET status\n"  #
                                         "Columns: program_start")
Exemplo n.º 11
0
def query_hosts_scheduled_downtime_depth(host_name: HostName) -> int:
    return LocalConnection().query_value("GET hosts\n"
                                         "Columns: scheduled_downtime_depth\n"
                                         f"Filter: host_name = {host_name}")
Exemplo n.º 12
0
def query_timeperiods_in() -> Mapping[TimeperiodName, bool]:
    return {
        name: bool(in_)  #
        for name, in_ in LocalConnection().query("GET timeperiods\n"  #
                                                 "Columns: name in")
    }
Exemplo n.º 13
0
 def _get_config_timestamp(self) -> Timestamp:
     return LocalConnection().query_value("GET status\n"  #
                                          "Columns: program_start")
Exemplo n.º 14
0
 def _get_host_configs(self) -> List[HostInfo]:
     return LocalConnection().query_table_assoc(
         "GET hosts\n"
         "Columns: name alias address custom_variables contacts contact_groups"
     )