Skip to content

Commit

Permalink
Merge pull request #59 from slayer321/limit-flag
Browse files Browse the repository at this point in the history
feat: add limit flag
  • Loading branch information
nyrahul committed May 4, 2022
2 parents 6da4191 + b52b3a9 commit b61b333
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 166 deletions.
1 change: 1 addition & 0 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ func init() {
logCmd.Flags().StringVar(&logOptions.PodName, "pod", "", "name of the pod ")
logCmd.Flags().StringVar(&logOptions.Resource, "resource", "", "command used by the user")
logCmd.Flags().StringVar(&logOptions.Source, "source", "", "binary used by the system ")
logCmd.Flags().Uint32Var(&logOptions.Limit, "limit", 0, "number of logs you want to see")
}
19 changes: 15 additions & 4 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Options struct {
PodName string
Source string
Resource string
Limit uint32
}

// StopChan Channel
Expand Down Expand Up @@ -120,7 +121,7 @@ func StartObserver(o Options) error {
}

// create a client
logClient := NewClient(gRPC, o.MsgPath, o.LogPath, o.LogFilter)
logClient := NewClient(gRPC, o.MsgPath, o.LogPath, o.LogFilter, o.Limit)
if logClient == nil {
return errors.New("failed to connect to the gRPC server\nPossible troubleshooting:\n- Check if Kubearmor is running\n- Create a portforward to KubeArmor relay service using\n\t\033[1mkubectl -n kube-system port-forward service/kubearmor --address 0.0.0.0 --address :: 32767:32767\033[0m\n- Configure grpc server information using\n\t\033[1mkarmor log --grpc <info>\033[0m")
}
Expand All @@ -143,6 +144,7 @@ func StartObserver(o Options) error {
return err
}

Limitchan = make(chan bool, 2)
if o.LogPath != "none" {
if o.LogFilter == "all" || o.LogFilter == "policy" {
// watch alerts
Expand All @@ -157,9 +159,18 @@ func StartObserver(o Options) error {
}
}

// listen for interrupt signals
sigChan := GetOSSigChannel()
<-sigChan
if o.Limit != 0 {
if o.LogFilter == "all" {
<-Limitchan
<-Limitchan
} else {
<-Limitchan
}
} else {
// listen for interrupt signals
sigChan := GetOSSigChannel()
<-sigChan
}
close(StopChan)

logClient.Running = false
Expand Down
Loading

0 comments on commit b61b333

Please sign in to comment.