Skip to content

Commit

Permalink
fixup! fixup! Fixes #23347: Improve variable_string_from_command by u…
Browse files Browse the repository at this point in the history
…sing execresult_as_data

Fixes #23347: Improve variable_string_from_command by using execresult_as_data
  • Loading branch information
amousset committed Aug 31, 2023
1 parent 3475cad commit 5a9c9b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bundle agent check
"var_name[${init.indices}]" string => "${init.var_prefix[${init.indices}]}.${init.var_name[${init.indices}]}";

classes:
# On error there var must not be created
# On error the var must not be created
"must_not_be_defined_${init.indices}" expression => strcmp("${init.expected_value[${init.indices}]}", "");
"error_${init.indices}_not_ok" expression => isvariable("${var_name[${init.indices}]}"),
ifvarclass => "must_not_be_defined_${init.indices}";
Expand Down
7 changes: 4 additions & 3 deletions tree/30_generic_methods/variable_string_from_command.cf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ bundle agent variable_string_from_command(prefix, name, command)
"class_prefix" string => string_head("${full_class_prefix}", "1000");

# only capture stdout for compatibility with previous implementation
"result" data => execresult_as_data("${command}", "useshell", "stdout");
# add a comment to allow executing the exact same command without hitting
# https://northerntech.atlassian.net/browse/CFE-4244
"result" data => execresult_as_data("${command} # as_data", "useshell", "stdout");

returned_zero::
"${prefix}.${name}" string => "${result[output]}";
Expand All @@ -64,7 +66,6 @@ bundle agent variable_string_from_command(prefix, name, command)
"pass1" expression => "any";

methods:

pass3.!variable_defined::
"error" usebundle => _classes_failure("${old_class_prefix}");
"error" usebundle => _classes_failure("${class_prefix}");
Expand All @@ -81,5 +82,5 @@ bundle agent variable_string_from_command(prefix, name, command)
pass3.info.returned_zero::
"The '${command}' command returned '${${prefix}.${name}}'";
pass3.info.!returned_zero::
"The '${command}' command failed with ${code} code";
"The '${command}' command failed with ${result[exit_code]} code";
}

0 comments on commit 5a9c9b1

Please sign in to comment.