Skip to content

Commit a0d3226

Browse files
committed
Add checkup for intune
1 parent e347655 commit a0d3226

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

ee/allowedcmd/cmd_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func Ipconfig(ctx context.Context, arg ...string) (*exec.Cmd, error) {
3131
return validatedCommand(ctx, filepath.Join(os.Getenv("WINDIR"), "System32", "ipconfig.exe"), arg...)
3232
}
3333

34+
func MdmDiagnosticsTool(ctx context.Context, arg ...string) (*exec.Cmd, error) {
35+
return validatedCommand(ctx, filepath.Join(os.Getenv("WINDIR"), "System32", "mdmdiagnosticstool.exe"), arg...)
36+
}
37+
3438
func Powercfg(ctx context.Context, arg ...string) (*exec.Cmd, error) {
3539
return validatedCommand(ctx, filepath.Join(os.Getenv("WINDIR"), "System32", "powercfg.exe"), arg...)
3640
}

ee/debug/checkups/checkups.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func checkupsFor(k types.Knapsack, target targetBits) []checkupInt {
119119
{&osqConfigConflictCheckup{}, doctorSupported | flareSupported},
120120
{&serverDataCheckup{k: k}, doctorSupported | flareSupported | logSupported},
121121
{&osqDataCollector{k: k}, doctorSupported | flareSupported},
122+
{&intuneCheckup{}, flareSupported},
122123
}
123124

124125
checkupsToRun := make([]checkupInt, 0)

ee/debug/checkups/intune_other.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package checkups
5+
6+
import (
7+
"context"
8+
"io"
9+
)
10+
11+
type intuneCheckup struct{}
12+
13+
func (i *intuneCheckup) Name() string {
14+
return ""
15+
}
16+
17+
func (i *intuneCheckup) Run(_ context.Context, _ io.Writer) error {
18+
return nil
19+
}
20+
21+
func (i *intuneCheckup) ExtraFileName() string {
22+
return ""
23+
}
24+
25+
func (i *intuneCheckup) Status() Status {
26+
return Informational
27+
}
28+
29+
func (i *intuneCheckup) Summary() string {
30+
return ""
31+
}
32+
33+
func (i *intuneCheckup) Data() any {
34+
return nil
35+
}

ee/debug/checkups/intune_windows.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package checkups
5+
6+
import (
7+
"archive/zip"
8+
"context"
9+
"fmt"
10+
"io"
11+
"os"
12+
"path/filepath"
13+
"strings"
14+
15+
"github.com/kolide/launcher/ee/agent"
16+
"github.com/kolide/launcher/ee/allowedcmd"
17+
)
18+
19+
type intuneCheckup struct {
20+
summary string
21+
}
22+
23+
func (i *intuneCheckup) Name() string {
24+
return "Intune"
25+
}
26+
27+
func (i *intuneCheckup) Run(ctx context.Context, extraWriter io.Writer) error {
28+
// Other areas of interest: https://learn.microsoft.com/en-us/mem/intune/remote-actions/collect-diagnostics
29+
30+
zipWriter := zip.NewWriter(extraWriter)
31+
defer zipWriter.Close()
32+
33+
if err := agentLogs(zipWriter); err != nil {
34+
i.summary += fmt.Sprintf("Failed to collect Intune agent logs: %v. ", err)
35+
}
36+
37+
if err := installLogs(zipWriter); err != nil {
38+
i.summary += fmt.Sprintf("Failed to collect Intune install logs: %v. ", err)
39+
}
40+
41+
if err := diagnostics(ctx, zipWriter); err != nil {
42+
i.summary += fmt.Sprintf("Failed to collect Intune diagnostics: %v. ", err)
43+
}
44+
45+
i.summary = strings.TrimSpace(i.summary)
46+
47+
return nil
48+
}
49+
50+
func agentLogs(zipWriter *zip.Writer) error {
51+
agentLogsPathPattern := filepath.Join(os.Getenv("SYSTEMROOT"), "ProgramData", "Microsoft", "IntuneManagementExtension", "Logs", "*")
52+
matches, err := filepath.Glob(agentLogsPathPattern)
53+
if err != nil {
54+
return fmt.Errorf("globbing for agent logs at %s: %w", agentLogsPathPattern, err)
55+
}
56+
57+
for _, match := range matches {
58+
if err := addFileToZip(zipWriter, match); err != nil {
59+
return fmt.Errorf("adding %s to zip: %w", match, err)
60+
}
61+
}
62+
63+
return nil
64+
}
65+
66+
func installLogs(zipWriter *zip.Writer) error {
67+
installLogsPathPattern := filepath.Join(os.Getenv("WINDIR"), "System32", "config", "systemprofile", "AppData", "Local", "mdm", "*.log")
68+
matches, err := filepath.Glob(installLogsPathPattern)
69+
if err != nil {
70+
return fmt.Errorf("globbing for install logs at %s: %w", installLogsPathPattern, err)
71+
}
72+
73+
for _, match := range matches {
74+
if err := addFileToZip(zipWriter, match); err != nil {
75+
return fmt.Errorf("adding %s to zip: %w", match, err)
76+
}
77+
}
78+
79+
return nil
80+
}
81+
82+
func diagnostics(ctx context.Context, zipWriter *zip.Writer) error {
83+
tempDir, err := agent.MkdirTemp("mdm-diagnostics")
84+
if err != nil {
85+
return fmt.Errorf("creating temp dir: %w", err)
86+
}
87+
defer os.RemoveAll(tempDir)
88+
89+
tempOutfile := filepath.Join(tempDir, "MdmDiagnosticReport.zip")
90+
91+
cmd, err := allowedcmd.MdmDiagnosticsTool(ctx, "-zip", outfile)
92+
if cmd == nil {
93+
return nil
94+
} else if err != nil {
95+
return fmt.Errorf("creating diagnostics command: %w", err)
96+
}
97+
98+
return addFileToZip(zipWriter, tempOutfile)
99+
}
100+
101+
func (i *intuneCheckup) ExtraFileName() string {
102+
return "intune.zip"
103+
}
104+
105+
func (i *intuneCheckup) Status() Status {
106+
return Informational
107+
}
108+
109+
func (i *intuneCheckup) Summary() string {
110+
return i.summary
111+
}
112+
113+
func (i *intuneCheckup) Data() any {
114+
return nil
115+
}

0 commit comments

Comments
 (0)