def display_site_landing(request): """ Display a list of all the available sites """ page_renderer = get_renderer("../templates/site_landing.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "modals/modal.js", "modals/iteminfo_modal.js", ] ampy = initAmpy(request) if ampy is None: print("Error starting ampy during item request") return None # get all sites that are in a source mesh, or that have a test scheduled # with them as the sources sources = ampy.get_amp_sources() sourcenames = [x["ampname"] for x in sources] sources.extend([x for x in ampy.get_amp_site_endpoints() if x["ampname"] not in sourcenames]) sources.sort(key=lambda x: (x["longname"], x["ampname"])) # get all sites that are in a destination mesh, or are not in a mesh destinations = ampy.get_amp_destinations() destinations.extend(ampy.get_amp_meshless_sites()) destinations.sort(key=lambda x: (x["longname"], x["ampname"])) # exclude any sources from the destinations list sourcenames = [x["ampname"] for x in sources] destinations = [x for x in destinations if x["ampname"] not in sourcenames] banopts = getBannerOptions(request) # TODO can this be done automatically when generating the lists? for source in sources: source["urlname"] = escapeURIComponent(source["ampname"]) for destination in destinations: destination["urlname"] = escapeURIComponent(destination["ampname"]) return { "title": "AMP Measurement Sites", "body": body, "scripts": SCRIPTS, "styles": ["bootstrap.min.css"], "sources": sources, "destinations": destinations, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "can_edit": has_permission("editconfig", request.context, request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }
def generateGraph(request, graph, url): title = graph.get_default_title() startgraph = generateStartScript("changeGraph", url[0]) page_renderer = get_renderer("../templates/graph.pt") body = page_renderer.implementation().macros['body'] banopts = getBannerOptions(request) scripts = getCommonScripts() + [ "pages/view.js", "lib/bootstrap-datetimepicker.min.js" ] scripts += pluginscripts scripts += stylescripts scripts += typescripts scripts += modalscripts scripts += pagescripts scripts += graph.get_required_scripts() settings = request.registry.settings if 'ampweb.eventratingfile' in settings: allowfeedback = True else: allowfeedback = False return { "title": title, "page": "view", "body": body, "styles": ['bootstrap.min.css', 'bootstrap-datetimepicker.min.css'], "scripts": scripts, "logged_in": authenticated_userid(request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "bannertitle": banopts['title'], "startgraph": startgraph, "allow_feedback": allowfeedback, }
def matrix(request): page_renderer = get_renderer("../templates/matrix.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "lib/jquery.sparkline.min.js", "pages/matrix.js", "matrix/basematrix.js", "matrix/latencymatrix.js", "matrix/lossmatrix.js", "matrix/hopmatrix.js", "matrix/throughputmatrix.js", "matrix/httpmatrix.js", "matrix/youtubematrix.js", "matrix/sipmatrix.js", ] ampy = initAmpy(request) if ampy is None: print("Error starting ampy during matrix request") return None src = ampy.get_meshes("source", public=True) banopts = getBannerOptions(request) return { "title": "AMP Measurements", "page": "matrix", "body": body, "scripts": SCRIPTS, "styles": ['bootstrap.min.css'], "logged_in": authenticated_userid(request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "bannertitle": banopts['title'], "srcMeshes": src, "tabs": _create_tabs(request), }
def display_users_landing(request): """ Display a list of all the users """ page_renderer = get_renderer("../templates/user_landing.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "modals/modal.js", "modals/user_modal.js", "pages/users.js", ] ampy = initAmpy(request) if ampy is None: print("Error starting ampy during item request") return None users = ampy.get_users() banopts = getBannerOptions(request) # TODO enforce username policy so this isn't required? #for user in users: # user["urlname"] = escapeURIComponent(user["username"]) return { "title": "AMP Measurement Users", "body": body, "scripts": SCRIPTS, "styles": ["bootstrap.min.css"], "users": users, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }
def display_mesh_landing(request): """ Display a list of all the available meshes """ page_renderer = get_renderer("../templates/mesh_landing.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "modals/modal.js", "modals/iteminfo_modal.js", ] ampy = initAmpy(request) if ampy is None: print("Error starting ampy during item request") return None meshes = ampy.get_meshes(None) banopts = getBannerOptions(request) for mesh in meshes: mesh["urlname"] = escapeURIComponent(mesh["ampname"]) return { "title": "AMP Measurement Meshes", "body": body, "scripts": SCRIPTS, "styles": ["bootstrap.min.css"], "meshes": meshes, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "can_edit": has_permission("editconfig", request.context, request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }
def display_item_info(request, ampname, category): """ Display an information page about a single site or mesh """ page_renderer = get_renderer("../templates/item.pt") body = page_renderer.implementation().macros['body'] SCRIPTS = getCommonScripts() + [ "lib/bootstrap-datetimepicker.min.js", "modals/modal.js", "modals/member_modal.js", "modals/iteminfo_modal.js", "modals/schedule_modal.js", "pages/item.js", ] STYLES = [ "bootstrap-datetimepicker.min.css", "bootstrap.min.css", ] ampname = urllib.parse.unquote(ampname) ampy = initAmpy(request) if ampy is None: print("Error starting ampy during schedule request") return None if category == "site": source = ampy.get_amp_site_info(ampname) members = meshes = ampy.get_meshes(None, site=ampname) else: meshes = {} source = ampy.get_amp_mesh_info(ampname) members = get_mesh_members(ampy, ampname) for member in members: member["urlname"] = escapeURIComponent(member["ampname"]) if "unknown" in source and source["unknown"] is True: return HTTPNotFound() # turn the list of dicts into a dict of dicts, keyed by ampname full_mesh_info = dict((x["ampname"], x) for x in ampy.get_meshes(None)) # XXX for mesh in full_mesh_info: full_mesh_info[mesh]["urlname"] = escapeURIComponent( full_mesh_info[mesh]["ampname"]) # get full info for any possible destinations that we have destinations = ampy.get_amp_destinations() destinations.extend(ampy.get_amp_meshless_sites()) full_dest_info = dict((x["ampname"], x) for x in destinations) # XXX for dest in full_dest_info: full_dest_info[dest]["urlname"] = escapeURIComponent( full_dest_info[dest]["ampname"]) # load the schedule for this particular source schedule = ampy.get_amp_source_schedule(ampname) schedule = [convert_schedule_item( source, x, full_mesh_info, full_dest_info) for x in schedule] # if it belongs to any meshes, then load those schedules too for mesh in meshes: mesh_schedule = ampy.get_amp_source_schedule(mesh["ampname"]) mesh_schedule = [convert_schedule_item( mesh, x, full_mesh_info, full_dest_info) for x in mesh_schedule] schedule.extend(mesh_schedule) # sort the schedule by test, then from most frequent to less frequent schedule.sort(key=lambda x: x["end"]) schedule.sort(key=lambda x: x["start"]) schedule.sort(key=lambda x: x["raw_frequency"]) schedule.sort(key=lambda x: x["test"]) # report on the current certificate status if possible if category == "site": source["pki"] = get_certificate_status(ampname) banopts = getBannerOptions(request) return { "title": "AMP Measurement Schedules for %s" % ampname, "page": "schedule", "body": body, "scripts": SCRIPTS, "styles": STYLES, "category": category, "ampname": ampname, "urlname": escapeURIComponent(ampname), "item": source, "members": members, "schedule": schedule, "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "can_edit": has_permission("editconfig", request.context, request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "logged_in": authenticated_userid(request), "bannertitle": banopts['title'], }
def dashboard(request): """ Generate the content for the basic overview dashboard page """ page_renderer = get_renderer("../templates/dashboard.pt") body = page_renderer.implementation().macros["body"] # display events from the last 24 hours end = time.time() start = end - (60 * 60 * 24) banopts = getBannerOptions(request) ampy = initAmpy(request) if ampy is None: print("Unable to start ampy while generating event dashboard") return None data = ampy.get_event_groups(start, end) groups = [] total_event_count = 0 total_group_count = 0 settings = request.registry.settings if 'ampweb.eventratingfile' in settings: allowfeedback = True else: allowfeedback = False if 'ampweb.hidedashgraphs' in settings: if settings['ampweb.hidedashgraphs'] in ['yes', 'true']: showrightgraphs = False else: showrightgraphs = True else: showrightgraphs = True # count global event/group statistics if data is not None: parser = EventParser(ampy) # get extra information about the 10 most recent event groups groups, total_group_count, total_event_count, _ = \ parser.parse_event_groups(data, start, end) dashboard_scripts = getCommonScripts() + [ "pages/dashboard.js", "eventgroups/events.js", "modals/eventrating_modal.js", "graphplugins/hit.js", "graphstyles/event_frequency.js", "lib/bootstrap-datetimepicker.min.js" ] return { "title": "Event Dashboard", "page": "dashboard", "body": body, "styles": ['bootstrap.min.css', 'dashboard.css'], "scripts": dashboard_scripts, "logged_in": authenticated_userid(request), "show_config": has_permission("viewconfig", request.context, request), "show_users": has_permission("editusers", request.context, request), "gtag": getGATrackingID(request), "show_dash": banopts['showdash'], "show_matrix": banopts['showmatrix'], "bannertitle": banopts['title'], "total_event_count": total_event_count, "total_group_count": total_group_count, "extra_groups": total_group_count - len(groups), "allow_feedback": allowfeedback, # XXX Globally disabled pending implementation of async loading # of graph data -- trying to process all the necessary # events before loading the dashboard was leading to massive # delays in loading the dashboard. Shane, 23/02/17 "showrightgraphs": False }