# # # profile_setup # # Functions in this template are invoked from # C++ (add_standard_reports() only) or from a log format plugin only # # clean_up_log_filters() # delete_database_field() # delete_xref_group() # add_field_to_xref_group() # # add_standard_reports() # include "templates.util.fix_duplicate_labels"; include "templates.util.update_reports_menu_labels"; include "lib.profile_setup.clean_up_report_groups"; include "lib.profile_setup.util"; # # clean_up_log_filters() # # Purpose: This cleans the log filters, removing any that refer to fields that don't exist. # # Parameters: profile: the profile to clean # subroutine(clean_up_log_filters(node profile), ( # Clean up filters and parsing filters for (int type = 0; type < 2; type++) ( string filters; if (type == 0) then filters = profile . ".log.filters"; else filters = profile . ".log.parsing_filters"; # Look through all the filters int num_filters = num_subnodes(filters); int filter_num; for (filter_num = 0; filter_num < num_filters; filter_num++) ( node filter = subnode_by_number(filters, filter_num); string filter_value = node_value(filter); # Do special cleanup on log.filters if (type == 0) then ( # If this is a final events filter (with any field name) but events are not being tracked, delete it # This is a general version of the two filters below; it will work with any field name. if (matches_regular_expression(filter_value, "^([a-z_]+) = 1;") and !node_exists(profile . ".log.fields." . $1)) then ( delete_node(filter); filter_num = -1; ); # If this is a final requests filter but requests are not being tracked, delete it if (contains(filter_value, "requests = 1;") and !node_exists(profile . ".log.fields.requests")) then ( delete_node(filter); filter_num = -1; ); # If this is a file type categorization filter but page views is not being tracked, delete it if (contains(filter_value, "file_type eq 'GIF'") and !node_exists(profile . ".log.fields.page_views")) then ( delete_node(filter); filter_num = -1; ); # If this is a filter that looks for page_views == 0 but page views is not being tracked, delete it if (contains(filter_value, "page_views == 0") and !node_exists(profile . ".log.fields.page_views")) then ( delete_node(filter); filter_num = -1; ); ); # if log.filters # If this filter contains a requires_fields node, make sure all the fields it needs exist; otherwise, delete it. if (node_exists(filter . ".requires_fields")) then ( node required_field; bool delete_filter = false; foreach required_field (filter . ".requires_fields") ( if (!node_exists(profile . ".log.fields." . node_name(required_field))) then ( delete_filter = true; ); ); if (delete_filter) then ( delete_node(filter); filter_num = -1; ); ); int num_filters = num_subnodes(filters); ); # for filter_num ); # for filter type )); #### clean_up_log_filters() #### # # delete_database_field() # # Purpose: This deletes a database field # # Parameters: profile: the profile # dbfieldname: the name of the field to delete # subroutine(delete_database_field(node profile, string dbfieldname), ( # Make sure the field exists if (node_exists(profile . ".database.fields." . dbfieldname)) then ( delete_node(profile . ".database.fields." . dbfieldname); node group; foreach group (profile . ".database.cross_reference_groups") ( node fields = group{"fields"}; bool detected_field = false; node field; foreach field fields ( if (node_name(field) eq dbfieldname) then ( detected_field = true; ); ); # foreach field # If this group contained the field, delete it if (detected_field) then ( delete_node(group); ); ); # foreach group ); # if field exists )); #### delete_database_field() #### # # delete_xref_group() # # Purpose: This deletes a cross-reference group # # Parameters: profile: the profile # xrefgroup: the name of the group to delete # subroutine(delete_xref_group(node profile, string xrefgroup), ( # Make sure the group exists if (node_exists(profile . ".database.cross_reference_groups." . xrefgroup)) then ( delete_node(profile . ".database.cross_reference_groups." . xrefgroup); ); # if group exists )); #### delete_xref_group() #### # # add_field_to_xref_group() # # Purpose: This adds a field to a cross-reference group # # Parameters: profile: the profile # xrefgroupname: the name of the group to add to # dbfieldname: the name of the field to add # subroutine(add_field_to_xref_group(node profile, string xrefgroupname, string dbfieldname), ( # Add this field, if it exists if (node_exists(profile . ".database.fields." . dbfieldname)) then ( (profile . ".database.cross_reference_groups." . xrefgroupname . ".fields." . dbfieldname) = ""; # If the xref group has no label, it must be newly-created--use the name as the label if (!(?(profile . ".database.cross_reference_groups." . xrefgroupname . ".label"))) then (profile . ".database.cross_reference_groups." . xrefgroupname . ".label") = xrefgroupname; ) # if field exists )); #### add_field_to_xref_group() #### # # add_standard_reports() # # Purpose: This adds all standard reports to a profile # # # Parameters: profile: the profile to add the report to # add_geo_location_reports: true to add geo_location reports; false otherwise # subroutine(add_standard_reports_without_snapons(node profile, bool add_geo_location_reports), ( debug_message("\n\n#### add_standard_reports_without_snapons() START \n\n"); # debug_message("\n\n" . node_as_string(profile) . "\n\n"); #echo("add_standard_reports_without_snapons(); add_geo_location_reports=" . add_geo_location_reports); # Show create_profile_wizard_info # debug_message("#### create_profile_wizard_info:\n" . node_as_string(profile{"create_profile_wizard_info"}) . "\n"); # # # Check whether to create the menu as specified in the log format plug in (manual_reports_menu = true) # or to create it automatically # # bool is_manual_reports_menu = false; if (?(profile . ".create_profile_wizard_options.manual_reports_menu") and @(profile . ".create_profile_wizard_options.manual_reports_menu")) then ( is_manual_reports_menu = true; ); # debug_message("#### is_manual_reports_menu: " . is_manual_reports_menu . "\n"); # sleep_milliseconds(15000); # # # Prepare report generation # # check_database_fields_integrity(profile); create_database_filters(profile); check_log_fields_integrity(profile); add_report_fields(profile, is_manual_reports_menu, add_geo_location_reports); update_numerical_report_fields(profile); node numerical_report_fields = create_numerical_report_fields_node(profile); string main_numerical_field_name = node_name(subnode_by_number(numerical_report_fields, 0)); # # # Set up the final report groups from which all reports will be created # # # # # # Clean up report groups in log format plugin # # # # Creates a single report_groups node for auto and manual # report generation and a custom reports node for any custom report # Any custom report in report groups is written to final_custom_reports for final processing delete_node("v.final_report_groups"); v.final_report_groups = ""; node final_report_groups = "v.final_report_groups"; delete_node("v.final_custom_reports"); v.final_custom_reports = ""; node final_custom_reports = "v.final_custom_reports"; clean_up_report_groups(profile, final_report_groups, final_custom_reports, is_manual_reports_menu, numerical_report_fields, add_geo_location_reports); # debug_message("\n\n#### #### PAUSE #### #### \n\n"); # sleep_milliseconds(15000); # # # Create all reports # # # debug_message("#### final_report_groups 1: \n" . node_as_string(final_report_groups) . "\n"); # debug_message("#### final_custom_reports 1: \n" . node_as_string(final_custom_reports) . "\n"); # sleep_milliseconds(15000); create_reports_from_final_report_groups(profile, final_report_groups, final_custom_reports, main_numerical_field_name); # debug_message("#### KHP 1: \n" . node_as_string(profile . ".statistics.reports") . "\n"); # sleep_milliseconds(15000); # KHP 05/May/2011 # create_xref_groups() must run after add_report_fields() because # add_report_fields() may delete not required database fields. create_xref_groups(profile); # # # Add group labels to reports menu # # add_reports_menu_group_labels(profile, final_report_groups); # # We capitalize the fields after the reports have been added # so that we can read the report labels from the report fields # capitalize_field_labels(profile); # # # Fix duplicate field labels # # # Note, doesn't apply fix_duplicate_labels() before capitalize_field_labels() has been accomplished! bool is_fixed_log_field_labels = fix_duplicate_labels(profile . ".log.fields"); bool is_fixed_db_field_lables = fix_duplicate_labels(profile . ".database.fields"); bool is_fixed_report_field_lables = fix_duplicate_labels(profile . ".statistics.report_fields"); debug_message("#### is_fixed_log_field_labels: " . is_fixed_log_field_labels . "\n"); debug_message("#### is_fixed_db_field_lables: " . is_fixed_db_field_lables . "\n"); debug_message("#### is_fixed_report_field_lables: " . is_fixed_report_field_lables . "\n"); # # # Add labels to reports_menu (see templates.util.update_reports_menu_labels() for details) # # debug_message("\n\n#### update_reports_menu_labels() START \n\n"); update_reports_menu_labels(profile . ".statistics.reports_menu", profile . ".statistics.reports"); debug_message("\n\n#### update_reports_menu_labels() DONE \n\n"); # # # Clean up database fields # # clean_up_database_fields(profile); # # # Clean up the log filters # # debug_message("\n\n#### clean_up_log_filters() START \n\n"); clean_up_log_filters(profile); debug_message("\n\n#### clean_up_log_filters() DONE \n\n"); # Remember which version this was created by @profile{"version"}{"created_in_version"} = @'internal'{"VERSION"}; )); # add_standard_reports_without_snapons() subroutine(add_standard_reports(node profile), ( #echo(`profile{"create_profile_wizard_options"}: ` . node_as_string(profile{"create_profile_wizard_options"})); #echo(`profile{"create_profile_wizard_info"}: ` . node_as_string(profile{"create_profile_wizard_info"})); # Attach all specified snapons # 2011-04-28 - GMF - Moved this to the top, because tomcat_pattern uses a snapon to set up database fields, which then must be used below to set up reports. #echo("calling attach_snapons()"); attach_snapons(profile); #echo("Done calling attach_snapons()"); # If the plug-in does not have snapons, add standard reports directly. if (!profile{"create_profile_wizard_options"}?{"snapons"}) then ( #echo("Adding standard reports without snapons"); add_standard_reports_without_snapons(profile, true); ); # Attach all standard snapons # 2011-05-09 - GMF - Split this off of attach_snapons(), so user-defined snapons can be attached first, and standard ones later. #echo("Attaching standard snapons"); attach_standard_snapons(profile); #echo("DONE Attaching standard snapons"); # # # DEBUG ONLY # # # debug_message("\n\n#### #### TEMP DEBUG #### ####\n"); # debug_message("\n" . node_as_string(profile{"database"}{"fields"}) . "\n"); # debug_message("\n" . node_as_string(profile{"statistics"}{"report_fields"}) . "\n"); # debug_message("\n" . node_as_string(profile{"statistics"}{"reports"}) . "\n"); )); #### add_standard_reports ####