diff --git a/cfbs.json b/cfbs.json index e05a954..a03db16 100644 --- a/cfbs.json +++ b/cfbs.json @@ -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", diff --git a/management/command-dispatcher/main.cf b/management/command-dispatcher/main.cf new file mode 100644 index 0000000..3f96805 --- /dev/null +++ b/management/command-dispatcher/main.cf @@ -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"; +}