Exemple #1
0
def bi_graphs_to_json(process_name, process_type='businessprocess'):
    c = {}
    c['messages'] = []
    c['errors'] = []
    bp = adagios.bi.get_business_process(process_name=process_name,
                                         process_type=process_type)

    graphs = []
    if not bp.graphs:
        return []
    for graph in bp.graphs or []:
        if graph.get('graph_type') == 'pnp':
            host_name = graph.get('host_name')
            service_description = graph.get('service_description')
            metric_name = graph.get('metric_name')
            pnp_result = run_pnp('json',
                                 host=graph.get('host_name'),
                                 srv=graph.get('service_description'))
            json_data = json.loads(pnp_result)
            for i in json_data:
                if i.get('ds_name') == graph.get('metric_name'):
                    notes = graph.get('notes')
                    last_value = bp.get_pnp_last_value(host_name,
                                                       service_description,
                                                       metric_name)
                    i['last_value'] = last_value
                    i['notes'] = notes
                    graphs.append(i)
    return graphs
Exemple #2
0
def graphs_json(request, process_name, process_type):
    """ Get graphs for one specific business process
    """
    c = {}
    c["messages"] = []
    c["errors"] = []
    import adagios.businessprocess

    bp = adagios.bi.get_business_process(process_name=process_name, process_type=process_type)

    graphs = []
    if not bp.graphs:
        return HttpResponse("[]")
    for graph in bp.graphs or []:
        if graph.get("graph_type") == "pnp":
            host_name = graph.get("host_name")
            service_description = graph.get("service_description")
            metric_name = graph.get("metric_name")
            pnp_result = run_pnp("json", host=graph.get("host_name"), srv=graph.get("service_description"))
            json_data = simplejson.loads(pnp_result)
            for i in json_data:
                if i.get("ds_name") == graph.get("metric_name"):
                    notes = graph.get("notes")
                    last_value = bp.get_pnp_last_value(host_name, service_description, metric_name)
                    i["last_value"] = last_value
                    i["notes"] = notes
                    graphs.append(i)
    graph_json = simplejson.dumps(graphs)
    return HttpResponse(graph_json)
Exemple #3
0
def graphs_json(request, process_name, process_type):
    """ Get graphs for one specific business process
    """
    c = {}
    c['messages'] = []
    c['errors'] = []
    import adagios.businessprocess
    bp = adagios.bi.get_business_process(process_name=process_name, process_type=process_type)

    graphs = []
    if not bp.graphs:
        return HttpResponse('[]')
    for graph in bp.graphs or []:
        if graph.get('graph_type') == 'pnp':
            host_name = graph.get('host_name')
            service_description = graph.get('service_description')
            metric_name = graph.get('metric_name')
            pnp_result = run_pnp('json', host=graph.get(
                'host_name'), srv=graph.get('service_description'))
            json_data = json.loads(pnp_result)
            for i in json_data:
                if i.get('ds_name') == graph.get('metric_name'):
                    notes = graph.get('notes')
                    last_value = bp.get_pnp_last_value(
                        host_name, service_description, metric_name)
                    i['last_value'] = last_value
                    i['notes'] = notes
                    graphs.append(i)
    graph_json = json.dumps(graphs)
    return HttpResponse(graph_json)
Exemple #4
0
def pnp(request, pnp_command='image'):
    c = {}
    c['messages'] = []
    c['errors'] = []
    result = run_pnp(pnp_command, **request.GET)
    mimetype = "text"
    if pnp_command == 'image':
        mimetype = "image/png"
    elif pnp_command == 'json':
        mimetype = "application/json"
    return HttpResponse(result, content_type=mimetype)
Exemple #5
0
def pnp(request, pnp_command="image"):
    c = {}
    c["messages"] = []
    c["errors"] = []
    result = run_pnp(pnp_command, **request.GET)
    content_type = "text"
    if pnp_command == "image":
        content_type = "image/png"
    elif pnp_command == "json":
        content_type = "application/json"
    return HttpResponse(result, content_type=content_type)
