Repository: elastic/go-sysinfo
Pull request #146 (2023-01-11 13:44:56)

fix to parse Family fileds in OSInfo struct correctly for openSUSE
In openSUSE Leap and openSUSE Tumbleweed that belong to suse family, the values of Platform filed in OSInfo struct are respectively `opensuse-leap` and `opensuse-tumbleweed`. so we need to add these two values to the specific location of familyMap.
https://github.com/elastic/go-sysinfo/blob/5b961f1632f749b41f9bdc0252476fb8c82b5952/providers/linux/os.go#L52-L68
https://github.com/elastic/go-sysinfo/blob/5b961f1632f749b41f9bdc0252476fb8c82b5952/providers/linux/os.go#L196

elasticmachine: 
## :grey_exclamation: Build Aborted
  
  > The PR is not allowed to run in the CI yet
  


<!-- BUILD BADGES-->
> _the below badges are clickable and redirect to their specific view in the CI or DOCS_
[![Pipeline View](https://img.shields.io/badge/pipeline-pipeline%20-green)](https://beats-ci.elastic.co/blue/organizations/jenkins/Library%2Fgo-sysinfo-mbp%2FPR-146/detail/PR-146/1//pipeline) [![Test View](https://img.shields.io/badge/test-test-green)](https://beats-ci.elastic.co/blue/organizations/jenkins/Library%2Fgo-sysinfo-mbp%2FPR-146/detail/PR-146/1//tests) [![Changes](https://img.shields.io/badge/changes-changes-green)](https://beats-ci.elastic.co/blue/organizations/jenkins/Library%2Fgo-sysinfo-mbp%2FPR-146/detail/PR-146/1//changes) [![Artifacts](https://img.shields.io/badge/artifacts-artifacts-yellow)](https://beats-ci.elastic.co/blue/organizations/jenkins/Library%2Fgo-sysinfo-mbp%2FPR-146/detail/PR-146/1//artifacts)   [![preview](https://img.shields.io/badge/elastic-observability-blue)](https://ci-stats.elastic.co/app/apm/services/beats-ci/transactions/view?rangeFrom=2023-01-11T13:35:09.542Z&rangeTo=2023-01-11T13:55:09.542Z&transactionName=BUILD+Library%2Fgo-sysinfo-mbp%2FPR-%7Bnumber%7D&transactionType=job&latencyAggregationType=avg&traceId=695f0084d522ae621cf25fc00fa83f36&transactionId=5eb8b43aa0a24408)

<!-- BUILD SUMMARY-->
<details><summary>Expand to view the summary</summary>
<p>

#### Build stats




* Start Time: 2023-01-11T13:45:09.542+0000


* Duration: 2 min 12 sec





</p>
</details>

<!-- TEST RESULTS IF ANY-->


<!-- STEPS ERRORS IF ANY -->














### Steps errors [![2](https://img.shields.io/badge/2%20-red)](https://beats-ci.elastic.co/blue/organizations/jenkins/Library%2Fgo-sysinfo-mbp%2FPR-146/detail/PR-146/1//pipeline)
  <details><summary>Expand to view the steps failures</summary>
  <p>


  
  
  
  
##### `Load a resource file from a library`
<ul>
<li>Took 0 min 0 sec . View more details <a href="https://beats-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/Library/pipelines/go-sysinfo-mbp/pipelines/PR-146/runs/1/steps/81/log/?start=0">here</a></li>
<li>Description: <code>approval-list/elastic/go-sysinfo.yml</code></l1>
</ul>
  
  
  
  
##### `Error signal`
<ul>
<li>Took 0 min 0 sec . View more details <a href="https://beats-ci.elastic.co//blue/rest/organizations/jenkins/pipelines/Library/pipelines/go-sysinfo-mbp/pipelines/PR-146/runs/1/steps/89/log/?start=0">here</a></li>
<li>Description: <code>githubApiCall: The REST API call https://api.github.com/orgs/elastic/members/topazus return the message : java.lang.Exception: httpRequest: Failure connecting to the service https://api.github.com/orgs/elastic/members/topazus : httpRequest: Failure connecting to the service https://api.github.com/orgs/elastic/members/topazus : Code: 404Error: {"message":"User does not exist or is not a member of the organization","documentation_url":"https://docs.github.com/rest/reference/orgs#check-organization-membership-for-a-user"}</code></l1>
</ul>
  
  </p>
  </details>




</p>
</details>

<!--COMMENT_GENERATED_WITH_ID_comment.id-->
andrewkroh: /test
topazus: @andrewkroh Thanks for your approval for the test.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4e32864..45d2c69 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
+- Add OS family mappings for `opensuse-leap` and `opensuse-tumbleweed`. [#146](https://github.com/elastic/go-sysinfo/pull/146)
+
 ### Changed
 
 ### Deprecated
diff --git a/providers/linux/os.go b/providers/linux/os.go
index 863234c..fc9f4d1 100644
--- a/providers/linux/os.go
+++ b/providers/linux/os.go
@@ -53,7 +53,7 @@ var familyMap = map[string][]string{
 	"redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "ol",
 		"amzn", "rhel", "almalinux", "openeuler", "rocky"},
 	"debian": {"debian", "ubuntu", "raspbian", "linuxmint"},
-	"suse":   {"suse", "sles", "opensuse"},
+	"suse":   {"suse", "sles", "opensuse", "opensuse-leap", "opensuse-tumbleweed"},
 }
 
 var platformToFamilyMap map[string]string
@@ -155,6 +155,11 @@ func makeOSInfo(osRelease map[string]string) (*types.OSInfo, error) {
 		Codename: osRelease["VERSION_CODENAME"],
 	}
 
+	if os.Version == "" {
+		// Fallback to VERSION_ID if VERSION is empty.
+		os.Version = osRelease["VERSION_ID"]
+	}
+
 	if os.Codename == "" {
 		// Some OSes uses their own CODENAME keys (e.g UBUNTU_CODENAME) or we
 		// can get the DISTRIB_CODENAME value from the lsb-release data.


Test patch:
diff --git a/providers/linux/os_test.go b/providers/linux/os_test.go
index 688ba78..d8d0d9b 100644
--- a/providers/linux/os_test.go
+++ b/providers/linux/os_test.go
@@ -235,6 +235,37 @@ func TestOperatingSystem(t *testing.T) {
 		}, *os)
 		t.Logf("%#v", os)
 	})
