Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdall committed Jun 26, 2019
1 parent 91c9181 commit e451cd5
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 7 deletions.
69 changes: 62 additions & 7 deletions tree/20_cfe_basics/log_rudder.cf
Expand Up @@ -15,10 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @name Log for Rudder
# @description Logging output for Rudder reports
#
# @name Log for Rudder with mode
# @description Logging different verbosity outputs for Rudder reports
#
# @parameter mode The mode use to make the report (can be info, normal, debug)
# @parameter message The common part of the message to display
# @parameter class_parameter The class_parameter for reporting (4.3+ version)
# @parameter old_class_prefix The prefix of the class for different states (<4.3 version)
Expand All @@ -28,7 +29,7 @@
# @class_prefix logger_rudder
# @class_parameter old_class_prefix

bundle agent log_rudder(message, class_parameter, old_class_prefix, class_prefix, args)
bundle agent log_rudder_mode(mode, message, class_parameter, old_class_prefix, class_prefix, args)
{

vars:
Expand All @@ -44,11 +45,39 @@ bundle agent log_rudder(message, class_parameter, old_class_prefix, class_prefix

"component_key" string => "${class_parameter}";

pass1.known_mode::
"effective_mode" string => "${mode}";
pass1.no_specified_mode::
"effective_mode" string => "${report_data.identifier}";
# TODO if the mode in not correct

defaults:
# if class_parameter is not set, then use the component_key from report_data
"component_key" string => "${report_data.component_key}", if_match_regex => "";

classes:

"pass2" expression => "pass1";
"pass1" expression => "any";

# Verify that the mode is known
"classic" or => {
strcmp("result_na", "${mode}"),
strcmp("result_success", "${mode}"),
strcmp("result_error", "${mode}"),
strcmp("result_repaired", "${mode}"),
};
"log" or => {
strcmp("log_repaired", "${mode}"),
strcmp("log_warn", "${mode}"),
strcmp("log_info", "${mode}"),
strcmp("log_debug", "${mode}"),
strcmp("log_trace", "${mode}")
};

"known_mode" or => { "classic", "log" };
"no_mode" expression => strcmp("", "${mode}");

# Use the full class prefix if:
# - it is defined
# - its length is smaller than 1000 character (classes are limited to 1023 characters, so if the prefix
Expand All @@ -63,20 +92,46 @@ bundle agent log_rudder(message, class_parameter, old_class_prefix, class_prefix
"use_class_prefix" expression => "class_prefix_defined.class_prefix_size_ok";

methods:
!use_class_prefix::
pass2.no_mode.!use_class_prefix::
"report" usebundle => _rudder_common_reports_generic("${report_data.technique_name}", "${c_old_class_prefix}", "${report_data.identifier}", "${report_data.component_name}", "${component_key}", "${message}"),
classes => classes_generic("logger_rudder_${c_old_class_prefix}");

use_class_prefix::
pass2.no_mode.use_class_prefix::
"report" usebundle => _rudder_common_reports_generic("${report_data.technique_name}", "${c_class_prefix}", "${report_data.identifier}", "${report_data.component_name}", "${component_key}", "${message}"),
classes => classes_generic("logger_rudder_${c_class_prefix}");

pass2.log.!use_class_prefix::
"report" usebundle => _rudder_common_report("${report_data.technique_name}", "${c_old_class_prefix}", "${effective_mode}", "${report_data.identifier}", "${report_data.component_name}", "${component_key}", "${message}"),
classes => classes_generic("logger_rudder_${c_old_class_prefix}");

pass2.log.use_class_prefix::
"report" usebundle => _rudder_common_report("${report_data.technique_name}", "${c_class_prefix}", "${effective_mode}", "${report_data.identifier}", "${report_data.component_name}", "${component_key}", "${message}"),
classes => classes_generic("logger_rudder_${c_class_prefix}");

reports:
info.!class_prefix_size_ok::
pass2.info.!class_prefix_size_ok::
# Since the class_prefix is too long, i'm not outputing it (it would fill several lines of text with no added value)
"${configuration.info}: Class prefix is too long - fallbacking to old_class_prefix ${old_class_prefix} for reporting";
}

# @name Log for Rudder
# @description Logging output for Rudder reports
#
# @parameter message The common part of the message to display
# @parameter class_parameter The class_parameter for reporting (4.3+ version)
# @parameter old_class_prefix The prefix of the class for different states (<4.3 version)
# @parameter class_prefix The prefix of the class for different states (4.3+ version)
# @parameter args The arguments used to call the generic method (slist)
#
# @class_prefix logger_rudder
# @class_parameter old_class_prefix

bundle agent log_rudder(message, class_parameter, old_class_prefix, class_prefix, args)
{
methods:
"report" usebundle => log_rudder_mode("", "${message}", "${class_parameter}", "${old_class_prefix}", "${class_prefix}", "${args}");
}

# bundle backported from rudder (prefixed with _ to avoid conflicts)
# all this whould be removed when we put this file back to rudder
#
Expand Down
46 changes: 46 additions & 0 deletions tree/30_generic_methods/_log_v3_mode.cf
@@ -0,0 +1,46 @@
#####################################################################################
# Copyright 2013-2015 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

# @name Log_v3_mode
# @description Standard logging output, with class_parameter passed as an argument
#
# @parameter mode The verbosity mode to use
# @parameter message The common part of the message to display
# @parameter class_parameter The class parameter used for reporting to support iterator
# @parameter old_class_prefix The prefix of the class for different states (<4.3 version)
# @parameter class_prefix The prefix of the class for different states (4.3 version)
# @parameter args The arguments used to call the generic method (slist)
#
# The args parameter is used:
# * to be able to make reports when calling the same method with the same class parameter several times
# * to be able to display detailed reports
#
# The class_prefix is used in priority, with a fallback on the old_class_prefix if empty.
#
# @class_prefix
# @class_parameter old_class_prefix

bundle agent _log_v3_mode(mode, message, class_parameter, old_class_prefix, class_prefix, args)
{
methods:
# Report using the appropriate bundle(s)
"wrapper for ${configuration.enabled_loggers}"
usebundle => log_rudder_mode("${mode}", "${message}", "${class_parameter}", "${old_class_prefix}", "${class_prefix}", "@{args}"),
#usebundle => ${configuration.enabled_loggers}("${mode}", "${message}", "${class_parameter}", "${old_class_prefix}", "${class_prefix}", "@{args}"),
comment => "Call the ${method} bundle with arguments ${old_class_prefix}, ${class_prefix}, @{args}";
}

0 comments on commit e451cd5

Please sign in to comment.