Beispiel #1
0
def snippets_log(request):
    """ Returns a html stub with the  snippet_statehistory_snippet.html
    """
    host_name = request.GET.get('host_name')
    service_description = request.GET.get('service_description')
    hostgroup_name = request.GET.get('hostgroup_name')

    if service_description == "_HOST_":
        service_description = None

    log = utils.get_state_history(request,
                                  host_name=host_name,
                                  service_description=service_description)

    # If hostgroup_name was specified, lets get all log entries that belong to that hostgroup
    if host_name and service_description:
        object_type = 'service'
    elif hostgroup_name:
        object_type = "hostgroup"
        hg = pynag.Model.Hostgroup.objects.get_by_shortname(hostgroup_name)
        hosts = hg.get_effective_hosts()
        hostnames = [x.host_name for x in hosts]
        log = [x for x in log if x['host_name'] in hostnames]
    elif host_name:
        object_type = "host"
    else:
        raise Exception(
            _("Need either a host_name or hostgroup_name parameter"))

    c = {'log': log}
    c['object_type'] = object_type
    # Create some state history progress bar from our logs:
    if len(c['log']) > 0:
        log = c['log']
        c['start_time'] = start_time = log[0]['time']
        c['end_time'] = end_time = log[-1]['time']
        now = time.time()

        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']]

    return render_to_response('snippets/status_statehistory_snippet.html',
                              locals(),
                              context_instance=RequestContext(request))
Beispiel #2
0
def snippets_log(request):
    """ Returns a html stub with the  snippet_statehistory_snippet.html
    """
    host_name = request.GET.get('host_name')
    service_description = request.GET.get('service_description')
    hostgroup_name = request.GET.get('hostgroup_name')

    if service_description == "_HOST_":
        service_description = None

    log = utils.get_state_history(request, host_name=host_name, service_description=service_description)

    # If hostgroup_name was specified, lets get all log entries that belong to that hostgroup
    if host_name and service_description:
        object_type = 'service'
    elif hostgroup_name:
        object_type = "hostgroup"
        hg = pynag.Model.Hostgroup.objects.get_by_shortname(hostgroup_name)
        hosts = hg.get_effective_hosts()
        hostnames = map(lambda x: x.host_name, hosts)
        log = filter(lambda x: x['host_name'] in hostnames, log)
    elif host_name:
        object_type = "host"
    else:
        raise Exception(_("Need either a host_name or hostgroup_name parameter"))

    c = {'log':log}
    c['object_type'] = object_type
    # Create some state history progress bar from our logs:
    if len(c['log']) > 0:
        log = c['log']
        c['start_time'] = start_time = log[0]['time']
        c['end_time'] = end_time = log[-1]['time']
        now = time.time()

        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']]

    return render_to_response('snippets/status_statehistory_snippet.html', locals(), context_instance=RequestContext(request))
Beispiel #3
0
def state_history(request):
    c = {}
    c['messages'] = []
    c['errors'] = []

    livestatus = adagios.status.utils.livestatus(request)
    start_time = request.GET.get('start_time', None)
    end_time = request.GET.get('end_time', None)
    if end_time is None:
        end_time = time.time()
    end_time = int(float(end_time))
    if start_time is None:
        seconds_in_a_day = 60 * 60 * 24
        seconds_today = end_time % seconds_in_a_day  # midnight of today
        start_time = end_time - seconds_today
    start_time = int(start_time)

    c['log'] = log = utils.get_state_history(request, start_time=start_time, end_time=end_time,strict=False)
    total_duration = end_time - start_time
    c['total_duration'] = total_duration
    css_hint = {}
    css_hint[0] = 'success'
    css_hint[1] = 'warning'
    css_hint[2] = 'danger'
    css_hint[3] = 'info'
    last_item = None

    services = {}
    search_filter = request.GET.copy()
    search_filter.pop('start_time', None)
    search_filter.pop('end_time', None)
    search_filter.pop('start_time_picker', None)
    search_filter.pop('start_hours', None)
    search_filter.pop('end_time_picker', None)
    search_filter.pop('end_hours', None)
    search_filter.pop('submit', None)

    log = pynag.Utils.grep(log, **search_filter)
    for i in log:
        short_name = "%s/%s" % (i['host_name'], i['service_description'])
        if short_name not in services:
            s = {}
            s['host_name'] = i['host_name']
            s['service_description'] = i['service_description']
            s['log'] = []
            s['worst_logfile_state'] = 0
            #s['log'] = [{'time':start_time,'state':3, 'plugin_output':'Unknown value here'}]
            services[short_name] = s

        services[short_name]['log'].append(i)
        services[short_name]['worst_logfile_state'] = max(
            services[short_name]['worst_logfile_state'], i['state'])
    for service in services.values():
        last_item = None
        service['sla'] = float(0)
        service['num_problems'] = 0
        service['duration'] = 0
        for i in service['log']:
            i['bootstrap_status'] = css_hint[i['state']]
            if i['time'] < start_time:
                i['time'] = start_time
            if last_item is not None:
                last_item['end_time'] = i['time']
                #last_item['time'] = max(last_item['time'], start_time)
                last_item['duration'] = duration = last_item[
                    'end_time'] - last_item['time']
                last_item['duration_percent'] = 100 * float(
                    duration) / total_duration
                service['duration'] += last_item['duration_percent']
                if last_item['state'] == 0:
                    service['sla'] += last_item['duration_percent']
                else:
                    service['num_problems'] += 1
            last_item = i
        if not last_item is None:
            last_item['end_time'] = end_time
            last_item['duration'] = duration = last_item[
                'end_time'] - last_item['time']
            last_item['duration_percent'] = 100 * duration / total_duration
            service['duration'] += last_item['duration_percent']
            if last_item['state'] == 0:
                service['sla'] += last_item['duration_percent']
            else:
                service['num_problems'] += 1
    live_services = livestatus.get_services("Columns: host_name description")

    # Convert live services into "host_name/description" strings:
    live_service_names = ["%s/%s" % (x['host_name'], x['description']) for x in live_services]

    # Collect a list of service_names that are in our log, but not in livestatus:
    dead_service_names = [x for x in services if x not in live_service_names]

    # Remove all dead service names from state history:
    for short_name in dead_service_names:
        services.pop(short_name)

    c['services'] = services
    c['start_time'] = start_time
    c['end_time'] = end_time
    return render_to_response('state_history.html', c, context_instance=RequestContext(request))
