Skip to content

Commit

Permalink
added metadata to server checkup (kolide#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarfda authored Oct 22, 2024
1 parent e6d3fee commit 272dda2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion ee/debug/checkups/server_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package checkups

import (
"context"
"fmt"
"io"
"os"
"path/filepath"

"github.com/kolide/launcher/ee/agent/types"
)
Expand All @@ -23,7 +26,7 @@ type serverDataCheckup struct {
}

func (sdc *serverDataCheckup) Data() any { return sdc.data }
func (sdc *serverDataCheckup) ExtraFileName() string { return "" }
func (sdc *serverDataCheckup) ExtraFileName() string { return "metadata.json" }
func (sdc *serverDataCheckup) Name() string { return "Server Data" }
func (sdc *serverDataCheckup) Status() Status { return sdc.status }
func (sdc *serverDataCheckup) Summary() string { return sdc.summary }
Expand All @@ -32,6 +35,12 @@ func (sdc *serverDataCheckup) Run(ctx context.Context, extraFH io.Writer) error
store := sdc.k.ServerProvidedDataStore()
sdc.data = make(map[string]any)

if err := sdc.addMetadata(extraFH); err != nil {
sdc.status = Warning
sdc.summary += "; failed to add metadata.json"
return fmt.Errorf("adding metadata.json: %w", err)
}

if store == nil {
sdc.status = Warning
sdc.summary = "no server_data store in knapsack"
Expand All @@ -58,3 +67,21 @@ func (sdc *serverDataCheckup) Run(ctx context.Context, extraFH io.Writer) error

return nil
}

func (sdc *serverDataCheckup) addMetadata(extraFH io.Writer) error {
rootDir := sdc.k.RootDirectory()
metadataPath := filepath.Join(rootDir, "metadata.json")

metadataFile, err := os.Open(metadataPath)
if err != nil {
return fmt.Errorf("opening metadata.json: %w", err)
}
defer metadataFile.Close()

// Copy the contents of metadata.json directly to extraFH
if _, err := io.Copy(extraFH, metadataFile); err != nil {
return fmt.Errorf("writing metadata.json to extra file handler: %w", err)
}

return nil
}

0 comments on commit 272dda2

Please sign in to comment.