# # # # alert_util.cfv # # # # get_error_item() # get_error_profile_info() # alert_util_add_subitems() # alert_util_get_bug_report_as_node() # # # # # get_split_error_ids() # # # subroutine(get_split_error_ids( string combined_error_id), ( debug_message("#### get_split_error_ids() \n"); # This returns a node with one or more error_id's. # combined_error_id is a single error_id or several # error_id's separated by a comma. node n = new_node(); if (!contains(combined_error_id, ",")) then ( # Single error_id @n{0} = combined_error_id; ) else ( # Multiple error_id's split(combined_error_id, ",", n); ); debug_message("#### combined_error_id: " . combined_error_id . "\n"); debug_message("#### split error_id's: " . node_as_string(n) . "\n"); # Return n n; )); # # # # get_error_item() # # # subroutine(get_error_item( string error_id), ( # This returns the error node of the given error_id from # LogAnalysisInfo/logs/errors/error_messages.cfg or # from any backup node within LogAnalysisInfo/logs/errors/. node errors = "logs.errors"; node error_messages = errors{"error_messages"}; node error_item; if (error_messages?{error_id}) then ( error_item = error_messages{error_id}; ) else ( # The error_id does not exist error_messages though it may exist # in a backup node within errors. node error_messages_item; bool error_id_exists = false; foreach error_messages_item errors ( if (node_name(error_messages_item) ne "error_messages" and error_messages_item?{error_id}) then ( error_item = error_messages_item{error_id}; error_id_exists = true; last; ); ); # If the error node does not exist create an error message # that the error with the given error_id could not be found. if (!error_id_exists) then ( string error_msg = "An error occurred while reporting another error. The initial error message with error_id \"" . error_id . "\" "; error_msg .= "could not be found in LogAnalysisInfo/logs/errors/. Please report this error."; error_item = new_node(); error_item{"timestamp"} = ""; error_item{"date_time"} = ""; error_item{"process_id"} = ""; error_item{"message"} = error_msg; error_item{"traceback"} = ""; ); ); # Return error_item )); # # # # get_error_profile_info() # # # subroutine(get_error_profile_info( node error_item), ( # This subroutine returns an error_profile_info node if the error item contains profile specific data node error_profile_info = new_node(); if (error_item?{"profile"} and @error_item{"profile"} ne "") then ( @error_profile_info{'profile'} = @error_item{"profile"}; if (error_item?{"log_format"} and @error_item{"log_format"} ne "") then ( @error_profile_info{'log_format'} = @error_item{"log_format"}; ); if (error_item?{"syslog_required_format"} and @error_item{"syslog_required_format"} ne "") then ( @error_profile_info{'syslog_required_format'} = @error_item{"syslog_required_format"}; ); if (error_item?{"syslog_format"} and @error_item{"syslog_format"} ne "") then ( @error_profile_info{'syslog_format'} = @error_item{"syslog_format"}; ); # if (command_line.profile ne '') then ( # string profile_name = command_line.profile; # node profilenode = 'profiles'{command_line.profile}; # if (profilenode{'create_profile_wizard_info'}?{'log_format'}) then # @error_profile_info{'log_format'} = @profilenode{'create_profile_wizard_info'}{'log_format'}; # if (profilenode{'create_profile_wizard_info'}?{'syslog_required_format'}) then # @error_profile_info{'syslog_required_format'} = @profilenode{'create_profile_wizard_info'}{'syslog_required_format'}; # if (profilenode{'create_profile_wizard_info'}?{'syslog_format'}) then # @error_profile_info{'syslog_format'} = @profilenode{'create_profile_wizard_info'}{'syslog_format'}; # ); ); # Return error_profile_info; )); # # # # alert_util_add_subitems() # # # subroutine(alert_util_add_subitems( node source, node target), ( # This copies the node items of source to target, # it does not cover any subnodes in source, though # we assume that there aren't any. node item; string item_name; string item_value; foreach item source ( item_name = node_name(item); if (num_subnodes(item) == 0) then ( item_value = @item; ) else ( item_value = node_as_string(item); ); if (item_value eq "") then ( item_value = "-"; ); target{item_name} = item_value; ); )); # # # # alert_util_get_bug_report_as_node() # # # subroutine(alert_util_get_bug_report_as_node( string combined_error_id), ( # Returns a node with all relevant bug report data, this replaces compose_bug_report_text() debug_message("#### alert_util_get_bug_report_as_node() \n"); # string message_file = LOGANALYSISINFO_DIRECTORY . "TemporaryFiles/" . error_id . "_error_message.txt"; # string traceback_file = LOGANALYSISINFO_DIRECTORY . "TemporaryFiles/" . error_id . "_error_traceback.txt"; # KHP 16/May/2012 - Added support for multiple error_id's. # combined_error_id may consist of several error_id's separated by a comma. # Support for multiple error_id reporting is required for run_task() in scheduler. node all_error_ids = get_split_error_ids(combined_error_id); bool is_multiple_errors = (num_subnodes(all_error_ids) > 1); string error_id; node item; node error_item; string error_message; string error_traceback; node error_profile_info; string message_name; string traceback_name; string info_name; string message_label; string traceback_label; string info_label; int count = 1; # Create a bug report node from which the bug report is then assembled # for HTML output or HTTP POST. Escaping is done in the callee, not here. node bug_report = new_node(); # # # Individual error message data # # foreach item all_error_ids ( error_id = @item; error_item = get_error_item(error_id); error_message = @error_item{"message"}; error_traceback = @error_item{"traceback"}; error_profile_info = get_error_profile_info(error_item); debug_message("#### error_profile_info:\n" . node_as_string(error_profile_info) . "\n"); message_name = "message_" . count; traceback_name = "traceback_" . count; info_name = "info_" . count; message_label = "MESSAGE"; traceback_label = "TRACEBACK"; info_label = "INFO"; if (is_multiple_errors) then ( # Add number to labels message_label .= " " . count; traceback_label .= " " . count; info_label .= " " . count; ); bug_report{message_name}{"label"} = message_label; bug_report{message_name}{"item_value"} = error_message; bug_report{traceback_name}{"label"} = traceback_label; bug_report{traceback_name}{"item_value"} = if (error_traceback ne "") then (error_traceback) else ("-"); bug_report{info_name}{"label"} = info_label; if (num_subnodes(error_profile_info) > 0) then ( # Add info as subitems alert_util_add_subitems(error_profile_info, bug_report{info_name}{"items"}); ) else ( bug_report{info_name}{"item_value"} = "-"; ); count++; ); # # # Common error message data # # bool is_webserver_mode = !CGI_MODE; string operation_mode; if (is_webserver_mode) then ( operation_mode = "Webserver Mode"; ) else ( operation_mode = "CGI Mode"; ); bug_report{"system"}{"label"} = "SYSTEM"; bug_report{"system"}{"item_value"} = expand(PRODUCT_NAME . " " . VERSION . " (" . ARCH . ", " . operation_mode . ")"); bug_report{"licensing"}{"label"} = "LICENSING"; # Use check_licensing() to makes sure that the licensing node exists node licensing = check_licensing(); if (licensing?{"features"}) then ( # Add licensing features as subitems debug_message("#### licensing.features:\n" . node_as_string(licensing{"features"}) . "\n"); alert_util_add_subitems(licensing{"features"}, bug_report{"licensing"}{"items"}); ) else ( bug_report{"licensing"}{"item_value"} = "-"; ); debug_message("\n\n#### bug_report 1:\n" . node_as_string(bug_report) . "\n\n"); # Return bug_report; ));