def all_services():
    """
    This of every single service that we know about, this is very slow if 
    no filter is in play.
    """
    extra_filters = gather_filters(request)
    service_list = query.get_all_services(
    columns='host_name description state last_check last_state_change plugin_output acknowledged host_acknowledged max_check_attempts current_attempt',
    extra_filter=extra_filters)
    try:
        service_stats = query.service_stats(extra_filter=extra_filters)
    except Exception, e:
        return redirect( url_for('tac'))
def show_services(service_name):
    """ list of services that match a service name, this will show the same
    service across a number of servers. """
    extra_filters = gather_filters(request)

    service_list = query.get_services(service_name, 
    columns='host_name description state last_check last_state_change plugin_output acknowledged host_acknowledged current_attempt max_check_attempts',
    extra_filter=extra_filters)

    service_stats = query.service_stats(
    extra_filter="description = %(service_name)s" % locals())
    return render_template('service_list.template', service_list=service_list,
    service_stats=service_stats, settings=settings )
def host_services(host_name):
    """ Given a host_name display all of its services. """
    extra_filters = gather_filters(request)
    service_list = query.get_host_services(host_name, 
    columns='host_name description state last_check last_state_change plugin_output acknowledged host_acknowledged max_check_attempts current_attempt',
    extra_filter=extra_filters)

    try:
        service_stats = query.service_stats(
        extra_filter="host_name = %(host_name)s" % locals())
    except Exception as error:
        return redirect("/tac")

    return render_template('service_list.template', service_list=service_list,
    service_stats=service_stats,settings=settings )
def tac():
    """ The 'Tactical Monitoring Overview', this will show an overview of all 
    the services: up, down, warning, error, etc.
    """
    extra_filters = gather_filters(request)
    try:
        service_stats = query.service_stats(extra_filter=extra_filters)
        host_stats = query.hosts_stats(extra_filter=extra_filters)
    except query.livestatus.MKLivestatusSocketError as error:
        error_message = """
        SimpleNagios received an error trying to connect to the nagios broker.
        <Br />
        You might want to check you'r settings.py file and make sure that nagios
        is currently running as expected.
        <Br />
        The error message was:
        <Br />
        %(error)s""" % locals()
        return render_template('error.template', error_message=error_message,
            error_tepe="connection error")

    return render_template('tac.template', service_stats=service_stats, 
    host_stats=host_stats )