@@ -79,6 +79,7 @@ cscli lapi context add --value evt.Meta.source_ip --value evt.Meta.target_user
7979 keySlice := strings .Split (v , "." )
8080 key := keySlice [len (keySlice )- 1 ]
8181 value := []string {v }
82+
8283 if err := cli .addContext (key , value ); err != nil {
8384 return err
8485 }
@@ -105,6 +106,7 @@ func (cli *cliLapi) newContextStatusCmd() *cobra.Command {
105106 DisableAutoGenTag : true ,
106107 RunE : func (_ * cobra.Command , _ []string ) error {
107108 cfg := cli .cfg ()
109+
108110 hub , err := require .Hub (cfg , nil )
109111 if err != nil {
110112 return err
@@ -145,6 +147,7 @@ cscli lapi context detect crowdsecurity/sshd-logs
145147 DisableAutoGenTag : true ,
146148 RunE : func (cmd * cobra.Command , args []string ) error {
147149 cfg := cli .cfg ()
150+
148151 if ! detectAll && len (args ) == 0 {
149152 _ = cmd .Help ()
150153 return errors .New ("please provide parsers to detect or --all flag" )
@@ -168,13 +171,16 @@ cscli lapi context detect crowdsecurity/sshd-logs
168171 }
169172
170173 fieldByParsers := make (map [string ][]string )
174+
171175 for _ , node := range csParsers .Nodes {
172176 if ! detectAll && ! slices .Contains (args , node .Name ) {
173177 continue
174178 }
179+
175180 if ! detectAll {
176181 args = removeFromSlice (node .Name , args )
177182 }
183+
178184 fieldByParsers [node .Name ] = make ([]string , 0 )
179185 fieldByParsers [node .Name ] = detectNode (node , * csParsers .Ctx )
180186
@@ -195,18 +201,22 @@ cscli lapi context detect crowdsecurity/sshd-logs
195201 for k := range fieldByParsers {
196202 parsersKey = append (parsersKey , k )
197203 }
204+
198205 sort .Strings (parsersKey )
199206
200207 for _ , k := range parsersKey {
201208 if len (fieldByParsers [k ]) == 0 {
202209 continue
203210 }
211+
204212 fmt .Fprintf (os .Stdout , "%s :\n \n " , k )
205213 values := fieldByParsers [k ]
206214 sort .Strings (values )
215+
207216 for _ , value := range values {
208217 fmt .Fprintf (os .Stdout , " - %s\n " , value )
209218 }
219+
210220 fmt .Fprintln (os .Stdout )
211221 }
212222
@@ -254,6 +264,7 @@ func (cli *cliLapi) newContextCmd() *cobra.Command {
254264 return fmt .Errorf ("unable to load CrowdSec agent configuration: %w" , err )
255265 }
256266 }
267+
257268 if cfg .DisableAgent {
258269 return errors .New ("agent is disabled and lapi context can only be used on the agent" )
259270 }
0 commit comments