Skip to content

Commit

Permalink
[CM] Fix enroll under Windows (elastic#12799)
Browse files Browse the repository at this point in the history
Enrolling of a Beat to Central Management was failing under Windows
because the Beat tries to create a configuration backup file that has
a colon character in its name, which is not allowed under Windows.

Fixes elastic#12797

(cherry picked from commit 4eb411b)
  • Loading branch information
adriansr committed Jul 9, 2019
1 parent c69f442 commit e3172f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ https://github.com/elastic/beats/compare/v7.2.0...7.2[Check the HEAD diff]

*Affecting all Beats*

- Fix Central Management enroll under Windows {issue}12797[12797] {pull}12799[12799]

*Auditbeat*

*Filebeat*
Expand Down
8 changes: 7 additions & 1 deletion x-pack/libbeat/management/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ func Enroll(

ts := time.Now()

// This timestamp format is a variation of RFC3339 replacing colons with
// slashes so that it can be used as part of a filename in all OSes.
// (Colon is not a valid character for filenames in Windows).
// Also removed the TZ-offset as that can cause a plus sign to be output.
const fsSafeTimestamp = "2006-01-02T15-04-05"

// backup current settings:
backConfigFile := configFile + "." + ts.Format(time.RFC3339) + ".bak"
backConfigFile := configFile + "." + ts.Format(fsSafeTimestamp) + ".bak"
fmt.Println("Saving a copy of current settings to " + backConfigFile)
err = file.SafeFileRotate(backConfigFile, configFile)
if err != nil {
Expand Down

0 comments on commit e3172f7

Please sign in to comment.