コード例 #1
0
    def _get_event_stats_query(self, context_filters):
        # In case the user is not allowed to see unrelated events
        ec_filters = ""
        if not user.may("mkeventd.seeall") and not user.may("mkeventd.seeunrelated"):
            ec_filters = "Filter: event_contact_groups != \nFilter: host_name != \nOr: 2\n"

        event_query = (
            # "Events" column
            "GET eventconsoleevents\n"
            "Stats: event_phase = open\n"
            "Stats: event_phase = ack\n"
            "StatsOr: 2\n"
            # "Problems" column
            "Stats: event_phase = open\n"
            "Stats: event_phase = ack\n"
            "StatsOr: 2\n"
            "Stats: event_state != 0\n"
            "StatsAnd: 2\n"
            # "Unhandled" column
            "Stats: event_phase = open\n"
            "Stats: event_state != 0\n"
            "Stats: event_host_in_downtime != 1\n"
            "StatsAnd: 3\n" + ec_filters + context_filters
        )

        # Do not mark the site as dead in case the Event Console is not available.
        return livestatus.Query(
            event_query,
            suppress_exceptions=(
                livestatus.MKLivestatusTableNotFoundError,
                livestatus.MKLivestatusBadGatewayError,
            ),
        )
コード例 #2
0
ファイル: mkeventd.py プロジェクト: inettgmbh/checkmk
def get_stats_per_site(only_sites, stats_keys):
    try:
        sites.live().set_only_sites(only_sites)
        # Do not mark the site as dead in case the Event Console is not available.
        query = livestatus.Query(
            "GET eventconsolestatus\nColumns: %s" % " ".join(stats_keys),
            suppress_exceptions=(livestatus.MKLivestatusTableNotFoundError,
                                 livestatus.MKLivestatusBadGatewayError))
        for list_row in sites.live().query(query):
            yield dict(zip(stats_keys, list_row))
    finally:
        sites.live().set_only_sites(None)