Beispiel #4
0
def state_history(request):
    c = {}
    c['messages'] = []
    c['errors'] = []

    livestatus = adagios.status.utils.livestatus(request)
    start_time = request.GET.get('start_time', None)
    end_time = request.GET.get('end_time', None)
    if end_time is None:
        end_time = time.time()
    end_time = int(float(end_time))
    if start_time is None:
        seconds_in_a_day = 60 * 60 * 24
        seconds_today = end_time % seconds_in_a_day  # midnight of today
        start_time = end_time - seconds_today
    start_time = int(start_time)

    c['log'] = log = utils.get_state_history(request,
                                             start_time=start_time,
                                             end_time=end_time,
                                             strict=False)
    total_duration = end_time - start_time
    c['total_duration'] = total_duration
    css_hint = {}
    css_hint[0] = 'success'
    css_hint[1] = 'warning'
    css_hint[2] = 'danger'
    css_hint[3] = 'info'
    last_item = None

    services = {}
    search_filter = request.GET.copy()
    search_filter.pop('start_time', None)
    search_filter.pop('end_time', None)
    search_filter.pop('start_time_picker', None)
    search_filter.pop('start_hours', None)
    search_filter.pop('end_time_picker', None)
    search_filter.pop('end_hours', None)
    search_filter.pop('submit', None)

    log = pynag.Utils.grep(log, **search_filter)
    for i in log:
        short_name = "%s/%s" % (i['host_name'], i['service_description'])
        if short_name not in services:
            s = {}
            s['host_name'] = i['host_name']
            s['service_description'] = i['service_description']
            s['log'] = []
            s['worst_logfile_state'] = 0
            #s['log'] = [{'time':start_time,'state':3, 'plugin_output':'Unknown value here'}]
            services[short_name] = s

        services[short_name]['log'].append(i)
        services[short_name]['worst_logfile_state'] = max(
            services[short_name]['worst_logfile_state'], i['state'])
    for service in list(services.values()):
        last_item = None
        service['sla'] = float(0)
        service['num_problems'] = 0
        service['duration'] = 0
        for i in service['log']:
            i['bootstrap_status'] = css_hint[i['state']]
            if i['time'] < start_time:
                i['time'] = start_time
            if last_item is not None:
                last_item['end_time'] = i['time']
                #last_item['time'] = max(last_item['time'], start_time)
                last_item['duration'] = duration = last_item[
                    'end_time'] - last_item['time']
                last_item['duration_percent'] = 100 * float(
                    duration) / total_duration
                service['duration'] += last_item['duration_percent']
                if last_item['state'] == 0:
                    service['sla'] += last_item['duration_percent']
                else:
                    service['num_problems'] += 1
            last_item = i
        if not last_item is None:
            last_item['end_time'] = end_time
            last_item['duration'] = duration = last_item[
                'end_time'] - last_item['time']
            last_item['duration_percent'] = 100 * duration / total_duration
            service['duration'] += last_item['duration_percent']
            if last_item['state'] == 0:
                service['sla'] += last_item['duration_percent']
            else:
                service['num_problems'] += 1
    live_services = livestatus.get_services("Columns: host_name description")

    # Convert live services into "host_name/description" strings:
    live_service_names = [
        "%s/%s" % (x['host_name'], x['description']) for x in live_services
    ]

    # Collect a list of service_names that are in our log, but not in livestatus:
    dead_service_names = [x for x in services if x not in live_service_names]

    # Remove all dead service names from state history:
    for short_name in dead_service_names:
        services.pop(short_name)

    c['services'] = services
    c['start_time'] = start_time
    c['end_time'] = end_time
    return render_to_response('state_history.html',
                              c,
                              context_instance=RequestContext(request))