Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hostname to device info #1

Merged
merged 1 commit into from
Oct 27, 2023
Merged
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
8 changes: 8 additions & 0 deletions versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package versions
import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"

Expand All @@ -16,6 +17,7 @@ type Versions struct {
SoftwareBuildID string `json:"software_build_id"`

SerialNumber string `json:"serial_number"`
Hostname string `json:"hostname"`
}

func (v *Versions) UserAgent() string {
Expand All @@ -38,6 +40,11 @@ func getSerialNumber() string {
return gjson.GetBytes(data, "SPHardwareDataType.0.serial_number").Str
}

func getHostname() string {
hostname, _ := os.Hostname()
return hostname
}

func Get() Versions {
// Alternative methods:
// Hardware version: `system_profiler SPHardwareDataType | awk '/Model Identifier/ { print $3 }'`
Expand All @@ -59,6 +66,7 @@ func Get() Versions {
SoftwareBuildID: string(outParts[1]),

SerialNumber: getSerialNumber(),
Hostname: getHostname(),
}
}

Expand Down