diff --git a/internal/workflow/collection.go b/internal/workflow/collection.go index 82983d65..245a5925 100644 --- a/internal/workflow/collection.go +++ b/internal/workflow/collection.go @@ -110,6 +110,9 @@ func outputsFromTargets(cmd *cobra.Command, myTargets []target.Target, tables [] // isTableForTarget checks if the given table is applicable for the specified target func isTableForTarget(tbl table.TableDefinition, t target.Target, localTempDir string) bool { + if allTableScriptsRequireSuperuser(tbl) && !t.CanElevatePrivileges() { + return false + } if len(tbl.Architectures) > 0 { architecture, err := t.GetArchitecture() if err != nil { @@ -158,6 +161,28 @@ func elevatedPrivilegesRequired(tables []table.TableDefinition) bool { return false } +// allTableScriptsRequireSuperuser checks if all scripts in the table require superuser privileges +func allTableScriptsRequireSuperuser(tbl table.TableDefinition) bool { + for _, scriptName := range tbl.ScriptNames { + script := script.GetScriptByName(scriptName) + if !script.Superuser { + return false + } + } + return true +} + +// numTablesForTarget returns the number of tables applicable for the specified target +func numTablesForTarget(tables []table.TableDefinition, t target.Target, localTempDir string) int { + count := 0 + for _, tbl := range tables { + if isTableForTarget(tbl, t, localTempDir) { + count++ + } + } + return count +} + // collectOnTarget runs the scripts on the target and sends the results to the appropriate channels func collectOnTarget(myTarget target.Target, scriptsToRun []script.ScriptDefinition, localTempDir string, duration string, ctrlCToStop bool, channelTargetScriptOutputs chan TargetScriptOutputs, channelError chan error, statusUpdate progress.MultiSpinnerUpdateFunc) { // run the scripts on the target diff --git a/internal/workflow/workflow.go b/internal/workflow/workflow.go index eef4f5ed..56926701 100644 --- a/internal/workflow/workflow.go +++ b/internal/workflow/workflow.go @@ -133,6 +133,17 @@ func (rc *ReportingCommand) Run() error { for i := len(indicesToRemove) - 1; i >= 0; i-- { myTargets = slices.Delete(myTargets, indicesToRemove[i], indicesToRemove[i]+1) } + // remove targets if no tables to collect + indicesToRemove = []int{} + for i, target := range myTargets { + if numTablesForTarget(rc.Tables, target, localTempDir) == 0 { + _ = multiSpinner.Status(target.GetName(), "No collectable data on this target, skipping") + indicesToRemove = append(indicesToRemove, i) + } + } + for i := len(indicesToRemove) - 1; i >= 0; i-- { + myTargets = slices.Delete(myTargets, indicesToRemove[i], indicesToRemove[i]+1) + } // set up signal handler to help with cleaning up child processes on ctrl-c/SIGINT or SIGTERM configureSignalHandler(myTargets, multiSpinner.Status) // collect data from targets