in internal/guestcollector/linux_guestcollector.go [443:538]
func (c *LinuxCollector) CollectGuestRules(ctx context.Context, timeout time.Duration) internal.Details {
details := internal.Details{
Name: "OS",
}
fields := map[string]string{}
if !c.remote {
ctxWithTimeout, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
ch := make(chan bool, 1)
go func() {
DiskToDiskType(fields, c.disks, c.usageMetricsLogger)
ch <- true
}()
select {
case <-ctxWithTimeout.Done():
log.Logger.Errorf("DiskToDiskType() for local linux disktype timeout")
c.usageMetricsLogger.Error(agentstatus.MappingLocalLinuxDiskTypeTimeout)
case <-ch:
}
} else {
if c.remoteRunner == nil {
fields[internal.LocalSSDRule] = "unknown"
details.Fields = append(details.Fields, fields)
log.Logger.Debugw("Remoterunner is nil. Remote collection attempted when ssh keys aren't set up correctly. Check customer support documentation.")
return details
}
defer func() {
log.Logger.Debug("Closing the remote runner client")
if err := c.remoteRunner.Close(); err != nil {
log.Logger.Errorw("Failed to close the client in remote runner", "error", err)
}
}()
}
for _, rule := range CollectionOSFields() {
exe := c.guestRuleCommandMap[rule]
func() {
ctxWithTimeout, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
ch := make(chan bool, 1)
go func() {
if c.remote {
res, err := exe.runRemoteCommand(ctx, exe.command, c.remoteRunner)
if err != nil {
if strings.Contains(err.Error(), "Check help docs") {
log.Logger.Warnw("Failed to run remote command. Install command on linux vm to collect more data", "command", exe.command, "error", err)
} else {
log.Logger.Errorw("Failed to run remote command", "command", exe.command, "error", err)
c.usageMetricsLogger.Error(agentstatus.RemoteCommandExecutionError)
}
fields[rule] = "unknown"
ch <- false
return
} else if res == "null" {
fields[rule] = "unknown"
ch <- false
return
}
fields[rule] = res
} else if exe.isRule { // local calls are only made if isrule is true
res, err := exe.runCommand(ctx, exe.command)
if err != nil {
if strings.Contains(err.Error(), "Check help docs") {
log.Logger.Warnw("Failed to run remote command. Install command on linux vm to collect more data", "command", exe.command, "error", err)
} else {
log.Logger.Errorw("Failed to run command", "command", exe.command, "error", err)
c.usageMetricsLogger.Error(agentstatus.CommandExecutionError)
}
fields[rule] = "unknown"
ch <- false
return
} else if res == "null" {
fields[rule] = "unknown"
ch <- false
return
}
fields[rule] = res
}
ch <- true
}()
select {
case <-ctxWithTimeout.Done():
log.Logger.Errorf("Running linux guest rule %s timeout", rule)
c.usageMetricsLogger.Error(agentstatus.LinuxGuestCollectionTimeout)
case <-ch:
}
}()
}
details.Fields = append(details.Fields, fields)
return details
}