Skip to content

Commit

Permalink
Fixes #15783: Make class_prefix unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdall committed Sep 24, 2019
1 parent 27ca237 commit 63acd97
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 72 deletions.
23 changes: 15 additions & 8 deletions tree/20_cfe_basics/ncf_lib.cf
Expand Up @@ -1173,7 +1173,7 @@ bundle agent ncf_services(service, action)
"canonified_action" string => canonify("${action}");
"canonified_action_command" string => canonify("${action_command}");

"class_prefix" string => "ncf_services_${canonified_service}_${canonified_action}";
"class_prefix" string => "${report_data.canonified_directive_id}_ncf_services_${canonified_service}_${canonified_action}";

defaults:
# status is an alias to is-active (in systemd, it is not the same thing the only difference is the output, which is not kept anyway)
Expand Down Expand Up @@ -1209,7 +1209,8 @@ bundle agent ncf_services(service, action)

# Due to lack of integration between upstart and init scripts, we have to make different cases.
"is_upstart_service" not => returnszero("/sbin/initctl status ${service} 2>&1 | ${paths.path[grep]} -E 'Unknown job|Unable to connect to Upstart' > /dev/null", "useshell"),
ifvarclass => "ubuntu.initctl_utility_present";
ifvarclass => "ubuntu.initctl_utility_present",
comment => "${report_data.directive_id}";

# Due to compatibility issues when mixing init.d/service and systemctl calls, we use the init script when present
"is_init_service" expression => fileexists("/etc/init.d/${service}");
Expand All @@ -1221,7 +1222,8 @@ bundle agent ncf_services(service, action)
# Actual command - for checks on non-windows systems
#####
pass1.is_check_action.!windows.!is_process_action.method_found.!(slackware.is_boot_action)::
"action_ok" expression => returnszero("${action_command} 2>&1 > /dev/null", "useshell");
"action_ok" expression => returnszero("${action_command} 2>&1 > /dev/null", "useshell"),
comment => "${report_data.directive_id}";

any::
"pass3" expression => "pass2";
Expand Down Expand Up @@ -1252,7 +1254,8 @@ bundle agent ncf_services(service, action)
ifvarclass => "${class_prefix}_checked_ok";
# Slackware boot actions
pass2.slackware.is_boot_action::
"action" usebundle => slackware_boot_services("${service}", "${action}", "${class_prefix}");
"action" usebundle => slackware_boot_services("${service}", "${action}", "${class_prefix}"),
comment => "${report_data.directive_id}";
processes:

###########################################################################
Expand All @@ -1279,17 +1282,20 @@ bundle agent ncf_services(service, action)
windows.is_valid_action.!is_restart_action::
"${service}"
service_policy => "${action}",
classes => classes_generic("${class_prefix}");
classes => classes_generic("${class_prefix}"),
comment => "${report_data.directive_id}";

windows.is_restart_action::
"${service}"
service_policy => "stop",
classes => classes_generic("${class_prefix}_stop_service");
classes => classes_generic("${class_prefix}_stop_service"),
comment => "${report_data.directive_id}";

"${service}"
service_policy => "start",
classes => classes_generic("${class_prefix}"),
ifvarclass => "${class_prefix}_stop_service_ok";
ifvarclass => "${class_prefix}_stop_service_ok",
comment => "${report_data.directive_id}";

commands:
#####
Expand All @@ -1302,7 +1308,8 @@ bundle agent ncf_services(service, action)
pass2.!is_check_action.!windows.!is_process_action.method_found.!(slackware.is_boot_action)::
"${action_command}"
contain => in_shell_and_silent,
classes => classes_generic("${class_prefix}");
classes => classes_generic("${class_prefix}"),
comment => "${report_data.directive_id}";

reports:

Expand Down
14 changes: 8 additions & 6 deletions tree/30_generic_methods/command_execution.cf
Expand Up @@ -21,27 +21,29 @@
# @action
#
# @parameter command_name Command name
#
#
# @class_prefix command_execution
# @class_parameter command_name

