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
25 changes: 25 additions & 0 deletions internal/workflow/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions internal/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down