@@ -22,15 +22,37 @@ var (
22
22
authcheckTemplateFS embed.FS
23
23
)
24
24
25
+ var diagnostics = []struct {
26
+ check func () (any , error )
27
+ template string
28
+ templateFS embed.FS
29
+ }{
30
+ {
31
+ authCheck ,
32
+ authcheckTemplate ,
33
+ authcheckTemplateFS ,
34
+ },
35
+ }
36
+
25
37
// diagnoseCmd represents the diagnose command
26
38
var diagnoseCmd = & cobra.Command {
27
39
Use : "diagnose" ,
28
40
Short : "Run diagnostic checks." ,
29
41
Long : `This command runs diagnostic checks for various settings and configurations
30
42
to attempt to identify issues that could cause the agent to function improperly.` ,
31
- Run : func (cmd * cobra.Command , args []string ) {
43
+ RunE : func (cmd * cobra.Command , args []string ) error {
32
44
fmt .Print ("Running diagnosis checks...\n \n " )
33
- runNetworkCheck ()
45
+ for _ , diagnostic := range diagnostics {
46
+ data , err := diagnostic .check ()
47
+ if err != nil {
48
+ return err
49
+ }
50
+ t := template .Must (template .New (diagnostic .template ).ParseFS (diagnostic .templateFS , diagnostic .template ))
51
+ if err := t .ExecuteTemplate (os .Stdout , authcheckTemplate , data ); err != nil {
52
+ return err
53
+ }
54
+ }
55
+ return nil
34
56
},
35
57
}
36
58
@@ -48,12 +70,8 @@ func init() {
48
70
// diagnoseCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
49
71
}
50
72
51
- func runNetworkCheck () error {
73
+ func authCheck () ( any , error ) {
52
74
collector_url := viper .GetString ("observe_url" )
53
75
authTestResponse := makeAuthTestRequest (collector_url )
54
- t := template .Must (template .New (authcheckTemplate ).ParseFS (authcheckTemplateFS , authcheckTemplate ))
55
- if err := t .ExecuteTemplate (os .Stdout , authcheckTemplate , authTestResponse ); err != nil {
56
- return err
57
- }
58
- return nil
76
+ return authTestResponse , nil
59
77
}
0 commit comments