+	t.Run("opensuse-leap15.4", func(t *testing.T) {
+		os, err := getOSInfo("testdata/opensuse-leap15.4")
+		if err != nil {
+			t.Fatal(err)
+		}
+		assert.Equal(t, types.OSInfo{
+			Type:     "linux",
+			Family:   "suse",
+			Platform: "opensuse-leap",
+			Name:     "openSUSE Leap",
+			Version:  "15.4",
+			Major:    15,
+			Minor:    4,
+		}, *os)
+		t.Logf("%#v", os)
+	})
+	t.Run("opensuse-tumbleweed", func(t *testing.T) {
+		os, err := getOSInfo("testdata/opensuse-tumbleweed")
+		if err != nil {
+			t.Fatal(err)
+		}
+		assert.Equal(t, types.OSInfo{
+			Type:     "linux",
+			Family:   "suse",
+			Platform: "opensuse-tumbleweed",
+			Name:     "openSUSE Tumbleweed",
+			Version:  "20230108",
+			Major:    20230108,
+		}, *os)
+		t.Logf("%#v", os)
+	})
 	t.Run("oraclelinux7", func(t *testing.T) {
 		os, err := getOSInfo("testdata/oraclelinux7")
 		if err != nil {
diff --git a/providers/linux/testdata/opensuse-leap15.4/etc/os-release b/providers/linux/testdata/opensuse-leap15.4/etc/os-release
new file mode 120000
index 0000000..c4c75b4
--- /dev/null
+++ b/providers/linux/testdata/opensuse-leap15.4/etc/os-release
@@ -0,0 +1,1 @@
+../usr/lib/os-release
\ No newline at end of file
diff --git a/providers/linux/testdata/opensuse-leap15.4/usr/lib/os-release b/providers/linux/testdata/opensuse-leap15.4/usr/lib/os-release
new file mode 100644
index 0000000..fa61b75
--- /dev/null
+++ b/providers/linux/testdata/opensuse-leap15.4/usr/lib/os-release
@@ -0,0 +1,12 @@
+NAME="openSUSE Leap"
+VERSION="15.4"
+ID="opensuse-leap"
+ID_LIKE="suse opensuse"
+VERSION_ID="15.4"
+PRETTY_NAME="openSUSE Leap 15.4"
+ANSI_COLOR="0;32"
+CPE_NAME="cpe:/o:opensuse:leap:15.4"
+BUG_REPORT_URL="https://bugs.opensuse.org"
+HOME_URL="https://www.opensuse.org/"
+DOCUMENTATION_URL="https://en.opensuse.org/Portal:Leap"
+LOGO="distributor-logo-Leap"
diff --git a/providers/linux/testdata/opensuse-tumbleweed/etc/os-release b/providers/linux/testdata/opensuse-tumbleweed/etc/os-release
new file mode 120000
index 0000000..c4c75b4
--- /dev/null
+++ b/providers/linux/testdata/opensuse-tumbleweed/etc/os-release
@@ -0,0 +1,1 @@
+../usr/lib/os-release
\ No newline at end of file
diff --git a/providers/linux/testdata/opensuse-tumbleweed/usr/lib/os-release b/providers/linux/testdata/opensuse-tumbleweed/usr/lib/os-release
new file mode 100644
index 0000000..0349bb9
--- /dev/null
+++ b/providers/linux/testdata/opensuse-tumbleweed/usr/lib/os-release
@@ -0,0 +1,12 @@
+NAME="openSUSE Tumbleweed"
+# VERSION="20230108"
+ID="opensuse-tumbleweed"
+ID_LIKE="opensuse suse"
+VERSION_ID="20230108"
+PRETTY_NAME="openSUSE Tumbleweed"
+ANSI_COLOR="0;32"
+CPE_NAME="cpe:/o:opensuse:tumbleweed:20230108"
+BUG_REPORT_URL="https://bugs.opensuse.org"
+HOME_URL="https://www.opensuse.org/"
+DOCUMENTATION_URL="https://en.opensuse.org/Portal:Tumbleweed"
+LOGO="distributor-logo-Tumbleweed"