|
|
|
@ -9,7 +9,6 @@ import (
|
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
@ -25,23 +24,20 @@ func HostIDWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
|
|
|
|
|
if platform == "SmartOS" {
|
|
|
|
|
// If everything works, use the current zone ID as the HostID if present.
|
|
|
|
|
zonename, err := exec.LookPath("zonename")
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, "zonename")
|
|
|
|
|
if err == nil {
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, zonename)
|
|
|
|
|
if err == nil {
|
|
|
|
|
sc := bufio.NewScanner(bytes.NewReader(out))
|
|
|
|
|
for sc.Scan() {
|
|
|
|
|
line := sc.Text()
|
|
|
|
|
|
|
|
|
|
// If we're in the global zone, rely on the hostname.
|
|
|
|
|
if line == "global" {
|
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
|
if err == nil {
|
|
|
|
|
return hostname, nil
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return strings.TrimSpace(line), nil
|
|
|
|
|
sc := bufio.NewScanner(bytes.NewReader(out))
|
|
|
|
|
for sc.Scan() {
|
|
|
|
|
line := sc.Text()
|
|
|
|
|
|
|
|
|
|
// If we're in the global zone, rely on the hostname.
|
|
|
|
|
if line == "global" {
|
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
|
if err == nil {
|
|
|
|
|
return hostname, nil
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return strings.TrimSpace(line), nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -50,15 +46,12 @@ func HostIDWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
// If HostID is still unknown, use hostid(1), which can lie to callers but at
|
|
|
|
|
// this point there are no hardware facilities available. This behavior
|
|
|
|
|
// matches that of other supported OSes.
|
|
|
|
|
hostID, err := exec.LookPath("hostid")
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, "hostid")
|
|
|
|
|
if err == nil {
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, hostID)
|
|
|
|
|
if err == nil {
|
|
|
|
|
sc := bufio.NewScanner(bytes.NewReader(out))
|
|
|
|
|
for sc.Scan() {
|
|
|
|
|
line := sc.Text()
|
|
|
|
|
return strings.TrimSpace(line), nil
|
|
|
|
|
}
|
|
|
|
|
sc := bufio.NewScanner(bytes.NewReader(out))
|
|
|
|
|
for sc.Scan() {
|
|
|
|
|
line := sc.Text()
|
|
|
|
|
return strings.TrimSpace(line), nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -77,12 +70,7 @@ func numProcs(ctx context.Context) (uint64, error) {
|
|
|
|
|
var kstatMatch = regexp.MustCompile(`([^\s]+)[\s]+([^\s]*)`)
|
|
|
|
|
|
|
|
|
|
func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|
|
|
|
kstat, err := exec.LookPath("kstat")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, kstat, "-p", "unix:0:system_misc:boot_time")
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, "kstat", "-p", "unix:0:system_misc:boot_time")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
@ -108,13 +96,9 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
|
|
|
|
|
ipmitool, err := exec.LookPath("ipmitool")
|
|
|
|
|
var ret []TemperatureStat
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ret, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, ipmitool, "-c", "sdr", "list")
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, "ipmitool", "-c", "sdr", "list")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ret, err
|
|
|
|
|
}
|
|
|
|
@ -185,12 +169,7 @@ func parseReleaseFile() (string, error) {
|
|
|
|
|
|
|
|
|
|
// parseUnameOutput returns platformFamily, kernelVersion and platformVersion
|
|
|
|
|
func parseUnameOutput(ctx context.Context) (string, string, string, error) {
|
|
|
|
|
uname, err := exec.LookPath("uname")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", "", "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, uname, "-srv")
|
|
|
|
|
out, err := invoke.CommandWithContext(ctx, "uname", "-srv")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", "", "", err
|
|
|
|
|
}
|
|
|
|
|