()
| 99 | } |
| 100 | |
| 101 | func (cli *cliLapi) newContextStatusCmd() *cobra.Command { |
| 102 | cmd := &cobra.Command{ |
| 103 | Use: "status", |
| 104 | Short: "List context to send with alerts", |
| 105 | Args: args.NoArgs, |
| 106 | DisableAutoGenTag: true, |
| 107 | RunE: func(_ *cobra.Command, _ []string) error { |
| 108 | cfg := cli.cfg() |
| 109 | |
| 110 | hub, err := require.Hub(cfg, nil) |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | |
| 115 | if err = alertcontext.LoadConsoleContext(cfg, hub); err != nil { |
| 116 | return fmt.Errorf("while loading context: %w", err) |
| 117 | } |
| 118 | |
| 119 | if len(cfg.Crowdsec.ContextToSend) == 0 { |
| 120 | fmt.Fprintln(os.Stdout, "No context found on this agent. You can use 'cscli lapi context add' to add context to your alerts.") |
| 121 | return nil |
| 122 | } |
| 123 | |
| 124 | dump, err := yaml.Marshal(cfg.Crowdsec.ContextToSend) |
| 125 | if err != nil { |
| 126 | return fmt.Errorf("unable to show context status: %w", err) |
| 127 | } |
| 128 | |
| 129 | fmt.Fprint(os.Stdout, string(dump)) |
| 130 | |
| 131 | return nil |
| 132 | }, |
| 133 | } |
| 134 | |
| 135 | return cmd |
| 136 | } |
| 137 | |
| 138 | func (cli *cliLapi) newContextDetectCmd() *cobra.Command { |
| 139 | var detectAll bool |
no test coverage detected