mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-08-27 00:37:20 +00:00
adding host collectors to support bundles
This commit is contained in:
@@ -3,6 +3,7 @@ package analyzer
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -25,7 +26,13 @@ func (a *AnalyzeHostServices) IsExcluded() (bool, error) {
|
||||
func (a *AnalyzeHostServices) Analyze(getCollectedFileContents func(string) ([]byte, error)) ([]*AnalyzeResult, error) {
|
||||
hostAnalyzer := a.hostAnalyzer
|
||||
|
||||
contents, err := getCollectedFileContents(collect.HostServicesPath)
|
||||
collectorName := hostAnalyzer.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "systemctl_services"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
contents, err := getCollectedFileContents(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get collected file")
|
||||
}
|
||||
|
||||
@@ -87,9 +87,11 @@ type CertificateAnalyze struct {
|
||||
}
|
||||
|
||||
type HostServicesAnalyze struct {
|
||||
AnalyzeMeta `json:",inline" yaml:",inline"`
|
||||
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
|
||||
AnalyzeMeta `json:",inline" yaml:",inline"`
|
||||
CollectorName string `json:"collectorName,omitempty" yaml:"collectorName,omitempty"`
|
||||
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
|
||||
}
|
||||
|
||||
type HostOSAnalyze struct {
|
||||
AnalyzeMeta `json:",inline" yaml:",inline"`
|
||||
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
type SupportBundleSpec struct {
|
||||
AfterCollection []*AfterCollection `json:"afterCollection,omitempty" yaml:"afterCollection,omitempty"`
|
||||
Collectors []*Collect `json:"collectors,omitempty" yaml:"collectors,omitempty"`
|
||||
HostCollectors []*HostCollect `json:"hostCollectors,omitempty" yaml:"hostCollectors,omitempty"`
|
||||
Analyzers []*Analyze `json:"analyzers,omitempty" yaml:"analyzers,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -3528,7 +3528,7 @@ func (in *Run) DeepCopy() *Run {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RunPod) DeepCopyInto(out *RunPod) {
|
||||
*out = *in
|
||||
out.CollectorMeta = in.CollectorMeta
|
||||
in.CollectorMeta.DeepCopyInto(&out.CollectorMeta)
|
||||
if in.ImagePullSecret != nil {
|
||||
in, out := &in.ImagePullSecret, &out.ImagePullSecret
|
||||
*out = new(ImagePullSecrets)
|
||||
@@ -3726,6 +3726,17 @@ func (in *SupportBundleSpec) DeepCopyInto(out *SupportBundleSpec) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.HostCollectors != nil {
|
||||
in, out := &in.HostCollectors, &out.HostCollectors
|
||||
*out = make([]*HostCollect, len(*in))
|
||||
for i := range *in {
|
||||
if (*in)[i] != nil {
|
||||
in, out := &(*in)[i], &(*out)[i]
|
||||
*out = new(HostCollect)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.Analyzers != nil {
|
||||
in, out := &in.Analyzers, &out.Analyzers
|
||||
*out = make([]*Analyze, len(*in))
|
||||
|
||||
@@ -56,7 +56,7 @@ func CollectHost(c *troubleshootv1beta2.HostCollector, additionalRedactors *trou
|
||||
|
||||
var collectors []HostCollector
|
||||
for _, desiredCollector := range c.Spec.Collectors {
|
||||
collector, ok := GetHostCollector(desiredCollector)
|
||||
collector, ok := GetHostCollector(desiredCollector, "")
|
||||
if !ok {
|
||||
return nil, ErrHostCollectorNotFound
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
@@ -31,6 +32,7 @@ const lsblkFormat = `NAME=%q KNAME=%q PKNAME=%q TYPE=%q MAJ:MIN="%d:%d" SIZE="%d
|
||||
|
||||
type CollectHostBlockDevices struct {
|
||||
hostCollector *troubleshootv1beta2.HostBlockDevices
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostBlockDevices) Title() string {
|
||||
@@ -83,7 +85,16 @@ func (c *CollectHostBlockDevices) Collect(progressChan chan<- interface{}) (map[
|
||||
return nil, errors.Wrap(err, "failed to marshal block device info")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "block_devices"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/block_devices.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ const KeyPairValid = "key-pair-valid"
|
||||
|
||||
type CollectHostCertificate struct {
|
||||
hostCollector *troubleshootv1beta2.Certificate
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostCertificate) Title() string {
|
||||
@@ -53,14 +54,19 @@ func (c *CollectHostCertificate) Collect(progressChan chan<- interface{}) (map[s
|
||||
}
|
||||
}
|
||||
|
||||
b := []byte(result)
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "certificate"
|
||||
}
|
||||
name := filepath.Join("certificate", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: []byte(result),
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,46 +10,47 @@ type HostCollector interface {
|
||||
Collect(progressChan chan<- interface{}) (map[string][]byte, error)
|
||||
}
|
||||
|
||||
func GetHostCollector(collector *troubleshootv1beta2.HostCollect) (HostCollector, bool) {
|
||||
func GetHostCollector(collector *troubleshootv1beta2.HostCollect, bundlePath string) (HostCollector, bool) {
|
||||
switch {
|
||||
case collector.CPU != nil:
|
||||
return &CollectHostCPU{collector.CPU}, true
|
||||
return &CollectHostCPU{collector.CPU, bundlePath}, true
|
||||
case collector.Memory != nil:
|
||||
return &CollectHostMemory{collector.Memory}, true
|
||||
return &CollectHostMemory{collector.Memory, bundlePath}, true
|
||||
case collector.TCPLoadBalancer != nil:
|
||||
return &CollectHostTCPLoadBalancer{collector.TCPLoadBalancer}, true
|
||||
return &CollectHostTCPLoadBalancer{collector.TCPLoadBalancer, bundlePath}, true
|
||||
case collector.HTTPLoadBalancer != nil:
|
||||
return &CollectHostHTTPLoadBalancer{collector.HTTPLoadBalancer}, true
|
||||
return &CollectHostHTTPLoadBalancer{collector.HTTPLoadBalancer, bundlePath}, true
|
||||
case collector.DiskUsage != nil:
|
||||
return &CollectHostDiskUsage{collector.DiskUsage}, true
|
||||
return &CollectHostDiskUsage{collector.DiskUsage, bundlePath}, true
|
||||
case collector.TCPPortStatus != nil:
|
||||
return &CollectHostTCPPortStatus{collector.TCPPortStatus}, true
|
||||
return &CollectHostTCPPortStatus{collector.TCPPortStatus, bundlePath}, true
|
||||
case collector.HTTP != nil:
|
||||
return &CollectHostHTTP{collector.HTTP}, true
|
||||
return &CollectHostHTTP{collector.HTTP, bundlePath}, true
|
||||
case collector.Time != nil:
|
||||
return &CollectHostTime{collector.Time}, true
|
||||
return &CollectHostTime{collector.Time, bundlePath}, true
|
||||
case collector.BlockDevices != nil:
|
||||
return &CollectHostBlockDevices{collector.BlockDevices}, true
|
||||
return &CollectHostBlockDevices{collector.BlockDevices, bundlePath}, true
|
||||
case collector.SystemPackages != nil:
|
||||
return &CollectHostSystemPackages{collector.SystemPackages}, true
|
||||
return &CollectHostSystemPackages{collector.SystemPackages, bundlePath}, true
|
||||
case collector.KernelModules != nil:
|
||||
return &CollectHostKernelModules{
|
||||
hostCollector: collector.KernelModules,
|
||||
BundlePath: bundlePath,
|
||||
loadable: kernelModulesLoadable{},
|
||||
loaded: kernelModulesLoaded{},
|
||||
}, true
|
||||
case collector.TCPConnect != nil:
|
||||
return &CollectHostTCPConnect{collector.TCPConnect}, true
|
||||
return &CollectHostTCPConnect{collector.TCPConnect, bundlePath}, true
|
||||
case collector.IPV4Interfaces != nil:
|
||||
return &CollectHostIPV4Interfaces{collector.IPV4Interfaces}, true
|
||||
return &CollectHostIPV4Interfaces{collector.IPV4Interfaces, bundlePath}, true
|
||||
case collector.FilesystemPerformance != nil:
|
||||
return &CollectHostFilesystemPerformance{collector.FilesystemPerformance}, true
|
||||
return &CollectHostFilesystemPerformance{collector.FilesystemPerformance, bundlePath}, true
|
||||
case collector.Certificate != nil:
|
||||
return &CollectHostCertificate{collector.Certificate}, true
|
||||
return &CollectHostCertificate{collector.Certificate, bundlePath}, true
|
||||
case collector.HostServices != nil:
|
||||
return &CollectHostServices{collector.HostServices}, true
|
||||
return &CollectHostServices{collector.HostServices, bundlePath}, true
|
||||
case collector.HostOS != nil:
|
||||
return &CollectHostOS{collector.HostOS}, true
|
||||
return &CollectHostOS{collector.HostOS, bundlePath}, true
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
|
||||
+13
-1
@@ -1,7 +1,9 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
@@ -15,6 +17,7 @@ type CPUInfo struct {
|
||||
|
||||
type CollectHostCPU struct {
|
||||
hostCollector *troubleshootv1beta2.CPU
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostCPU) Title() string {
|
||||
@@ -45,7 +48,16 @@ func (c *CollectHostCPU) Collect(progressChan chan<- interface{}) (map[string][]
|
||||
return nil, errors.Wrap(err, "failed to marshal cpu info")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "cpu"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/cpu.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -18,6 +19,7 @@ type DiskUsageInfo struct {
|
||||
|
||||
type CollectHostDiskUsage struct {
|
||||
hostCollector *troubleshootv1beta2.DiskUsage
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostDiskUsage) Title() string {
|
||||
@@ -55,6 +57,15 @@ func (c *CollectHostDiskUsage) Collect(progressChan chan<- interface{}) (map[str
|
||||
key := HostDiskUsageKey(c.hostCollector.CollectorName)
|
||||
result[key] = b
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "disk_usage"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ func init() {
|
||||
|
||||
type CollectHostFilesystemPerformance struct {
|
||||
hostCollector *troubleshootv1beta2.FilesystemPerformance
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostFilesystemPerformance) Title() string {
|
||||
@@ -27,7 +28,7 @@ func (c *CollectHostFilesystemPerformance) IsExcluded() (bool, error) {
|
||||
}
|
||||
|
||||
func (c *CollectHostFilesystemPerformance) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
|
||||
return collectHostFilesystemPerformance(c.hostCollector)
|
||||
return collectHostFilesystemPerformance(c.hostCollector, c.BundlePath)
|
||||
}
|
||||
|
||||
type FSPerfResults struct {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -37,7 +38,7 @@ func (d Durations) Swap(i, j int) {
|
||||
d[i], d[j] = d[j], d[i]
|
||||
}
|
||||
|
||||
func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.FilesystemPerformance) (map[string][]byte, error) {
|
||||
func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.FilesystemPerformance, bundlePath string) (map[string][]byte, error) {
|
||||
timeout := time.Minute
|
||||
if hostCollector.Timeout != "" {
|
||||
d, err := time.ParseDuration(hostCollector.Timeout)
|
||||
@@ -204,6 +205,9 @@ func collectHostFilesystemPerformance(hostCollector *troubleshootv1beta2.Filesys
|
||||
return nil, errors.Wrap(err, "failed to marshal fs perf results")
|
||||
}
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(bundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: b,
|
||||
}, nil
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
|
||||
type CollectHostHTTP struct {
|
||||
hostCollector *troubleshootv1beta2.HostHTTP
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostHTTP) Title() string {
|
||||
@@ -36,17 +38,22 @@ func (c *CollectHostHTTP) Collect(progressChan chan<- interface{}) (map[string][
|
||||
return nil, errors.New("no supported http request type")
|
||||
}
|
||||
|
||||
output, err := responseToOutput(response, err, false)
|
||||
responseOutput, err := responseToOutput(response, err, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileName := "result.json"
|
||||
if httpCollector.CollectorName != "" {
|
||||
fileName = httpCollector.CollectorName + ".json"
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "result"
|
||||
}
|
||||
name := filepath.Join("http", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(responseOutput))
|
||||
|
||||
httpOutput := map[string][]byte{
|
||||
filepath.Join("http", fileName): output,
|
||||
name: responseOutput,
|
||||
}
|
||||
|
||||
return httpOutput, nil
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
type CollectHostHTTPLoadBalancer struct {
|
||||
hostCollector *troubleshootv1beta2.HTTPLoadBalancer
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostHTTPLoadBalancer) Title() string {
|
||||
@@ -120,10 +121,14 @@ func (c *CollectHostHTTPLoadBalancer) Collect(progressChan chan<- interface{}) (
|
||||
return nil, errors.Wrap(err, "failed to marshal result")
|
||||
}
|
||||
|
||||
name := path.Join("httpLoadBalancer", "httpLoadBalancer.json")
|
||||
if c.hostCollector.CollectorName != "" {
|
||||
name = path.Join("httpLoadBalancer", fmt.Sprintf("%s.json", c.hostCollector.CollectorName))
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "httpLoadBalancer"
|
||||
}
|
||||
name := filepath.Join("httpLoadBalancer", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: b,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
@@ -10,6 +12,7 @@ import (
|
||||
|
||||
type CollectHostIPV4Interfaces struct {
|
||||
hostCollector *troubleshootv1beta2.IPV4Interfaces
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostIPV4Interfaces) Title() string {
|
||||
@@ -47,7 +50,16 @@ func (c *CollectHostIPV4Interfaces) Collect(progressChan chan<- interface{}) (ma
|
||||
return nil, errors.Wrap(err, "failed to marshal network interfaces")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "ipv4Interfaces"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/ipv4Interfaces.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ type kernelModuleCollector interface {
|
||||
// from the host.
|
||||
type CollectHostKernelModules struct {
|
||||
hostCollector *troubleshootv1beta2.HostKernelModules
|
||||
BundlePath string
|
||||
loadable kernelModuleCollector
|
||||
loaded kernelModuleCollector
|
||||
}
|
||||
@@ -95,8 +96,17 @@ func (c *CollectHostKernelModules) Collect(progressChan chan<- interface{}) (map
|
||||
return nil, errors.Wrap(err, "failed to marshal kernel modules")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "kernel_modules"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/kernel_modules.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
@@ -14,6 +16,7 @@ type MemoryInfo struct {
|
||||
|
||||
type CollectHostMemory struct {
|
||||
hostCollector *troubleshootv1beta2.Memory
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostMemory) Title() string {
|
||||
@@ -38,7 +41,16 @@ func (c *CollectHostMemory) Collect(progressChan chan<- interface{}) (map[string
|
||||
return nil, errors.Wrap(err, "failed to marshal memory info")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "memory"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/memory.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
@@ -17,6 +19,7 @@ type HostOSInfo struct {
|
||||
|
||||
type CollectHostOS struct {
|
||||
hostCollector *troubleshootv1beta2.HostOS
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostOS) Title() string {
|
||||
@@ -43,7 +46,16 @@ func (c *CollectHostOS) Collect(progressChan chan<- interface{}) (map[string][]b
|
||||
return nil, errors.Wrap(err, "failed to marshal host os info")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "hostos_info"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/hostos_info.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
||||
@@ -19,10 +20,10 @@ type ServiceInfo struct {
|
||||
}
|
||||
|
||||
const systemctlFormat = `%s %s %s %s` // this leaves off the description
|
||||
const HostServicesPath = `system/systemctl_services.json`
|
||||
|
||||
type CollectHostServices struct {
|
||||
hostCollector *troubleshootv1beta2.HostServices
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostServices) Title() string {
|
||||
@@ -63,7 +64,16 @@ func (c *CollectHostServices) Collect(progressChan chan<- interface{}) (map[stri
|
||||
return nil, errors.Wrap(err, "failed to marshal systemctl service info")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "systemctl_services"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
HostServicesPath: b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -28,6 +29,7 @@ type SystemPackage struct {
|
||||
|
||||
type CollectHostSystemPackages struct {
|
||||
hostCollector *troubleshootv1beta2.HostSystemPackages
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostSystemPackages) Title() string {
|
||||
@@ -162,13 +164,17 @@ func (c *CollectHostSystemPackages) Collect(progressChan chan<- interface{}) (ma
|
||||
return nil, errors.Wrap(err, "failed to marshal system packages info")
|
||||
}
|
||||
|
||||
outputFileName := "system/packages.json"
|
||||
if c.hostCollector.CollectorName != "" {
|
||||
outputFileName = fmt.Sprintf("system/%s-packages.json", c.hostCollector.CollectorName)
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "packages"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+"-packages.json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
outputFileName: b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
type CollectHostTCPConnect struct {
|
||||
hostCollector *troubleshootv1beta2.TCPConnect
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostTCPConnect) Title() string {
|
||||
@@ -45,7 +46,14 @@ func (c *CollectHostTCPConnect) Collect(progressChan chan<- interface{}) (map[st
|
||||
return nil, errors.Wrap(err, "failed to marshal result")
|
||||
}
|
||||
|
||||
name := path.Join("connect", fmt.Sprintf("%s.json", c.hostCollector.CollectorName))
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "connect"
|
||||
}
|
||||
name := filepath.Join("connect", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: b,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
type CollectHostTCPLoadBalancer struct {
|
||||
hostCollector *troubleshootv1beta2.TCPLoadBalancer
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostTCPLoadBalancer) Title() string {
|
||||
@@ -26,10 +28,13 @@ func (c *CollectHostTCPLoadBalancer) Collect(progressChan chan<- interface{}) (m
|
||||
listenAddress := fmt.Sprintf("0.0.0.0:%d", c.hostCollector.Port)
|
||||
dialAddress := c.hostCollector.Address
|
||||
|
||||
name := path.Join("tcpLoadBalancer", "tcpLoadBalancer.json")
|
||||
if c.hostCollector.CollectorName != "" {
|
||||
name = path.Join("tcpLoadBalancer", fmt.Sprintf("%s.json", c.hostCollector.CollectorName))
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "tcpLoadBalancer"
|
||||
}
|
||||
name := filepath.Join("tcpLoadBalancer", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
|
||||
timeout := 60 * time.Minute
|
||||
if c.hostCollector.Timeout != "" {
|
||||
@@ -50,6 +55,8 @@ func (c *CollectHostTCPLoadBalancer) Collect(progressChan chan<- interface{}) (m
|
||||
return nil, errors.Wrap(err, "failed to marshal result")
|
||||
}
|
||||
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: b,
|
||||
}, err
|
||||
@@ -63,6 +70,8 @@ func (c *CollectHostTCPLoadBalancer) Collect(progressChan chan<- interface{}) (m
|
||||
return nil, errors.Wrap(err, "failed to marshal result")
|
||||
}
|
||||
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: b,
|
||||
}, nil
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
|
||||
type CollectHostTCPPortStatus struct {
|
||||
hostCollector *troubleshootv1beta2.TCPPortStatus
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostTCPPortStatus) Title() string {
|
||||
@@ -61,10 +63,15 @@ func (c *CollectHostTCPPortStatus) Collect(progressChan chan<- interface{}) (map
|
||||
return nil, errors.Wrap(err, "failed to marshal result")
|
||||
}
|
||||
|
||||
name := path.Join("tcpPortStatus", "tcpPortStatus.json")
|
||||
if c.hostCollector.CollectorName != "" {
|
||||
name = path.Join("tcpPortStatus", fmt.Sprintf("%s.json", c.hostCollector.CollectorName))
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "tcpPortStatus"
|
||||
}
|
||||
name := filepath.Join("tcpPortStatus", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
name: b,
|
||||
}, nil
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/godbus/dbus"
|
||||
@@ -21,6 +23,7 @@ type TimeInfo struct {
|
||||
|
||||
type CollectHostTime struct {
|
||||
hostCollector *troubleshootv1beta2.HostTime
|
||||
BundlePath string
|
||||
}
|
||||
|
||||
func (c *CollectHostTime) Title() string {
|
||||
@@ -90,7 +93,16 @@ func (c *CollectHostTime) Collect(progressChan chan<- interface{}) (map[string][
|
||||
return nil, errors.Wrap(err, "failed to marshal time info")
|
||||
}
|
||||
|
||||
collectorName := c.hostCollector.CollectorName
|
||||
if collectorName == "" {
|
||||
collectorName = "time"
|
||||
}
|
||||
name := filepath.Join("system", collectorName+".json")
|
||||
|
||||
output := NewResult()
|
||||
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
|
||||
|
||||
return map[string][]byte{
|
||||
"system/time.json": b,
|
||||
name: b,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func CollectHost(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (Collec
|
||||
|
||||
var collectors []collect.HostCollector
|
||||
for _, desiredCollector := range collectSpecs {
|
||||
collector, ok := collect.GetHostCollector(desiredCollector)
|
||||
collector, ok := collect.GetHostCollector(desiredCollector, "")
|
||||
if ok {
|
||||
collectors = append(collectors, collector)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,43 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
func runHostCollectors(opts SupportBundleCreateOpts, hostCollectors []*troubleshootv1beta2.HostCollect, bundlePath string) (collect.CollectorResult, error) {
|
||||
collectSpecs := make([]*troubleshootv1beta2.HostCollect, 0, 0)
|
||||
collectSpecs = append(collectSpecs, hostCollectors...)
|
||||
|
||||
allCollectedData := make(map[string][]byte)
|
||||
|
||||
var collectors []collect.HostCollector
|
||||
for _, desiredCollector := range collectSpecs {
|
||||
collector, ok := collect.GetHostCollector(desiredCollector, bundlePath)
|
||||
if ok {
|
||||
collectors = append(collectors, collector)
|
||||
}
|
||||
}
|
||||
|
||||
collectResult := collect.NewResult()
|
||||
|
||||
for _, collector := range collectors {
|
||||
isExcluded, _ := collector.IsExcluded()
|
||||
if isExcluded {
|
||||
continue
|
||||
}
|
||||
|
||||
opts.ProgressChan <- fmt.Sprintf("[%s] Running collector...", collector.Title())
|
||||
result, err := collector.Collect(opts.ProgressChan)
|
||||
if err != nil {
|
||||
opts.ProgressChan <- errors.Errorf("failed to run collector: %s: %v", collector.Title(), err)
|
||||
}
|
||||
for k, v := range result {
|
||||
allCollectedData[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
collectResult = allCollectedData
|
||||
|
||||
return collectResult, nil
|
||||
}
|
||||
|
||||
// TODO (dan): This is VERY similar to the Preflight collect package and should be refactored.
|
||||
func runCollectors(collectors []*troubleshootv1beta2.Collect, additionalRedactors *troubleshootv1beta2.Redactor, bundlePath string, opts SupportBundleCreateOpts) (collect.CollectorResult, error) {
|
||||
|
||||
|
||||
@@ -86,12 +86,21 @@ func CollectSupportBundleFromSpec(spec *troubleshootv1beta2.SupportBundleSpec, a
|
||||
return nil, errors.Wrap(err, "create bundle dir")
|
||||
}
|
||||
|
||||
hostFiles, err := runHostCollectors(opts, spec.HostCollectors, bundlePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to run host collectors")
|
||||
}
|
||||
|
||||
// Run collectors
|
||||
files, err := runCollectors(spec.Collectors, additionalRedactors, bundlePath, opts)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to run collectors")
|
||||
}
|
||||
|
||||
for k, v := range hostFiles {
|
||||
files[k] = v
|
||||
}
|
||||
|
||||
version, err := getVersionFile()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get version file")
|
||||
|
||||
Reference in New Issue
Block a user