Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3089 : add a rudder-stdlib library for rudder's best practises #15

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 98 additions & 0 deletions initial-promises/node-server/common/1.0/rudder_stdlib.cf
@@ -0,0 +1,98 @@
#####################################################################################
# Copyright 2012 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/>.
#
#####################################################################################
#
# Rudder Promise Body and Bundle Library
#
# This library includes standardized bundles and bodies to be used as part of the
# "best practices" in the Techniques writing
#

##################################################
# classes body
##################################################

#
# Automatically defines classes bases on a given prefix
# The classes are defined based on the romises outcome
#
body classes rudder_common_classes(prefix)
{
promise_kept => { "${prefix}_kept" };
promise_repaired => { "${prefix}_repaired" };
repair_failed => { "${prefix}_failed" , "${prefix}_error" };
repair_denied => { "${prefix}_denied" , "${prefix}_error" };
repair_timeout => { "${prefix}_timeout", "${prefix}_error" };
}


################################################
# Reporting bundles
################################################

#
# Create and send a report to the server
# This bundle takes 6 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
#
bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message)
{
reports:
linux|!linux::
"@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@$(g.execRun)##$(g.uuid)@#${message}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a detail, but our convention says use ${} not $(), and g.execRun and g.uuid are therefore not up to date with it.

}


#
# Automatically create reports based on existing classes starting by
# class_prefix (as defined by the body classes rudder_common_classes)
# Takes 6 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
#
bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix)
{
methods:
"success"
usebundle => rudder_common_report(technique_name, "result_success", identifier, component_name, component_key, "${message_prefix} was correct"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that the variables here (technique_name, class_prefix, etc) need to have ${} around them. Same on the 2 below.

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"),
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"),
ifvarclass => "${class_prefix}_error";
}
@@ -0,0 +1,98 @@
#####################################################################################
# Copyright 2012 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/>.
#
#####################################################################################
#
# Rudder Promise Body and Bundle Library
#
# This library includes standardized bundles and bodies to be used as part of the
# "best practices" in the Techniques writing
#

##################################################
# classes body
##################################################

#
# Automatically defines classes bases on a given prefix
# The classes are defined based on the romises outcome
#
body classes rudder_common_classes(prefix)
{
promise_kept => { "${prefix}_kept" };
promise_repaired => { "${prefix}_repaired" };
repair_failed => { "${prefix}_failed" , "${prefix}_error" };
repair_denied => { "${prefix}_denied" , "${prefix}_error" };
repair_timeout => { "${prefix}_timeout", "${prefix}_error" };
}


################################################
# Reporting bundles
################################################

#
# Create and send a report to the server
# This bundle takes 6 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
#
bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message)
{
reports:
linux|!linux::
"@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@$(g.execRun)##$(g.uuid)@#${message}";
}


#
# Automatically create reports based on existing classes starting by
# class_prefix (as defined by the body classes rudder_common_classes)
# Takes 6 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
#
bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix)
{
methods:
"success"
usebundle => rudder_common_report(technique_name, "result_success", identifier, component_name, component_key, "${message_prefix} was correct"),
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"),
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"),
ifvarclass => "${class_prefix}_error";
}
1 change: 1 addition & 0 deletions techniques/system/common/1.0/metadata.xml
Expand Up @@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<TML name="cf-served"/>
<TML name="cfengine_stdlib" />
<TML name="rudder_lib" />
<TML name="rudder_stdlib" />
<TML name="process_matching" />
<TML name="internal_security" />
<TML name="e2s_activation"/>
Expand Down
98 changes: 98 additions & 0 deletions techniques/system/common/1.0/rudder_stdlib.st
@@ -0,0 +1,98 @@
#####################################################################################
# Copyright 2012 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/>.
#
#####################################################################################
#
# Rudder Promise Body and Bundle Library
#
# This library includes standardized bundles and bodies to be used as part of the
# "best practices" in the Techniques writing
#

##################################################
# classes body
##################################################

#
# Automatically defines classes bases on a given prefix
# The classes are defined based on the romises outcome
#
body classes rudder_common_classes(prefix)
{
promise_kept => { "${prefix}_kept" };
promise_repaired => { "${prefix}_repaired" };
repair_failed => { "${prefix}_failed" , "${prefix}_error" };
repair_denied => { "${prefix}_denied" , "${prefix}_error" };
repair_timeout => { "${prefix}_timeout", "${prefix}_error" };
}


################################################
# Reporting bundles
################################################

#
# Create and send a report to the server
# This bundle takes 6 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
#
bundle agent rudder_common_report(technique_name, status, identifier, component_name, component_key, message)
{
reports:
linux|!linux::
"@@${technique_name}@@${status}@@${identifier}@@${component_name}@@${component_key}@@$(g.execRun)##$(g.uuid)@#${message}";
}


#
# Automatically create reports based on existing classes starting by
# class_prefix (as defined by the body classes rudder_common_classes)
# Takes 6 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
#
bundle agent rudder_common_reports_generic(technique_name, class_prefix, identifier, component_name, component_key, message_prefix)
{
methods:
"success"
usebundle => rudder_common_report("${technique_name}", "result_success", "${identifier}", "${component_name}", "${component_key}", "${message_prefix} was correct"),
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"),
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"),
ifvarclass => "${class_prefix}_error";
}