Skip to content

Commit

Permalink
(feat) dates
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Aug 8, 2024
1 parent 87f800a commit 4eebbc4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.3

require (
github.com/glebarez/go-sqlite v1.22.0
github.com/gravwell/gravwell/v3 v3.8.34
github.com/jasonlvhit/gocron v0.0.1
github.com/kevincobain2000/go-msteams v1.1.1
github.com/lmittmann/tint v1.0.5
Expand All @@ -14,10 +15,10 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.37.6 // indirect
modernc.org/mathutil v1.6.0 // indirect
Expand Down
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ github.com/go-redis/redis v6.15.5+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gravwell/gravwell/v3 v3.8.34 h1:3Cctgw3RAjZBxvm1rUlZybzKPxrVdmC6nt6vlozOMbI=
github.com/gravwell/gravwell/v3 v3.8.34/go.mod h1:FsIn6mNCcY7wEswbhxRpLchB9cF5jjaQIb/V3jh1YOg=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jasonlvhit/gocron v0.0.1 h1:qTt5qF3b3srDjeOIR4Le1LfeyvoYzJlYpqvG7tJX5YU=
github.com/jasonlvhit/gocron v0.0.1/go.mod h1:k9a3TV8VcU73XZxfVHCHWMWF9SOqgoku0/QlY2yvlA4=
github.com/kevincobain2000/go-msteams v1.0.0 h1:dp8zIs2PfzsFV1LFFSNFzy1tpEIYJ+X1Hx/W2oC0CAY=
github.com/kevincobain2000/go-msteams v1.0.0/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo=
github.com/kevincobain2000/go-msteams v1.0.1 h1:EXwMHSrmvV3k6WKL3MotAqkBWta85bq56NBTQi/wbag=
github.com/kevincobain2000/go-msteams v1.0.1/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo=
github.com/kevincobain2000/go-msteams v1.1.0 h1:r2Q/Ug2ZGQclDHzIfppyfB4FPjAcDjNIti3WmI91VTo=
github.com/kevincobain2000/go-msteams v1.1.0/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo=
github.com/kevincobain2000/go-msteams v1.1.1 h1:vZ8AYvVmiCdC+VZwsw7RFhb89RG/GasX9kvbdKheFN4=
github.com/kevincobain2000/go-msteams v1.1.1/go.mod h1:+HowoQQHg9HLfx3CYQGImGGYw20+kN9rFmUXgxrqBzo=
github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw=
Expand All @@ -47,8 +43,8 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
13 changes: 10 additions & 3 deletions pkg/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func GetHealthCheckDetails(f *Flags, version string) []gmt.Details {
}

func GetAlertDetails(f *Flags, result *ScanResult) []gmt.Details {
return []gmt.Details{
details := []gmt.Details{
{
Label: "File Path",
Message: result.FilePath,
Expand All @@ -71,15 +71,22 @@ func GetAlertDetails(f *Flags, result *ScanResult) []gmt.Details {
},
{
Label: "First Line",
Message: result.FirstLine,
Message: Truncate(result.FirstLine, TRUNCATE_MAX),
},
{
Label: "Mid Lines",
Message: result.PreviewLine,
},
{
Label: "Last Line",
Message: result.LastLine,
Message: Truncate(result.LastLine, TRUNCATE_MAX),
},
}
if result.FirstDate != "" || result.LastDate != "" {
details = append(details, gmt.Details{
Label: "From - To",
Message: fmt.Sprintf("%s - %s", result.FirstDate, result.LastDate),
})
}
return details
}
20 changes: 0 additions & 20 deletions pkg/slices.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
package pkg

import (
"github.com/gravwell/gravwell/v3/timegrinder"
)

func Capped[T any](cap int, slice []T) []T {
capped := cap
if capped > len(slice) {
capped = len(slice)
}
return slice[:capped]
}

func searchDate(input string) string {
cfg := timegrinder.Config{}
tg, err := timegrinder.NewTimeGrinder(cfg)
if err != nil {
return ""
}
ts, ok, err := tg.Extract([]byte(input))
if err != nil {
return ""
}
if !ok {
return ""
}
return ts.String()
}
26 changes: 25 additions & 1 deletion pkg/strings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package pkg

import "crypto/sha256"
import (
"crypto/sha256"

"github.com/gravwell/gravwell/v3/timegrinder"
)

const (
TRUNCATE_MAX = 200
)

func Hash(s string) string {
h := sha256.New()
Expand All @@ -15,3 +23,19 @@ func Truncate(s string, n int) string {
}
return s[:n] + "..."
}

func SearchDate(input string) string {
cfg := timegrinder.Config{}
tg, err := timegrinder.NewTimeGrinder(cfg)
if err != nil {
return ""
}
ts, ok, err := tg.Extract([]byte(input))
if err != nil {
return ""
}
if !ok {
return ""
}
return ts.String()
}
4 changes: 4 additions & 0 deletions pkg/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ type ScanResult struct {
FilePath string
ErrorCount int
FirstLine string
FirstDate string
PreviewLine string
LastLine string
LastDate string
}

func (w *Watcher) Scan() (*ScanResult, error) {
Expand Down Expand Up @@ -135,8 +137,10 @@ func (w *Watcher) Scan() (*ScanResult, error) {
return &ScanResult{
ErrorCount: errorCounts,
FirstLine: firstLine,
FirstDate: SearchDate(firstLine),
PreviewLine: previewLine,
LastLine: lastLine,
LastDate: SearchDate(lastLine),
FilePath: w.filePath,
}, nil
}
Expand Down

0 comments on commit 4eebbc4

Please sign in to comment.