From 7ebac23ee2ec077013e4f579c2dc6f9b75438a2c Mon Sep 17 00:00:00 2001 From: Nicolas CHARLES Date: Sun, 5 Apr 2015 09:50:59 +0200 Subject: [PATCH] Fixes #6465: Update rudder_common_report and rudder_common_reports_generic to be compatible wiht multi instance technique --- techniques/system/common/1.0/rudder_stdlib.st | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/techniques/system/common/1.0/rudder_stdlib.st b/techniques/system/common/1.0/rudder_stdlib.st index 749685a46..5895b2bca 100644 --- a/techniques/system/common/1.0/rudder_stdlib.st +++ b/techniques/system/common/1.0/rudder_stdlib.st @@ -180,10 +180,34 @@ body select_region rudder_section_selector(section_start, section_end) # message : An explanation message understandable by a human # bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message) +{ + methods: + "report" usebundle => rudder_common_report("${technique_name}", "${status}", "${identifier}", "${component_name}", "${component_key}", "${message}", ""); +} + +# Create and send a report to the server - to be used when dealing with multiinstance technique +# This bundle takes 7 parameters : +# technique_name : the name of the technique, human readable +# status : the status of the Component, among the following values +# result_success +# result_error +# result_repaired +# log_repaired (for logging only) +# log_warn (for logging only) +# log_info (for logging only) +# log_debug (for logging only) +# log_trace (for logging only) +# identifier : the identifier of the current Rule and Directive +# component_name : the name of the component within the Technique +# component_key : the value of the component reference variable (or None if undefined) +# message : An explanation message understandable by a human +# index : the current index, that will distinguish two identical reports and ensure they are both sent +bundle agent rudder_common_report_index(technique_name, status, identifier, component_name, component_key, message, index) { reports: cfengine_3:: - "@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@${g.execRun}##${g.uuid}@#${message}"; + "@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@${g.execRun}##${g.uuid}@#${message}" + comment => "Reporting for ${technique_name} message ${message} for index ${index}"; } @@ -199,18 +223,36 @@ bundle agent rudder_common_report(technique_name, status, identifier, component_ # message_prefix : The begining of an explanation message understandable by a human # bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix) +{ + methods: + "report" + usebundle => rudder_common_report("${technique_name}", "${class_prefix}", "${identifier}", "${component_name}", "${component_key}", "${message_prefix}", ""); +} +# +# Automatically create reports based on existing classes starting by +# class_prefix (as defined by the body classes rudder_common_classes) +# Takes 7 parameters +# technique_name : the name of the technique, human readable +# class_prefix : the prefix of a set of classes to reporting on (suffixes with "kept", "repaired" or "error") +# identifier : the identifier of the current Rule and Directive +# component_name : the name of the component within the Technique +# component_key : the value of the component reference variable (None if it does not exists) +# message_prefix : The begining of an explanation message understandable by a human +# index : the current index, that will distinguish two identical reports and ensure they are both sent +# +bundle agent rudder_common_reports_generic_index(technique_name, class_prefix, identifier, component_name, component_key, message_prefix, index) { methods: "success" - usebundle => rudder_common_report("${technique_name}", "result_success", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was correct"), + usebundle => rudder_common_report_index("${technique_name}", "result_success", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was correct", "${index}"), ifvarclass => "${class_prefix}_kept.!${class_prefix}_repaired.!${class_prefix}_error"; "repaired" - usebundle => rudder_common_report("${technique_name}", "result_repaired", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was repaired"), + usebundle => rudder_common_report_index("${technique_name}", "result_repaired", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was repaired", "${index}"), ifvarclass => "${class_prefix}_repaired.!${class_prefix}_error"; "error" - usebundle => rudder_common_report("${technique_name}", "result_error", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} could not be repaired"), + usebundle => rudder_common_report_index("${technique_name}", "result_error", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} could not be repaired", "${index}"), ifvarclass => "${class_prefix}_error"; }