Exemplo n.º 1
0
def module_details(request, netbox_sysname, module_name):
    """Show detailed view of one IP device module"""
    def get_module_view(module_object, perspective, activity_interval=None):
        """
        Returns a dict structure with all ports on the module.

        Arguments:
        perspective -- decides what kind of ports are included.
        activity_interval -- number of days to check for port activity.

        """

        module = utils.get_module_view(module_object, perspective,
                                       activity_interval)

        if activity_interval is not None:
            module['activity_interval'] = activity_interval
            module['activity_interval_start'] = (
                dt.datetime.now() - dt.timedelta(days=activity_interval))

            # Check if we got data for the entire search interval
            try:
                module['activity_data_start'] = (
                    module_object.netbox.cam_set.order_by(
                        'start_time')[0].start_time)
                module['activity_data_interval'] = (
                    dt.datetime.now() - module['activity_data_start']).days
                module['activity_complete_data'] = (
                    module['activity_data_start'] <
                    module['activity_interval_start'])
            except IndexError:
                module['activity_data_start'] = None
                module['activity_data_interval'] = 0
                module['activity_complete_data'] = False

        return module

    # Get port activity search interval from form
    activity_interval = 30
    if 'interval' in request.GET:
        activity_interval_form = ActivityIntervalForm(request.GET)
        if activity_interval_form.is_valid():
            activity_interval = activity_interval_form.cleaned_data['interval']
    else:
        activity_interval_form = ActivityIntervalForm(
            initial={'interval': activity_interval})

    module = get_object_or_404(Module.objects.select_related(depth=1),
                               netbox__sysname=netbox_sysname,
                               name=module_name)
    swportstatus_view = get_module_view(module, 'swportstatus')
    swportactive_view = get_module_view(module, 'swportactive',
                                        activity_interval)
    gwportstatus_view = get_module_view(module, 'gwportstatus')

    navpath = NAVPATH + [('Module Details', )]

    return render_to_response('ipdevinfo/module-details.html', {
        'module': module,
        'swportstatus_view': swportstatus_view,
        'swportactive_view': swportactive_view,
        'gwportstatus_view': gwportstatus_view,
        'activity_interval_form': activity_interval_form,
        'activity_interval': activity_interval,
        'navpath': navpath,
        'heading': navpath[-1][0],
        'title': create_title(navpath)
    },
                              context_instance=RequestContext(
                                  request, processors=[search_form_processor]))
Exemplo n.º 2
0
def module_details(request, netbox_sysname, module_name):
    """Show detailed view of one IP device module"""

    def get_module_view(module_object, perspective, activity_interval=None):
        """
        Returns a dict structure with all ports on the module.

        Arguments:
        perspective -- decides what kind of ports are included.
        activity_interval -- number of days to check for port activity.

        """

        module = utils.get_module_view(
            module_object, perspective, activity_interval)

        if activity_interval is not None:
            module['activity_interval'] = activity_interval
            module['activity_interval_start'] = (
                    dt.datetime.now() - dt.timedelta(days=activity_interval))

            # Check if we got data for the entire search interval
            try:
                module['activity_data_start'] = (
                    module_object.netbox.cam_set.order_by(
                        'start_time')[0].start_time)
                module['activity_data_interval'] = (
                    dt.datetime.now() - module['activity_data_start']).days
                module['activity_complete_data'] = (
                    module['activity_data_start'] <
                    module['activity_interval_start'])
            except IndexError:
                module['activity_data_start'] = None
                module['activity_data_interval'] = 0
                module['activity_complete_data'] = False

        return module

    # Get port activity search interval from form
    activity_interval = 30
    if 'interval' in request.GET:
        activity_interval_form = ActivityIntervalForm(request.GET)
        if activity_interval_form.is_valid():
            activity_interval = activity_interval_form.cleaned_data[
                'interval']
    else:
        activity_interval_form = ActivityIntervalForm(
            initial={'interval': activity_interval})

    module = get_object_or_404(Module.objects.select_related(depth=1),
        netbox__sysname=netbox_sysname, name=module_name)
    swportstatus_view = get_module_view(module, 'swportstatus')
    swportactive_view = get_module_view(
        module, 'swportactive', activity_interval)
    gwportstatus_view = get_module_view(module, 'gwportstatus')

    navpath = NAVPATH + [('Module Details',)]

    return render_to_response(
        'ipdevinfo/module-details.html',
        {
            'module': module,
            'swportstatus_view': swportstatus_view,
            'swportactive_view': swportactive_view,
            'gwportstatus_view': gwportstatus_view,
            'activity_interval_form': activity_interval_form,
            'activity_interval': activity_interval,
            'navpath': navpath,
            'heading': navpath[-1][0],
            'title': create_title(navpath)
        },
        context_instance=RequestContext(request,
            processors=[search_form_processor]))
Exemplo n.º 3
0
def get_port_view(request, netbox_sysname, perspective):
    """Returns a html fragment with all modules and ports on the netbox.

    Arguments:
    netbox_sysname -- ...
    perspective -- decides what kind of ports are included.
    """

    netbox = get_object_or_404(Netbox, sysname=netbox_sysname)

    # Get port activity search interval from form
    activity_interval = 30
    activity_interval_form = None
    if perspective == 'swportactive':
        if 'interval' in request.GET:
            activity_interval_form = ActivityIntervalForm(request.GET)
            if activity_interval_form.is_valid():
                activity_interval = activity_interval_form.cleaned_data[
                    'interval']
        else:
            activity_interval_form = ActivityIntervalForm(
                initial={'interval': activity_interval})

    port_view = {
        'perspective':
        perspective,
        'modules': [],
        'activity_interval':
        activity_interval,
        'activity_interval_start':
        dt.datetime.now() - dt.timedelta(days=activity_interval),
    }

    # Check if we got data for the entire search interval
    try:
        port_view['activity_data_start'] = netbox.cam_set.order_by(
            'start_time')[0].start_time
        port_view['activity_data_interval'] = (
            dt.datetime.now() - port_view['activity_data_start']).days
        port_view['activity_complete_data'] = (
            port_view['activity_data_start'] <
            port_view['activity_interval_start'])
    except IndexError:
        port_view['activity_data_start'] = None
        port_view['activity_data_interval'] = 0
        port_view['activity_complete_data'] = False

    # Add the modules
    for module in netbox.module_set.select_related():
        port_view['modules'].append(
            utils.get_module_view(module, perspective, activity_interval))

    # Add interfaces with no module
    port_view['modules'].append(
        utils.get_module_view(None, perspective, activity_interval, netbox))

    # Min length of ifname for it to be shortened
    ifname_too_long = 12

    return render_to_response('ipdevinfo/modules.html', {
        'netbox': netbox,
        'port_view': port_view,
        'ifname_too_long': ifname_too_long,
        'activity_interval_form': activity_interval_form
    },
                              context_instance=RequestContext(request))
Exemplo n.º 4
0
def get_port_view(request, netbox_sysname, perspective):
    """Returns a html fragment with all modules and ports on the netbox.

    Arguments:
    netbox_sysname -- ...
    perspective -- decides what kind of ports are included.
    """

    netbox = get_object_or_404(Netbox, sysname=netbox_sysname)

    # Get port activity search interval from form
    activity_interval = 30
    activity_interval_form = None
    if perspective == 'swportactive':
        if 'interval' in request.GET:
            activity_interval_form = ActivityIntervalForm(request.GET)
            if activity_interval_form.is_valid():
                activity_interval = activity_interval_form.cleaned_data[
                                    'interval']
        else:
            activity_interval_form = ActivityIntervalForm(
                initial={'interval': activity_interval})

    port_view = {
            'perspective': perspective,
            'modules': [],
            'activity_interval': activity_interval,
            'activity_interval_start':
                dt.datetime.now() - dt.timedelta(days=activity_interval),
            }

    # Check if we got data for the entire search interval
    try:
        port_view['activity_data_start'] = netbox.cam_set.order_by(
            'start_time')[0].start_time
        port_view['activity_data_interval'] = (
            dt.datetime.now() - port_view['activity_data_start']).days
        port_view['activity_complete_data'] = (
            port_view['activity_data_start'] <
            port_view['activity_interval_start'])
    except IndexError:
        port_view['activity_data_start'] = None
        port_view['activity_data_interval'] = 0
        port_view['activity_complete_data'] = False

    # Add the modules
    for module in netbox.module_set.select_related():
        port_view['modules'].append(utils.get_module_view(
            module, perspective, activity_interval))

    # Add interfaces with no module
    port_view['modules'].append(utils.get_module_view(
        None, perspective, activity_interval, netbox))

    # Min length of ifname for it to be shortened
    ifname_too_long = 12

    return render_to_response(
        'ipdevinfo/modules.html',
            {
            'netbox': netbox,
            'port_view': port_view,
            'ifname_too_long': ifname_too_long,
            'activity_interval_form': activity_interval_form
            },
        context_instance=RequestContext(request))