Exemple #6
0
def get_graph_urls(bp):
    """ Returns a json with urls to all graphs of a specific business process """
    graphs = []
    if not bp.graphs:
        return []
    for graph in bp.graphs or []:
        if graph.get('graph_type') == 'pnp':
            host_name = graph.get('host_name')
            service_description = graph.get('service_description')
            metric_name = graph.get('metric_name')
            pnp_result = run_pnp('json', host=graph.get(
                'host_name'), srv=graph.get('service_description'))
            json_data = simplejson.loads(pnp_result)
            for i in json_data:
                if i.get('ds_name') == graph.get('metric_name'):
                    notes = graph.get('notes')
                    last_value = bp.get_pnp_last_value(
                        host_name, service_description, metric_name)
                    i['last_value'] = last_value
                    i['notes'] = notes
                    graphs.append(i)
    return graphs
Exemple #7
0
def get_graph_urls(bp):
    """ Returns a json with urls to all graphs of a specific business process """
    graphs = []
    if not bp.graphs:
        return []
    for graph in bp.graphs or []:
        if graph.get('graph_type') == 'pnp':
            host_name = graph.get('host_name')
            service_description = graph.get('service_description')
            metric_name = graph.get('metric_name')
            pnp_result = run_pnp('json',
                                 host=graph.get('host_name'),
                                 srv=graph.get('service_description'))
            json_data = simplejson.loads(pnp_result)
            for i in json_data:
                if i.get('ds_name') == graph.get('metric_name'):
                    notes = graph.get('notes')
                    last_value = bp.get_pnp_last_value(host_name,
                                                       service_description,
                                                       metric_name)
                    i['last_value'] = last_value
                    i['notes'] = notes
                    graphs.append(i)
    return graphs
def bi_graphs_to_json(process_name, process_type='businessprocess'):
    c = {}
    c['messages'] = []
    c['errors'] = []
    bp = adagios.bi.get_business_process(process_name=process_name, process_type=process_type)

    graphs = []
    if not bp.graphs:
        return []
    for graph in bp.graphs or []:
        if graph.get('graph_type') == 'pnp':
            host_name = graph.get('host_name')
            service_description = graph.get('service_description')
            metric_name = graph.get('metric_name')
            pnp_result = run_pnp('json', host=graph.get('host_name'), srv=graph.get('service_description'))
            json_data = json.loads(pnp_result)
            for i in json_data:
                if i.get('ds_name') == graph.get('metric_name'):
                    notes = graph.get('notes')
                    last_value = bp.get_pnp_last_value(host_name, service_description, metric_name)
                    i['last_value'] = last_value
                    i['notes'] = notes
                    graphs.append(i)
    return graphs
Exemple #9
0
        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, 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, 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,
                                     )
Exemple #10
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))
Exemple #11
0
        total_duration = now - start_time
        state_hist = []
        start = start_time
        last_item = None
        css_hint = {}
        css_hint[0] = 'success'
        css_hint[1] = 'warning'
        css_hint[2] = 'danger'
        css_hint[3] = 'unknown'
        for i in log:
            i['duration_percent'] = 100 * i['duration'] / total_duration
            i['bootstrap_status'] = css_hint[i['state']]

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

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


def _get_network_parents(host_name):
    """ Returns a list of hosts that are network parents (or grandparents) to host_name

     Every item in the list is a host dictionary from mk_livestatus

     Returns:
Exemple #12
0
 def testGetJson(self):
     result = functions.run_pnp('json')
     self.assertGreaterEqual(
         len(result),
         0,
         msg=_("Tried to get json from pnp4nagios but result was improper"))
Exemple #13
0
 def testGetJson(self):
     result = functions.run_pnp('json')
     self.assertGreaterEqual(
         len(result), 0, msg=_("Tried to get json from pnp4nagios but result was improper"))