{= # # # # detect_log_format_result.cfv # # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.encoding"; include "templates.new_profile_wizard.log_format_labels_util"; debug_message("\n\n#### detect_log_format_result.cfv \n"); # Invoked from the client after detect_log_format.cfv # Possible results are: # 1.) detect log format has been completed and a result node exists in TempoararyFiles. # The result node may indicate: # a.) One or more log formats have been detected. # b.) No log format has been detected. # c.) The log source is not valid. # 2.) detect log format has not yet been completed, a result node does not exist in TemporaryFiles # In this case initiate progress for auto-detection. string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_admin_feature_permission(session_id, "profiles", "add")) and get_is_valid_page_token(session_id, "new_profile_wizard", page_token)) then ( string autodetecting_id = v.fp.autodetecting_id; string task_id = v.fp.task_id; string server_response_method; string server_response_dat = "''"; debug_message("#### autodetecting_id: " . autodetecting_id . "\n"); debug_message("#### task_id: " . task_id . "\n"); if (node_exists("TemporaryFiles." . autodetecting_id)) then ( debug_message("#### Found auto-detecting result \n"); if (!node_exists("TemporaryFiles." . autodetecting_id . ".error_message")) then ( string detected_log_formats_dat; string log_format_item_dat; if (?("TemporaryFiles." . autodetecting_id) and (num_subnodes("TemporaryFiles." . autodetecting_id) > 0)) then ( node detected_log_formats = "TemporaryFiles." . autodetecting_id; debug_message("#### detected_log_formats:\n" . node_as_string(detected_log_formats) . "\n"); # TODO - must be disbaled in production version # Temp - simulate auto-detected log formats by overwriting detected_log_formats # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_1"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_2"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_3"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_4"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_5"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_6"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_7"; # detected_log_formats = "templates.new_profile_wizard.autodetected.direct_match_8"; # detected_log_formats = "templates.new_profile_wizard.autodetected.multiple_match_1"; # detected_log_formats = "templates.new_profile_wizard.autodetected.multiple_match_2"; # detected_log_formats = "templates.new_profile_wizard.autodetected.multiple_match_3"; # detected_log_formats = "templates.new_profile_wizard.autodetected.multiple_match_4"; detected_log_formats_dat = "["; int i; node detected_log_format; string detected_log_format_name; node log_format; string log_data_type; bool syslog_detected = false; bool syslog_required_detected = false; # KHP 10/Jan/2012 # Added support for syslog_optional as new log format type. # syslog_required will now always require a syslog # but syslog_optional may use the "no_syslog" header # when no syslog has been detected. # Though we do not include "no_syslog" as auto-detected syslog # but simply set it in the new profile wizard. bool syslog_optional_detected = false; foreach detected_log_format detected_log_formats ( detected_log_format_name = node_value(detected_log_format); debug_message("#### detected_log_format_name: " . detected_log_format_name . "\n"); log_format = "log_formats." . detected_log_format_name; log_data_type = node_value(subnode_by_name(log_format, "log.miscellaneous.log_data_type")); if (log_data_type eq "syslog") then ( syslog_detected = true; ) else if (log_data_type eq "syslog_required") then ( syslog_required_detected = true; ) else if (log_data_type eq "syslog_optional") then ( syslog_optional_detected = true; ); log_format_item_dat = get_log_format_item_dat(log_format); detected_log_formats_dat .= log_format_item_dat . ","; ); # # Handle missing syslog or syslog_required format # debug_message("#### syslog_required_detected: " . syslog_required_detected . "\n"); debug_message("#### syslog_detected: " . syslog_detected . "\n"); string missing_log_format_name; string missing_log_data_type; if (syslog_detected and !syslog_required_detected and !syslog_optional_detected) then ( # Detected syslog but no syslog_required nor a syslog_optional format # Add the general purpose "syslog_full_messages" # (syslog_required) plugin to the detected result. missing_log_format_name = "syslog_full_messages"; missing_log_data_type = "syslog_required"; ); # else if (syslog_optional_detected and !syslog_detected) then ( # # # Detected syslog_optional but no syslog. # # Add no_syslog.cfg as default syslog, which will # # work in most cases as the default syslog. # missing_log_format_name = "no_syslog"; # missing_log_data_type = "syslog"; # ); if (missing_log_format_name ne "") then ( string missing_label = @("log_formats." . missing_log_format_name . ".log.format.format_label"); string missing_labels_dat = '["' . encode_json(missing_label) . '"]'; log_format_item_dat = "{"; log_format_item_dat .= add_json("name", missing_log_format_name, "string"); log_format_item_dat .= add_json("labels", missing_labels_dat, "obj"); log_format_item_dat .= add_json("description", "", "string"); log_format_item_dat .= add_json("type", missing_log_data_type, "string"); log_format_item_dat .= add_json("lfType", missing_log_data_type, "string"); # Use same value as for type! log_format_item_dat .= add_json("isSupportedLogFormat", "true", "bool"); log_format_item_dat .= add_json("notSupportedMessage", "", "string"); log_format_item_dat = close_json(log_format_item_dat); detected_log_formats_dat .= log_format_item_dat . ","; ); detected_log_formats_dat = replace_last(detected_log_formats_dat,",","]"); ) else ( # No log format detected detected_log_formats_dat = "[]"; ); server_response_method = "server_response_detected_log_formats"; server_response_dat = detected_log_formats_dat; ) else ( string msg = node_value("TemporaryFiles." . autodetecting_id . ".error_message"); msg = encode_json(msg); server_response_method = "server_response_invalid_log_source"; server_response_dat = '"' . msg . '"'; ); ) else ( # show progress debug_message("#### No autodetecting result, show progress \n"); string suboperation_description = "-"; string log_bytes_downloaded = "-"; string display_format_type; if (node_exists("volatile.progress")) then ( delete_node("volatile.progress"); ); get_progress_info(task_id, "volatile.progress"); debug_message("#### detect log format progress:\n" . node_as_string("volatile.progress") . "\n"); if (?("volatile.progress.step.0.suboperation_description")) then ( # suboperation_description = get_text_value("volatile.progress.step.0.suboperation_description"); suboperation_description = @("volatile.progress.step.0.suboperation_description"); ); if (node_exists("volatile.progress.details.log_bytes_downloaded")) then ( log_bytes_downloaded = node_value("volatile.progress.details.log_bytes_downloaded"); display_format_type = node_value("volatile.progress.details.log_bytes_downloaded.display_format_type"); debug_message("#### display_format_type:" . display_format_type . "\n"); debug_message("#### log_bytes_downloaded 1:" . log_bytes_downloaded . "\n"); log_bytes_downloaded = format(log_bytes_downloaded, display_format_type); debug_message("#### log_bytes_downloaded 2:" . log_bytes_downloaded . "\n"); ); server_response_method = "server_response_autodetection_in_progess"; server_response_dat = "{"; server_response_dat .= add_json("suboperation_description", suboperation_description, "string"); server_response_dat .= add_json("log_bytes_downloaded", log_bytes_downloaded, "string"); server_response_dat = close_json(server_response_dat); ); debug_message("\n#### server_response_method:\n" . server_response_method . "\n"); debug_message("#### server_response_dat:\n" . server_response_dat . "\n"); 'newProfileWizard.' . server_response_method . '(' . server_response_dat . ')\n'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}