-
Notifications
You must be signed in to change notification settings - Fork 3
/
diagnosis.go
47 lines (38 loc) · 1.03 KB
/
diagnosis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package engine
import (
"encoding/json"
"log"
"os"
"github.com/ahrtr/etcd-diagnosis/engine/intf"
)
const (
reportFileName = "etcd_diagnosis_report.json"
)
type report struct {
Input any `json:"input,omitempty"`
Results []any `json:"results,omitempty"`
}
func Diagnose(input any, plugins []intf.Plugin) {
rp := report{
Input: input,
}
for i, plugin := range plugins {
log.Println("---------------------------------------------------------")
log.Printf("Running %q (%d/%d)...\n", plugin.Name(), i+1, len(plugins))
result := plugin.Diagnose()
rp.Results = append(rp.Results, result)
b, err := json.MarshalIndent(result, "", "\t")
if err != nil {
log.Printf("Failed to marshal result for plugin %q: %v", plugin.Name(), err)
continue
}
log.Println(string(b))
}
b, err := json.MarshalIndent(rp, "", "\t")
if err != nil {
log.Fatalf("Failed to marshal the report: %v", err)
}
if err := os.WriteFile(reportFileName, b, 0644); err != nil {
log.Fatalf("Failed to write the report to file: %v", err)
}
}