# ---------------------------------------------------------------------- # This template is invoked from command line / scheduler actions -a only # ---------------------------------------------------------------------- # The task_originator is command_line or scheduler # -a Actions invoked are: # export_csv_table # send_report_by_email # generate_report_files # generate_all_report_files debug_message("report_setup.cfv START \n"); string session_id = volatile.session_id; string profile_name = command_line.profile; string action_name = command_line.action; string report_name = command_line.report_name; string zoom_value = command_line.zoom_value; # only used to zoom within a hierarchical report! string filters = command_line.filters; string task_originator = volatile.task_originator; string schedule_id; string report_id; bool expand_paths = command_line.expand_paths; bool date_breakdown = command_line.date_breakdown; bool generate_pdf_friendly_files = command_line.generate_pdf_friendly_files; string ending_row = command_line.ending_row; if (starts_with(task_originator, "schedule")) then ( schedule_id = replace_first(task_originator, "schedule.", ""); task_originator = "scheduler"; ); # Debug start --------------------------------------------------------------------------------------------- if (node_exists("command_line")) then ( debug_message("report_setup.cvf - command_line:\n " . node_as_string("command_line") . "\n"); ) else ( # debug_message("\n ####\n report_setup.cvf - No 'command_line' node exists!\n####\n"); ); if (node_exists("volatile.task_originator")) then ( # debug_message("\n ####\n report_setup.cvf - task_originator: " . volatile.task_originator . "\n"); ); # debug_message("\n ####\n report_setup.cvf - session_id: " . volatile.session_id . "\n"); # debug_message(node_as_string("volatile") . "\n"); # Debug end ----------------------------------------------------------------------------------------------- # -------------------------------- # Subroutine start_generate_report # -------------------------------- subroutine(start_generate_report( string session_id, string profile_name, string report_id, string report_directory, bool set_generate_mime_files), ( volatile.options.1 = "background"; volatile.options.2 = "-si"; volatile.options.3 = volatile.session_id; volatile.options.4 = "-p"; volatile.options.5 = profile_name; volatile.options.6 = "-gr"; volatile.options.7 = report_id; volatile.options.8 = "volatile.generate_mime_files"; volatile.options.9 = set_generate_mime_files; volatile.options.10 = "-v"; volatile.options.11 = "e"; if (report_directory ne "") then ( volatile.options.10 = "volatile.report_directory"; volatile.options.11 = report_directory; ); string pid = exec("", "volatile.options", true); )); # ------------------------------- # Subroutine get_date_time_exists # ------------------------------- subroutine(get_date_time_exists(string profile_name), ( bool date_time_exists = false; get_database_info(profile_name, "volatile.database_info"); if (node_exists("volatile.database_info.earliest_date_time")) then ( date_time_exists = true; ); date_time_exists; )); # ------------------------------- # Subroutine set_date_time_filter # ------------------------------- # Gets the date_time filter value for the internal node! # Only valid for actions started from Scheduler! subroutine(set_date_time_filter( string profile_name, string schedule_id, bool date_time_exists), ( # schedule_id is equal schedule node name string date_time_filter_type = "none"; bool date_time_filter_active = false; if (node_exists("schedule." . schedule_id . ".date_time_filter.active")) then ( date_time_filter_active = node_value("schedule." . schedule_id . ".date_time_filter.active"); ); debug_message("SUBROUTINE get_date_time_filter() \n"); debug_message("date_time_filter_active: " . date_time_filter_active . "\n"); if (date_time_filter_active) then ( if (date_time_exists) then ( string start_date; string end_date; int start_date_in_sec; int end_date_in_sec; string filter_value; string filter_expression; int back_count = node_value("schedule." . schedule_id . ".date_time_filter.back_count"); string back_count_unit = node_value("schedule." . schedule_id . ".date_time_filter.back_count_unit"); bool include_scheduler_execution_date = node_value("schedule." . schedule_id . ".date_time_filter.include_scheduler_execution_date"); end_date_in_sec = now(); if (back_count_unit eq "days") then ( if (!include_scheduler_execution_date) then ( end_date_in_sec = end_date_in_sec - (60*60*24); ); end_date = epoc_to_date_time(end_date_in_sec); if (back_count == 1) then ( end_date = substr(end_date, 0, 11) . " __:__:__"; filter_value = end_date; filter_expression = "(date_time within '" . end_date . "')"; date_time_filter_type = "date_time"; ) else ( end_date = substr(end_date, 0, 11) . " 23:59:59"; start_date_in_sec = end_date_in_sec - (60*60*24*(back_count - 1)); start_date = epoc_to_date_time(start_date_in_sec); start_date = substr(start_date, 0, 11) . " 00:00:00"; filter_value = start_date . "-" . end_date; filter_expression = "((date_time >= '" . start_date . "') and (date_time <= '" . end_date . "'))"; date_time_filter_type = "date_time_range"; ); ) else if (back_count_unit eq "months") then ( if (node_exists("volatile.temp.months")) then ( delete_node("volatile.temp.months"); ); volatile.temp.months.Jan = 1; volatile.temp.months.Feb = 2; volatile.temp.months.Mar = 3; volatile.temp.months.Apr = 4; volatile.temp.months.May = 5; volatile.temp.months.Jun = 6; volatile.temp.months.Jul = 7; volatile.temp.months.Aug = 8; volatile.temp.months.Sep = 9; volatile.temp.months.Oct = 10; volatile.temp.months.Nov = 11; volatile.temp.months.Dec = 12; volatile.temp.months.1 = "Jan"; volatile.temp.months.2 = "Feb"; volatile.temp.months.3 = "Mar"; volatile.temp.months.4 = "Apr"; volatile.temp.months.5 = "May"; volatile.temp.months.6 = "Jun"; volatile.temp.months.7 = "Jul"; volatile.temp.months.8 = "Aug"; volatile.temp.months.9 = "Sep"; volatile.temp.months.10 = "Oct"; volatile.temp.months.11 = "Nov"; volatile.temp.months.12 = "Dec"; end_date = epoc_to_date_time(end_date_in_sec); string month_string = substr(end_date, 3, 3); string year_string = substr(end_date, 7, 4); # debug_message("#### month_string: " . month_string . "\n"); # debug_message("#### year_string: " . year_string . "\n"); int end_month = node_value("volatile.temp.months." . month_string); int end_year = year_string; # debug_message("#### end_month: " . end_month . "\n"); # debug_message("#### end_year: " . end_year . "\n"); # debug_message("#### remainder of years: " . 24048 % 12 . "\n"); int total_number_of_months = ((end_year - 1) * 12) + end_month; if (!include_scheduler_execution_date) then ( total_number_of_months = total_number_of_months - 1; ); int final_end_year = total_number_of_months / 12; int final_end_month = total_number_of_months % 12; if (final_end_month == 0) then ( final_end_month = 12; ) else ( final_end_year++; ); string final_end_month_string = node_value("volatile.temp.months." . final_end_month); if (back_count == 1) then ( filter_value = "__/" . final_end_month_string . "/" . final_end_year . " __:__:__"; filter_expression = "(date_time within '" . filter_value . "')"; date_time_filter_type = "date_time"; ) else ( string final_end_date; if (include_scheduler_execution_date) then ( final_end_date = substr(end_date, 0, 11) . " 23:59:59"; ) else ( int number_of_days = (date_time_duration("__/" . final_end_month_string . "/" . final_end_year . " __:__:__")) / (60*60*24); string final_end_days = number_of_days; if (length(final_end_days == 1)) then ( final_end_days = "0" . final_end_days; ); final_end_date = final_end_days . "/" . final_end_month_string . "/" . final_end_year . " 23:59:59"; ); int final_start_year = (total_number_of_months - (back_count - 1)) / 12; int final_start_month = (total_number_of_months - (back_count - 1)) % 12; if (final_start_month == 0) then ( final_start_month = 12; ) else ( final_start_year++; ); string final_start_month_string = node_value("volatile.temp.months." . final_start_month); string final_start_date = "01/" . final_start_month_string . "/" . final_start_year . " 00:00:00"; filter_value = final_start_date . "-" . final_end_date; filter_expression = "((date_time >= '" . final_start_date . "') and (date_time <= '" . final_end_date . "'))"; date_time_filter_type = "date_time_range"; ); ) else ( # if back_count_unit eq years end_date = epoc_to_date_time(end_date_in_sec); string year_string = substr(end_date, 7, 4); int year = year_string; if (back_count == 1) then ( if (!include_scheduler_execution_date) then ( year--; year_string = year; ); filter_value = "__/___/" . year_string . " __:__:__"; filter_expression = "(date_time within '" . filter_value . "')"; date_time_filter_type = "date_time"; ) else ( string final_end_date; if (!include_scheduler_execution_date) then ( year--; final_end_date = "31/Dec/" . year . " 23:59:59"; ) else ( final_end_date = substr(end_date, 0, 11) . " 23:59:59"; ); int start_year = year - (back_count - 1); string final_start_date = "01/Jan/" . start_year . " 00:00:00"; filter_value = final_start_date . "-" . final_end_date; filter_expression = "((date_time >= '" . final_start_date . "') and (date_time <= '" . final_end_date . "'))"; date_time_filter_type = "date_time_range"; ); ); # debug_message("#### filter_value: " . filter_value . "\n"); # debug_message("#### filter_expression: " . filter_expression . "\n"); internal.date_time.date_time_filter_value = filter_value; internal.date_time.filter_expression = filter_expression; ); ); date_time_filter_type; )); # ----------------- # Subroutine set_df # ----------------- subroutine(set_df( string profile_name, bool date_time_exists), ( subroutine(build_single_date_string(string single_date_string, bool set_single, bool set_start, bool set_end), ( # returns a single date string without time int string_length = length(single_date_string); string result_date; if (string_length == 4) then ( # is year if (set_single) then ( result_date = "__/___/" . single_date_string; ); if (set_start) then ( result_date = "01/Jan/" . single_date_string; ); if (set_end) then ( result_date = "31/Dec/" . single_date_string; ); ) else if (string_length == 8) then ( # is month/year if (set_single) then ( result_date = "__/" . single_date_string; ); if (set_start) then ( result_date = "01/" . single_date_string; ); if (set_end) then ( # get the number of days in month int number_of_days = date_time_duration("__/" . single_date_string . " __:__:__") / (60*60*24); result_date = number_of_days . "/" . single_date_string; ); ) else if (string_length == 10) then ( # is day/month/year without leading 0, i.e. 1/Jan/2004 result_date = "0" . single_date_string; ) else if (string_length == 11) then ( # is day/month/year result_date = single_date_string; ) else ( # error in date string result_date = "__/___/____"; ); result_date; )); # ------ # set_df # ------ string date_time_filter_type = "none"; string filter_value; string filter_expression; if (date_time_exists) then ( string df_string = command_line.date_filter; # debug_message("----------------------------------------- set_df start-------------------------------------------\n"); # debug_message("df_string: " . df_string . "\n"); if (contains(df_string, "-")) then ( # compute date range split(df_string, "-", "volatile.temp.date_split"); # debug_message(node_as_string("volatile.temp.date_split") . "\n"); string start_date = volatile.temp.date_split.0; string end_date = volatile.temp.date_split.1; if (length(start_date) <= 11) then ( start_date = build_single_date_string(start_date, false, true, false); start_date .= " 00:00:00"; ); if (length(end_date) <= 11) then ( end_date = build_single_date_string(end_date, false, false, true); end_date .= " 23:59:59"; ); date_time_filter_type = "date_time_range"; filter_value = start_date . "-" . end_date; filter_expression = "((date_time >= '" . start_date . "') and (date_time <= '" . end_date . "'))"; ) else ( # compute single date string date_time; if (length(df_string) <= 11) then ( date_time = build_single_date_string(df_string, true, false, false); date_time .= " __:__:__"; ) else ( # df_string already contains the time values date_time = df_string; ); date_time_filter_type = "date_time"; filter_value = date_time; filter_expression = "(date_time within '" . date_time . "')"; debug_message("date_time: " . date_time . "\n"); ); ); # if date_time_exists date_time_filter_type; internal.date_time.date_time_filter_value = filter_value; internal.date_time.filter_expression = filter_expression; # debug_message("----------------------------------------- set_df end -------------------------------------------\n"); )); # ----------------------------------------- # Subroutine generate_multiple_report_files # ----------------------------------------- subroutine(generate_multiple_report_files( string report_menu_items_node, string session_id, string profile_name, string report_directory), ( node menu_item; string menu_type; bool visible_if_files; string report_name; foreach menu_item report_menu_items_node ( visible_if_files = node_value(subnode_by_name(menu_item, "visible_if_files")); if (visible_if_files) then ( menu_type = node_value(subnode_by_name(menu_item, "type")); if (menu_type eq "view") then ( report_name = node_value(subnode_by_name(menu_item, "view_name")); internal.report.report_name = report_name; save_session_changes(); string report_id = generate_report_id(profile_name, ""); start_generate_report(session_id, profile_name, report_id, report_directory, false); debug_message("exec done for report: " . report_name . "\n"); ) else ( if (node_exists(menu_item . ".items") and (num_subnodes(menu_item . ".items") > 0)) then ( # menu_type is group, handle menu group recursively generate_multiple_report_files(menu_item . ".items", session_id, profile_name, report_directory); ); ); ); # if visible_if_files ); # foreach menu_item )); # ---------------------------- # Basic report parameter setup # ---------------------------- internal.task_originator = task_originator; internal.report.report_name = report_name; internal.command_line.filter_expression = filters; internal.row_number_intervals.0.n = 10; internal.report_list = ""; if (ending_row ne "") then ( # ending_row overrides any existing ending_row internal.command_line.ending_row = ending_row; ); if (node_exists("volatile.current_language")) then ( internal.current_language = volatile.current_language; ) else ( internal.current_language = ""; ); # -------------------------------------------------------------------- # Set zoom (set via command line -zf (zoom field) and -zf (zoom value) # -------------------------------------------------------------------- bool zoom_is_active = false; if (zoom_value ne "") then ( string report_path = "profiles." . profile_name . ".statistics.reports." . report_name; if (node_exists(report_path) and (num_subnodes(report_path . ".report_elements") == 1)) then ( # get zoom_field string report_element_node = subnode_by_number(report_path . ".report_elements", 0); string zoom_field = node_value(subnode_by_name(report_element_node, "database_field_name")); "internal.zoom.zoom_fields." . zoom_field = zoom_value; internal.zoom.filter_expression = "(" . zoom_field . " within '" . zoom_value . "')"; zoom_is_active = true; ); ); internal.zoom.zoom_is_active = zoom_is_active; # ---------------- # date_time_exists # ---------------- bool date_time_exists = get_date_time_exists(profile_name); internal.date_time.date_time_exists = date_time_exists; # ---------------- # date_time_filter # ---------------- string date_time_filter_type = "none"; debug_message("task_originator: " . task_originator . "\n"); if (task_originator eq "scheduler") then ( if ((action_name eq "send_report_by_email") or (action_name eq "generate_report_files")) then ( date_time_filter_type = set_date_time_filter(profile_name, schedule_id, date_time_exists); ); ); if (command_line.date_filter ne "") then ( date_time_filter_type = set_df(profile_name, date_time_exists); ); internal.date_time.date_time_filter_type = date_time_filter_type; # ------------------ # set date_breakdown # ------------------ # Works only in combination with date_filter -df if ((command_line.date_filter ne "") and date_breakdown) then ( internal.date_time.breakdown = true; ) else ( internal.date_time.breakdown = false; ); # ---------------- # export_csv_table # ---------------- if (action_name eq "export_csv_table") then ( # create a node_id, exported data will be saved in LogAnalysisInfo/IPC/ int date_time_stamp = now(); string csv_data_node_name = "CSV_export_" . date_time_stamp; internal.task_type = "export"; internal.export.csv_data_node_name = csv_data_node_name; internal.export.export_to_file = false; internal.export.report_element = ""; save_session_changes(); report_id = generate_report_id(profile_name, ""); start_generate_report(session_id, profile_name, report_id, "", false); # Get the CSV export result data string csv_data = node_value("IPC." . csv_data_node_name); # display CSV in outpt stream csv_data; ); # -------------------- # send_report_by_email # -------------------- if (action_name eq "send_report_by_email") then ( internal.task_type = "email"; internal.email.recipient_address = command_line.recipient_address; internal.email.return_address = command_line.return_address; internal.email.report_email_subject = command_line.report_email_subject; internal.email.smtp_server = command_line.smtp_server; internal.expand_paths = expand_paths; save_session_changes(); report_id = generate_report_id(profile_name, ""); start_generate_report(session_id, profile_name, report_id, "", true); ); # --------------------- # generate_report_files # --------------------- if ((action_name eq "generate_report_files") and (report_name ne "*")) then ( string report_directory = expand(command_line.generate_html_to_directory); internal.task_type = "file"; internal.generate_html_to_directory = expand(command_line.generate_html_to_directory); internal.expand_paths = expand_paths; internal.report.generate_pdf_friendly_files = generate_pdf_friendly_files; save_session_changes(); report_id = generate_report_id(profile_name, ""); start_generate_report(session_id, profile_name, report_id, report_directory, false); ); # ------------------------- # generate_all_report_files # ------------------------- if ((action_name eq "generate_all_report_files") or ((action_name eq "generate_report_files") and (report_name eq "*"))) then ( string report_directory = expand(command_line.generate_html_to_directory); internal.task_type = "file"; internal.generate_html_to_directory = expand(command_line.generate_html_to_directory); internal.expand_paths = expand_paths; internal.report.generate_pdf_friendly_files = generate_pdf_friendly_files; node report_menu_items_node = "profiles." . profile_name . ".statistics.reports_menu"; # ----------------------------------------------------- # generate frameset files and generate multiple reports # ----------------------------------------------------- # Note, the left_navigation and table_of_contents are created prior generating the report files because it is # possible that the reports_menu needs to be updated (adding visible and visible_if_files nodes via update_reports_menu()!) string divider = internal.directory_divider; volatile.display_reports = true; volatile.generating_report_files = true; volatile.report_directory = report_directory; if (!ends_with(report_directory, divider)) then ( report_directory .= divider; ); if (!generate_pdf_friendly_files) then ( string left_navigation = expand(templates.statistics.left_navigation); write_file(report_directory . "left_navigation.html", left_navigation); string top_frame = expand(templates.profile.top_frame); write_file(report_directory . "top_frame.html", top_frame); generate_multiple_report_files(report_menu_items_node, session_id, profile_name, report_directory); string index_page = expand(templates.profile.index); write_file(report_directory . "index.html", index_page); ) else ( string table_of_contents = expand(templates.statistics.table_of_contents); generate_multiple_report_files(report_menu_items_node, session_id, profile_name, report_directory); write_file(report_directory . "index.html", table_of_contents); ); );