Skip to content

Commit

Permalink
add linux distribution info to kernel spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ak1t0 committed Sep 2, 2016
1 parent 8d6a9c0 commit 1ce0325
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions spec/linux/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/mackerelio/mackerel-agent/logging"
"github.com/shirou/gopsutil/host"
)

// KernelGenerator XXX
Expand Down Expand Up @@ -42,5 +43,72 @@ func (g *KernelGenerator) Generate() (interface{}, error) {
results[key] = str
}

hostInfo, err := host.Info()
if err != nil {
kernelLogger.Errorf("Failed to get platform information: %s", err)
}

if np := normalizePlatform(hostInfo.Platform); np != "" {
platformInfo := np + " " + hostInfo.PlatformVersion

// when platform version is empty string
platformInfo = strings.TrimSpace(platformInfo)

results["platform"] = platformInfo
}

return results, nil
}

func normalizePlatform(platform string) string {
var normalized string

switch platform {
case "debian":
normalized = "Debian"
case "ubuntu":
normalized = "Ubuntu"
case "linuxmint":
normalized = "Linux Mint"
case "raspbian":
normalized = "Raspbian"
case "fedora":
normalized = "Fedora"
case "oracle":
normalized = "Oracle Linux"
case "centos":
normalized = "CentOS"
case "redhat":
normalized = "Red Hat Enterprise Linux"
case "scientific":
normalized = "Scientific Linux"
case "amazon":
normalized = "Amazon Linux"
case "xenserver":
normalized = "XenServer"
case "cloudlinux":
normalized = "CloudLinux"
case "ibm_powerkvm":
normalized = "IBM PowerKVM"
case "suse":
normalized = "SUSE Linux Enterprise Server"
case "opensuse":
normalized = "openSUSE"
case "gentoo":
normalized = "Gentoo Linux"
case "slackware":
normalized = "Slackware"
case "arch":
normalized = "Arch Linux"
case "exherbo":
normalized = "Exherbo"
case "alpine":
normalized = "Alpine Linux"
case "coreos":
normalized = "CoreOS"
default:
normalized = ""
}

return normalized
}

0 comments on commit 1ce0325

Please sign in to comment.