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

Linux: Check historic machine-id files #44

Merged
merged 4 commits into from
Mar 27, 2019

Conversation

cwurm
Copy link

@cwurm cwurm commented Mar 22, 2019

Historically, the machine-id was not always in /etc/machine-id. On Ubuntu 14.04, it is still in /var/lib/dbus/machine-id. Another possible location is /var/db/dbus/machine-id.

This checks these three locations in order and returns the first ID it finds.

@cwurm cwurm added the review label Mar 22, 2019
@cwurm cwurm requested a review from andrewkroh March 22, 2019 14:01
// These will be searched in order.
machineIDFiles = []string{"/etc/machine-id", "/var/lib/dbus/machine-id", "/var/db/dbus/machine-id"}
)

func MachineID() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding machine-id files to the testdata directory? Then make this unit testable by adding a machineID(rootDir string) that enables a test to point this at a specific directory in testdata. MachineID() would call machineID("/").

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We certainly could. I assume it wouldn't do much more than ioutil.ReadFile() and string(bytes.TrimSpace()) though, so I'm not sure how much testing it actually achieves.

Thanks for merging!

@andrewkroh andrewkroh merged commit ab18537 into elastic:master Mar 27, 2019
@cwurm cwurm deleted the ubuntu1404_host_id branch April 1, 2019 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants