Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cfbs.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,48 @@
"subdirectory": "reporting/client-initiated-reporting",
"steps": ["json def.json def.json"]
},
"command-dispatcher": {
"description": "Command dispatcher for running shell commands on schedule",
"subdirectory": "management/command-dispatcher",
"steps": [
"copy main.cf services/cfbs/modules/command-dispatcher/main.cf",
"policy_files services/cfbs/command-dispatcher/main.cf",
"bundles command_dispatcher:main",
"input ./input.json def.json"
],
"input": [
{
"type": "list",
"variable": "commands_to_run",
"namespace": "command_dispatcher",
"bundle": "main",
"label": "Command",
"subtype": [
{
"key": "command",
"type": "string",
"label": "Command",
"question": "Command to run"
},
{
"key": "condition",
"type": "string",
"label": "Condition",
"question": "Condition for when to run",
"default": "any"
},
{
"key": "ifelapsed",
"type": "string",
"label": "ifelapsed",
"question": "Number of minutes between promise assessments",
"default": "5"
}
],
"while": "Do you want to specify more commands to be run?"
}
]
},
"conditional-installer": {
"description": "Allows you to specify packages you want installed and conditions for where you want them installed, as well as a list of packages you generally want uninstalled.",
"subdirectory": "security/conditional-installer",
Expand Down
65 changes: 65 additions & 0 deletions management/command-dispatcher/main.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
body file control
{
namespace => "command_dispatcher";
}
bundle agent main
{
classes:
"enabled"
expression => isvariable("commands_to_run");
"run_$(i)"
expression => "$(_condition[$(i)])";

vars:
enabled::
"i"
slist => getindices(commands_to_run);

"_command[$(i)]"
string => "$(commands_to_run[$(i)][command])",
if => isvariable("commands_to_run[$(i)][command]");

"_condition[$(i)]"
string => ifelse(
not(strcmp("$(commands_to_run[$(i)][condition])", "")),
"$(commands_to_run[$(i)][condition])",
"any");

"_ifelapsed[$(i)]"
string => ifelse(
not(strcmp("$(commands_to_run[$(i)][ifelapsed])", "")),
"$(commands_to_run[$(i)][ifelapsed])",
"5");

reports:
enabled::
"Command [$(i)]: $(_command[$(i)]), condition: $(_condition[$(i)]), ifelapsed: $(_ifelapsed[$(i)])";
!enabled::
"Command-dispatcher: commands_to_run variable not found";

commands:
enabled::
"$(_command[$(i)])"
if => "run_$(i)",
action => ifelapsed("$(_ifelapsed[$(i)])"),
contain => in_shell;
}
body contain in_shell
{
useshell => "true";
exec_owner => "root";
exec_timeout => "300";
}
body action ifelapsed(x)
{
ifelapsed => "$(x)";
}
body file control
{
namespace => "default";
}
bundle agent __main__
{
methods:
"command_dispatcher:main";
}