Skip to content

Commit

Permalink
(vup) using details for facts (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Aug 1, 2024
1 parent bf4bb31 commit 78af252
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.3
require (
github.com/glebarez/go-sqlite v1.22.0
github.com/jasonlvhit/gocron v0.0.1
github.com/kevincobain2000/go-msteams v1.0.1
github.com/kevincobain2000/go-msteams v1.1.0
github.com/lmittmann/tint v1.0.5
github.com/mattn/go-isatty v0.0.20
github.com/stretchr/testify v1.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ github.com/kevincobain2000/go-msteams v1.0.0 h1:dp8zIs2PfzsFV1LFFSNFzy1tpEIYJ+X1
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/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw=
github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
Expand Down
40 changes: 21 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,27 @@ func watch(filePath string) {
}

func notify(errorCount int, firstLine, lastLine string) {
if f.msTeamsHook != "" {
teamsMsg := fmt.Sprintf("total errors: %d\n\n", errorCount)
teamsMsg += fmt.Sprintf("first line: %s\n\n", firstLine)
teamsMsg += fmt.Sprintf("last line: %s\n\n", lastLine)
slog.Info("Sending to Teams")

hostname, _ := os.Hostname()
subject := fmt.Sprintf("match: %s", f.match)
subject += "," // nolint: goconst
subject += fmt.Sprintf("ignore: %s", f.ignore)
subject += "," // nolint: goconst
subject += fmt.Sprintf("min error: %d", f.min)
err := gmt.Send(hostname, f.filePath, subject, teamsMsg, f.msTeamsHook, f.proxy)
if err != nil {
slog.Error("Error sending to Teams", "error", err.Error())
} else {
slog.Info("Sent to Teams")
slog.Info("Done")
}
if f.msTeamsHook == "" {
return
}

slog.Info("Sending to MS Teams")
details := map[string]string{
"Match Pattern": f.match,
"Ignore Pattern": f.ignore,
"Min Errors Threshold": fmt.Sprintf("%d", f.min),
"Total Errors Found": fmt.Sprintf("%d", errorCount),
"First Line": firstLine,
"Last Line": lastLine,
}

hostname, _ := os.Hostname()

err := gmt.Send(hostname, details, f.msTeamsHook, f.proxy)
if err != nil {
slog.Error("Error sending to Teams", "error", err.Error())
} else {
slog.Info("Succesfully sent to MS Teams")
}
}

Expand Down

0 comments on commit 78af252

Please sign in to comment.