-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grab launcher windows events in flare (#1588)
- Loading branch information
1 parent
d647dfb
commit d5f4fb4
Showing
6 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package checkups | ||
|
||
import ( | ||
"archive/zip" | ||
"context" | ||
"io" | ||
) | ||
|
||
type InitLogs struct { | ||
status Status | ||
summary string | ||
} | ||
|
||
func (c *InitLogs) Name() string { | ||
return "Init Logs" | ||
} | ||
|
||
func (c *InitLogs) Run(ctx context.Context, fullFH io.Writer) error { | ||
c.status = Passing | ||
|
||
// if were discarding, just return | ||
if fullFH == io.Discard { | ||
return nil | ||
} | ||
|
||
logZip := zip.NewWriter(fullFH) | ||
defer logZip.Close() | ||
|
||
return writeInitLogs(ctx, logZip) | ||
} | ||
|
||
func (c *InitLogs) Status() Status { | ||
return c.status | ||
} | ||
|
||
func (c *InitLogs) Summary() string { | ||
return c.summary | ||
} | ||
|
||
func (c *InitLogs) ExtraFileName() string { | ||
return "init_logs.zip" | ||
} | ||
|
||
func (c *InitLogs) Data() any { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package checkups | ||
|
||
import ( | ||
"archive/zip" | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func writeInitLogs(_ context.Context, logZip *zip.Writer) error { | ||
stdMatches, err := filepath.Glob("/var/log/kolide-k2/*") | ||
if err != nil { | ||
return fmt.Errorf("globbing /var/log/kolide-k2/*: %w", err) | ||
} | ||
|
||
var lastErr error | ||
for _, f := range stdMatches { | ||
out, err := logZip.Create(filepath.Base(f)) | ||
if err != nil { | ||
lastErr = err | ||
continue | ||
} | ||
|
||
in, err := os.Open(f) | ||
if err != nil { | ||
lastErr = err | ||
continue | ||
} | ||
defer in.Close() | ||
|
||
io.Copy(out, in) | ||
} | ||
|
||
return lastErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package checkups | ||
|
||
import ( | ||
"archive/zip" | ||
"context" | ||
) | ||
|
||
func writeInitLogs(_ context.Context, _ *zip.Writer) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package checkups | ||
|
||
import ( | ||
"archive/zip" | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kolide/launcher/ee/allowedcmd" | ||
) | ||
|
||
func writeInitLogs(ctx context.Context, logZip *zip.Writer) error { | ||
cmdStr := `Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='launcher'} | ConvertTo-Json` | ||
cmd, err := allowedcmd.Powershell(ctx, cmdStr) | ||
if err != nil { | ||
return fmt.Errorf("creating powershell command: %w", err) | ||
} | ||
|
||
outFile, err := logZip.Create("windows_launcher_events.json") | ||
if err != nil { | ||
return fmt.Errorf("creating windows_launcher_events.json: %w", err) | ||
} | ||
|
||
cmd.Stderr = outFile | ||
cmd.Stdout = outFile | ||
|
||
return cmd.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters