# Path: app/lib/livestatusconnection.py

# 
# Path: app/lib/datasources.py



from app.lib.livestatusconnection import live
from app.lib.datasources import multisite_datasources as datasources
# prepare row-function needed for painters
# datasource: the datasource key value as defined in plugins/views/datasources.py
# columns: the list of livestatus columns to query
# add_columns: list of columns the datasource is known to add itself
#  (couldn't we get rid of this parameter by looking that up ourselves?)
# add_headers: additional livestatus headers to add
# only_sites: list of sites the query is limited to
# limit: maximum number of data rows to query
def query_data(datasource, columns, add_headers, filters_string, only_sites = [], limit = None):
    if "add_columns" in datasource.keys():
        add_columns = datasource["add_columns"]
    else:
        add_columns = ['']

    tablename = datasource["table"]
    add_headers += datasource.get("add_headers", "")
    merge_column = datasource.get("merge_by")
    if merge_column:
        columns = [merge_column] + columns

    # Most layouts need current state of object in order to
    # choose background color - even if no painter for state
    # is selected. Make sure those columns are fetched. This
    # must not be done for the table 'log' as it cannot correctly
    # distinguish between service_state and host_state
    if "log" not in datasource["infos"]:
        state_columns = []
        if "service" in datasource["infos"]:
            state_columns += [ "service_has_been_checked", "service_state" ]
        if "host" in datasource["infos"]:

# Path: app/lib/livestatusconnection.py

# 
# Path: app/lib/datasources.py



# Path: app/lib/livestatus_query.py
from app.lib.livestatusconnection import live
from app.lib.datasources import multisite_datasources as datasources

# prepare row-function needed for painters
# datasource: the datasource key value as defined in plugins/views/datasources.py
# columns: the list of livestatus columns to query
# add_columns: list of columns the datasource is known to add itself
#  (couldn't we get rid of this parameter by looking that up ourselves?)
# add_headers: additional livestatus headers to add
# only_sites: list of sites the query is limited to
# limit: maximum number of data rows to query
def query_data(datasource, columns, add_headers, filters_string, only_sites = [], limit = None):
    if "add_columns" in datasource.keys():
        add_columns = datasource["add_columns"]
    else:
        add_columns = ['']

    tablename = datasource["table"]
    add_headers += datasource.get("add_headers", "")
    merge_column = datasource.get("merge_by")
    if merge_column:
        columns = [merge_column] + columns

    # Most layouts need current state of object in order to
    # choose background color - even if no painter for state
    # is selected. Make sure those columns are fetched. This
    # must not be done for the table 'log' as it cannot correctly
    # distinguish between service_state and host_state
    if "log" not in datasource["infos"]:
        state_columns = []
        if "service" in datasource["infos"]:
            state_columns += [ "service_has_been_checked", "service_state" ]
        if "host" in datasource["infos"]:

            state_columns += [ "host_has_been_checked", "host_state" ]