-
Notifications
You must be signed in to change notification settings - Fork 92
/
host_os_info.go
54 lines (43 loc) · 1.44 KB
/
host_os_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package collect
import (
"bytes"
"encoding/json"
"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
osutils "github.com/shirou/gopsutil/v3/host"
)
type HostOSInfo struct {
Name string `json:"name"`
KernelVersion string `json:"kernelVersion"`
PlatformVersion string `json:"platformVersion"`
Platform string `json:"platform"`
}
const HostOSInfoPath = `host-collectors/system/hostos_info.json`
type CollectHostOS struct {
hostCollector *troubleshootv1beta2.HostOS
BundlePath string
}
func (c *CollectHostOS) Title() string {
return hostCollectorTitleOrDefault(c.hostCollector.HostCollectorMeta, "Host OS Info")
}
func (c *CollectHostOS) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}
func (c *CollectHostOS) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
infoStat, err := osutils.Info()
if err != nil {
return nil, errors.Wrap(err, "failed to get os info")
}
hostInfo := HostOSInfo{}
hostInfo.Platform = infoStat.Platform
hostInfo.KernelVersion = infoStat.KernelVersion
hostInfo.Name = infoStat.Hostname
hostInfo.PlatformVersion = infoStat.PlatformVersion
b, err := json.MarshalIndent(hostInfo, "", " ")
if err != nil {
return nil, errors.Wrap(err, "failed to marshal host os info")
}
output := NewResult()
output.SaveResult(c.BundlePath, HostOSInfoPath, bytes.NewBuffer(b))
return output, nil
}