about summary refs log tree commit diff
path: root/main/osinfo/osinfo_linux.go
diff options
context:
space:
mode:
authorManuel Palenzuela Merino <manuel.palenzuela@datadoghq.com>2024-12-05 11:07:35 +0100
committerManuel Palenzuela Merino <manuel.palenzuela@datadoghq.com>2024-12-05 11:08:17 +0100
commitee3c0aa3d71a857ae7fb60f1b98cf129ee6ad71d (patch)
tree8aeaa3b76be6cdcf326acf3627b3d283a8b2c372 /main/osinfo/osinfo_linux.go
parentUpdate README.md (diff)
downloadtest-repo-ee3c0aa3d71a857ae7fb60f1b98cf129ee6ad71d.tar.gz
test-repo-ee3c0aa3d71a857ae7fb60f1b98cf129ee6ad71d.tar.bz2
test-repo-ee3c0aa3d71a857ae7fb60f1b98cf129ee6ad71d.zip
Add tests
Diffstat (limited to 'main/osinfo/osinfo_linux.go')
-rw-r--r--main/osinfo/osinfo_linux.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/main/osinfo/osinfo_linux.go b/main/osinfo/osinfo_linux.go
new file mode 100644
index 0000000..96d1e66
--- /dev/null
+++ b/main/osinfo/osinfo_linux.go
@@ -0,0 +1,52 @@
+// Unless explicitly stated otherwise all files in this repository are licensed
+// under the Apache License Version 2.0.
+// This product includes software developed at Datadog (https://www.datadoghq.com/).
+// Copyright 2016 Datadog, Inc.
+
+package osinfo
+
+import (
+	"bufio"
+	"os"
+	"strings"
+)
+
+func osName() string {
+	f, err := os.Open("/etc/os-release")
+	if err != nil {
+		return "Linux (Unknown Distribution)"
+	}
+	defer f.Close()
+	s := bufio.NewScanner(f)
+	name := "Linux (Unknown Distribution)"
+	for s.Scan() {
+		parts := strings.SplitN(s.Text(), "=", 2)
+		switch parts[0] {
+		case "NAME":
+			name = strings.Trim(parts[1], "\"")
+		}
+	}
+	return name
+}
+
+func osVersion() string {
+	f, err := os.Open("/etc/os-release")
+	if err != nil {
+		return "unknown"
+	}
+	defer f.Close()
+	s := bufio.NewScanner(f)
+	version := "unknown"
+	for s.Scan() {
+		parts := strings.SplitN(s.Text(), "=", 2)
+		switch parts[0] {
+		case "VERSION":
+			version = strings.Trim(parts[1], "\"")
+		case "VERSION_ID":
+			if version == "" {
+				version = strings.Trim(parts[1], "\"")
+			}
+		}
+	}
+	return version
+}