Ejemplo n.º 1
0
def service_detail(request, host_name, service_description):
    """ Displays status details for one host or service """
    c = {}
    c['messages'] = []
    c['errors'] = []

    livestatus = utils.livestatus(request)
    backend = request.GET.get('backend')
    c['pnp_url'] = adagios.settings.pnp_url
    c['nagios_url'] = adagios.settings.nagios_url
    c['request'] = request
    now = time.time()
    seconds_in_a_day = 60 * 60 * 24
    seconds_passed_today = now % seconds_in_a_day
    today = now - seconds_passed_today  # midnight of today

    try:
        c['host'] = my_host = livestatus.get_host(host_name, backend)
        my_host['object_type'] = 'host'
        my_host['short_name'] = my_host['name']
    except IndexError:
        c['errors'].append(_("Could not find any host named '%s'") % host_name)
        return error_page(request, c)

    if service_description is None:
        tmp = request.GET.get('service_description')
        if tmp is not None:
            return service_detail(request, host_name, service_description=tmp)
        primary_object = my_host
        c['service_description'] = '_HOST_'
    else:
        try:
            c['service'] = my_service = livestatus.get_service(
                host_name, service_description, backend=backend)
            my_service['object_type'] = 'service'
            c['service_description'] = service_description
            my_service['short_name'] = "%s/%s" % (my_service['host_name'],
                                                  my_service['description'])
            primary_object = my_service
        except IndexError:
            c['errors'].append(
                _("Could not find any service named '%s'") %
                service_description)
            return error_page(request, c)

    c['my_object'] = primary_object
    c['object_type'] = primary_object['object_type']

    # Friendly statusname (i.e. turn 2 into "critical")
    primary_object['status'] = state[primary_object['state']]

    # Plugin longoutput comes to us with special characters escaped. lets undo
    # that:
    primary_object['long_plugin_output'] = primary_object[
        'long_plugin_output'].replace('\\n', '\n')

    # Service list on the sidebar should be sorted
    my_host['services_with_info'] = sorted(
        my_host.get('services_with_info', []))
    c['host_name'] = host_name

    perfdata = primary_object['perf_data']
    perfdata = pynag.Utils.PerfData(perfdata)
    for i, datum in enumerate(perfdata.metrics):
        datum.i = i
        try:
            datum.status = state[datum.get_status()]
        except pynag.Utils.PynagError:
            datum.status = state[3]
    c['perfdata'] = perfdata.metrics

    # Get a complete list of network parents
    try:
        c['network_parents'] = reversed(
            _get_network_parents(request, host_name))
    except Exception as e:
        c['errors'].append(e)

    # Lets get some graphs
    if adagios.settings.enable_pnp4nagios:
        try:
            tmp = run_pnp("json", host=host_name)
            tmp = json.loads(tmp)
        except Exception as e:
            tmp = []
            c['pnp4nagios_error'] = e
        c['graph_urls'] = tmp

    if adagios.settings.enable_graphite:
        metrics = [x.label for x in perfdata.metrics]
        service = c['service_description'].replace(' ', '_')
        c['graphite'] = graphite.get(
            adagios.settings.graphite_url,
            c['host_name'],
            service,
            metrics,
            adagios.settings.GRAPHITE_PERIODS,
        )
        # used in the General tab - preview
        for graph in c['graphite']:
            if graph['css_id'] == adagios.settings.GRAPHITE_DEFAULT_TAB:
                default = {}
                for k, v in list(graph['metrics'].items()):
                    default[k] = v
                c['graphite_default'] = default

    return render_to_response('status_detail.html',
                              c,
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
    # Lets get some graphs
    if adagios.settings.enable_pnp4nagios:
        try:
            tmp = run_pnp("json", host=host_name)
            tmp = json.loads(tmp)
        except Exception, e:
            tmp = []
            c['pnp4nagios_error'] = e
        c['graph_urls'] = tmp
    
    if adagios.settings.enable_graphite:
        metrics = [x.label for x in perfdata.metrics]
        service = c['service_description'].replace(' ', '_')
        c['graphite'] = graphite.get(adagios.settings.graphite_url,
                                     c['host_name'],
                                     service,
                                     metrics,
                                     adagios.settings.GRAPHITE_PERIODS,
                                     )
        # used in the General tab - preview
        for graph in c['graphite']:
            if graph['css_id'] == adagios.settings.GRAPHITE_DEFAULT_TAB:
                default = {}
                for k,v in graph['metrics'].items():
                    default[k] = v
                c['graphite_default'] = default

    if adagios.settings.enable_rekishi:
        metrics = [x.label for x in perfdata.metrics]
        service = c['service_description'].replace(' ', '_')
        c['rekishi'] = rekishi.get(adagios.settings.rekishi_url,
                                   c['host_name'],
Ejemplo n.º 3
0
    if adagios.settings.enable_pnp4nagios:
        try:
            tmp = run_pnp("json", host=host_name)
            tmp = json.loads(tmp)
        except Exception, e:
            tmp = []
            c['pnp4nagios_error'] = e
        c['graph_urls'] = tmp

    if adagios.settings.enable_graphite:
        metrics = [x.label for x in perfdata.metrics]
        service = c['service_description'].replace(' ', '_')
        c['graphite'] = graphite.get(
            adagios.settings.graphite_url,
            c['host_name'],
            service,
            metrics,
            adagios.settings.GRAPHITE_PERIODS,
        )
        # used in the General tab - preview
        for graph in c['graphite']:
            if graph['css_id'] == adagios.settings.GRAPHITE_DEFAULT_TAB:
                default = {}
                for k, v in graph['metrics'].items():
                    default[k] = v
                c['graphite_default'] = default

    return render_to_response('status_detail.html',
                              c,
                              context_instance=RequestContext(request))