bundle agent command_execution(command_name)
{
vars:
"old_class_prefix" string => canonify("command_execution_${command_name}");
"old_class_prefix" string => canonify("${report_data.canonified_directive_id}_command_execution_${command_name}");
"args" slist => { "${command_name}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("command_execution_${report_param}");
"full_class_prefix" string => canonify("${report_data.canonified_directive_id}_command_execution_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

methods:
"report"
usebundle => _log_v3("Execute the command ${command_name}", "${command_name}", "${old_class_prefix}", "${class_prefix}", @{args}),
ifvarclass => "${old_class_prefix}_reached|${class_prefix}_reached";
ifvarclass => "${old_class_prefix}_reached|${class_prefix}_reached",
comment => "${report_data.directive_id}";

commands:
"${command_name}"
contain => in_shell,
classes => classes_generic_two("${old_class_prefix}", "${class_prefix}");
contain => in_shell,
classes => classes_generic_two("${old_class_prefix}", "${class_prefix}"),
comment => "${report_data.directive_id}";

}
10 changes: 6 additions & 4 deletions tree/30_generic_methods/command_execution_result.cf
Expand Up @@ -34,10 +34,10 @@
bundle agent command_execution_result(command, kept_codes, repaired_codes)
{
vars:
"old_class_prefix" string => canonify("command_execution_result_${command}");
"old_class_prefix" string => canonify("${report_data.canonified_directive_id}_command_execution_result_${command}");
"args" slist => { "${command}", "${kept_codes}", "${repaired_codes}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("command_execution_result_${report_param}");
"full_class_prefix" string => canonify("${report_data.canonified_directive_id}_command_execution_result_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

"kept_list" slist => splitstring("${kept_codes}", "\s*,\s*", "256");
Expand All @@ -46,10 +46,12 @@ bundle agent command_execution_result(command, kept_codes, repaired_codes)
methods:
"report"
usebundle => _log_v3("Execute the command ${command}", "${command}", "${old_class_prefix}", "${class_prefix}", @{args}),
ifvarclass => "${old_class_prefix}_reached|${class_prefix}_reached";
ifvarclass => "${old_class_prefix}_reached|${class_prefix}_reached",
comment => "${report_data.directive_id}";

commands:
"${command}"
contain => in_shell,
classes => classes_generic_return_code_list_two("${old_class_prefix}", "${class_prefix}", @{kept_list}, @{repaired_list});
classes => classes_generic_return_code_list_two("${old_class_prefix}", "${class_prefix}", @{kept_list}, @{repaired_list}),
comment => "${report_data.directive_id}";
}
14 changes: 8 additions & 6 deletions tree/30_generic_methods/service_action.cf
Expand Up @@ -78,7 +78,7 @@
#
# @parameter service_name Name of the service
# @parameter action Action to trigger on the service (start, stop, restart, reload, ...)
#
#
# @class_prefix service_action
# @class_parameter service_name

Expand All @@ -89,14 +89,14 @@ bundle agent service_action(service_name, action)
"canonified_service_name" string => canonify("${service_name}");
"canonified_action" string => canonify("${action}");

"old_class_prefix" string => "service_action_${canonified_service_name}";
"old_class_prefix" string => "${report_data.canonified_directive_id}_service_action_${canonified_service_name}";

"args" slist => { "${service_name}", "${action}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("service_action_${report_param}");
"full_class_prefix" string => canonify("${report_data.canonified_directive_id}_service_action_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

"full_inner_class_prefix" string => canonify("ncf_services_${report_param}");
"full_inner_class_prefix" string => canonify("${report_data.canonified_directive_id}_ncf_services_${report_param}");
"inner_class_prefix" string => string_head("${full_inner_class_prefix}", "1000");


Expand All @@ -107,7 +107,8 @@ bundle agent service_action(service_name, action)
"disable_reporting_${class_prefix}"
usebundle => disable_reporting;

"action" usebundle => ncf_services("${service_name}", "${action}");
"action" usebundle => ncf_services("${service_name}", "${action}"),
comment => "${report_data.directive_id}";

"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
Expand All @@ -117,5 +118,6 @@ bundle agent service_action(service_name, action)
"new result classes" usebundle => _classes_copy("${inner_class_prefix}", "${class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";

"report" usebundle => _log_v3("Run action ${action} on service ${service_name}", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args});
"report" usebundle => _log_v3("Run action ${action} on service ${service_name}", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args}),
comment => "${report_data.directive_id}";
}
14 changes: 8 additions & 6 deletions tree/30_generic_methods/service_check_disabled_at_boot.cf
Expand Up @@ -20,7 +20,7 @@
# @description Check if a service is set to not start at boot using the appropriate method
#
# @parameter service_name Service name (as recognized by systemd, init.d, etc...)
#
#
# @class_prefix service_check_disabled_at_boot
# @class_parameter service_name
# This bundle will define a condition service_check_disabled_at_boot_${service_name}_{kept,ok,not_ok,failed,reached}
Expand All @@ -37,7 +37,7 @@ bundle agent service_check_disabled_at_boot(service_name)
"full_class_prefix" string => canonify("service_check_disabled_at_boot_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

"full_inner_class_prefix" string => canonify("ncf_services_${report_param}_is_enabled");
"full_inner_class_prefix" string => canonify("${report_data.canonified_directive_id}_ncf_services_${report_param}_is_enabled");
"inner_class_prefix" string => string_head("${full_inner_class_prefix}", "1000");


Expand All @@ -48,21 +48,23 @@ bundle agent service_check_disabled_at_boot(service_name)
methods:
"disable_reporting_${class_prefix}"
usebundle => disable_reporting;
"check_enabled" usebundle => ncf_services("${service_name}", "is-enabled");
"check_enabled" usebundle => ncf_services("${service_name}", "is-enabled"),
comment => "${report_data.directive_id}";

"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
ifvarclass => "should_report";
"success" usebundle => _classes_success("${old_class_prefix}"),
ifvarclass => "ncf_services_${canonified_service_name}_is_enabled_not_ok";
ifvarclass => "${report_data.canonified_directive_id}_ncf_services_${canonified_service_name}_is_enabled_not_ok";
"success" usebundle => _classes_success("${class_prefix}"),
ifvarclass => "${inner_class_prefix}_not_ok";

"failure" usebundle => _classes_failure("${old_class_prefix}"),
ifvarclass => "ncf_services_${canonified_service_name}_is_enabled_ok";
ifvarclass => "${report_data.canonified_directive_id}_ncf_services_${canonified_service_name}_is_enabled_ok";
"failure" usebundle => _classes_failure("${class_prefix}"),
ifvarclass => "${inner_class_prefix}_ok";

"reports" usebundle => _log_v3("Check if service ${service_name} is disabled at boot", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args});
"reports" usebundle => _log_v3("Check if service ${service_name} is disabled at boot", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args}),
comment => "${report_data.directive_id}";

}
14 changes: 8 additions & 6 deletions tree/30_generic_methods/service_check_running.cf
Expand Up @@ -20,7 +20,7 @@
# @description Check if a service is running using the appropriate method
#
# @parameter service_name Process name
#
#
# @class_prefix service_check_running
# @class_parameter service_name

Expand All @@ -36,7 +36,7 @@ bundle agent service_check_running(service_name)
"full_class_prefix" string => canonify("service_check_running_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

"full_inner_class_prefix" string => canonify("ncf_services_${report_param}_is_active");
"full_inner_class_prefix" string => canonify("${report_data.canonified_directive_id}_ncf_services_${report_param}_is_active");
"inner_class_prefix" string => string_head("${full_inner_class_prefix}", "1000");


Expand All @@ -47,15 +47,17 @@ bundle agent service_check_running(service_name)
methods:
"disable_reporting_${class_prefix}"
usebundle => disable_reporting;
"check_active" usebundle => ncf_services("${service_name}", "is-active");
"check_active" usebundle => ncf_services("${service_name}", "is-active"),
comment => "${report_data.directive_id}";

"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
ifvarclass => "should_report";
"class copy" usebundle => _classes_copy("ncf_services_${canonified_service_name}_is_active", "${old_class_prefix}"),
ifvarclass => "ncf_services_${canonified_service_name}_is_active_reached";
"class copy" usebundle => _classes_copy("${inner_class_prefix}", "${old_class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";
"new result classes" usebundle => _classes_copy("${inner_class_prefix}", "${class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";

"report" usebundle => _log_v3("Check if the service ${service_name} is started", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args});
"report" usebundle => _log_v3("Check if the service ${service_name} is started", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args}),
comment => "${report_data.directive_id}";
}
14 changes: 8 additions & 6 deletions tree/30_generic_methods/service_check_running_ps.cf
Expand Up @@ -20,7 +20,7 @@
# @description Check if a service is running using ps
#
# @parameter service_regex Regular expression used to select a process in ps output
#
#
# @class_prefix service_check_running
# @class_parameter service_regex

Expand All @@ -36,7 +36,7 @@ bundle agent service_check_running_ps(service_regex)
"full_class_prefix" string => canonify("service_check_running_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

"full_inner_class_prefix" string => canonify("ncf_services_${report_param}_is_active_process");
"full_inner_class_prefix" string => canonify("${report_data.directive_id}_ncf_services_${report_param}_is_active_process");
"inner_class_prefix" string => string_head("${full_inner_class_prefix}", "1000");


Expand All @@ -48,17 +48,19 @@ bundle agent service_check_running_ps(service_regex)
methods:
"disable_reporting_${class_prefix}"
usebundle => disable_reporting;
"check_active" usebundle => ncf_services("${service_regex}", "is-active-process");
"check_active" usebundle => ncf_services("${service_regex}", "is-active-process"),
comment => "${report_data.directive_id}";

"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
ifvarclass => "should_report";
"class copy" usebundle => _classes_copy("ncf_services_${canonified_service_regex}_is_active_process", "${old_class_prefix}"),
ifvarclass => "ncf_services_${canonified_service_regex}_is_active_process_reached";
"class copy" usebundle => _classes_copy("${inner_class_prefix}", "${old_class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";
"new result classes" usebundle => _classes_copy("${inner_class_prefix}", "${class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";

"report"
usebundle => _log_v3("Check if the service ${service_regex} is started using ps", "${service_regex}", "${old_class_prefix}", "${class_prefix}", @{args});
usebundle => _log_v3("Check if the service ${service_regex} is started using ps", "${service_regex}", "${old_class_prefix}", "${class_prefix}", @{args}),
comment => "${report_data.directive_id}";

}
12 changes: 7 additions & 5 deletions tree/30_generic_methods/service_check_started_at_boot.cf
Expand Up @@ -37,7 +37,7 @@ bundle agent service_check_started_at_boot(service_name)
"full_class_prefix" string => canonify("service_check_started_at_boot_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");

"full_inner_class_prefix" string => canonify("ncf_services_${report_param}_is_enabled");
"full_inner_class_prefix" string => canonify("${report_data.canonified_directive_id}_ncf_services_${report_param}_is_enabled");
"inner_class_prefix" string => string_head("${full_inner_class_prefix}", "1000");


Expand All @@ -48,15 +48,17 @@ bundle agent service_check_started_at_boot(service_name)
methods:
"disable_reporting_${class_prefix}"
usebundle => disable_reporting;
"check_enabled" usebundle => ncf_services("${service_name}", "is-enabled");
"check_enabled" usebundle => ncf_services("${service_name}", "is-enabled"),
comment => "${report_data.directive_id}";

"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
ifvarclass => "should_report";
"class copy" usebundle => _classes_copy("ncf_services_${canonified_service_name}_is_enabled", "${old_class_prefix}"),
ifvarclass => "ncf_services_${canonified_service_name}_is_enabled_reached";
"class copy" usebundle => _classes_copy("${inner_class_prefix}", "${old_class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";
"new result classes" usebundle => _classes_copy("${inner_class_prefix}", "${class_prefix}"),
ifvarclass => "${inner_class_prefix}_reached";

"reports" usebundle => _log_v3("Check if service ${service_name} is started at boot", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args});
"reports" usebundle => _log_v3("Check if service ${service_name} is started at boot", "${service_name}", "${old_class_prefix}", "${class_prefix}", @{args}),
comment => "${report_data.directive_id};
}

0 comments on commit 63acd97

Please sign in to comment.