From 0bb5f485951e44335e148a31c00cdb3e25463ce2 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Mon, 21 Mar 2022 19:18:31 -0300 Subject: [PATCH] messenger: Add hostname before every discord msg --- .../recordtester/continuous_record_tester.go | 4 +--- messenger/messenger.go | 22 +++++-------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/internal/app/recordtester/continuous_record_tester.go b/internal/app/recordtester/continuous_record_tester.go index 4e666566..aafb1801 100644 --- a/internal/app/recordtester/continuous_record_tester.go +++ b/internal/app/recordtester/continuous_record_tester.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "net/url" - "os" "strconv" "time" @@ -66,8 +65,7 @@ func NewContinuousRecordTester(gctx context.Context, opts ContinuousRecordTester } func (crt *continuousRecordTester) Start(fileName string, testDuration, pauseDuration, pauseBetweenTests time.Duration) error { - hostname, _ := os.Hostname() - messenger.SendMessage(fmt.Sprintf("Starting continuous test of %s on hostname=%s", crt.host, hostname)) + messenger.SendMessage(fmt.Sprintf("Starting continuous test of %s", crt.host)) try := 0 notRtmpTry := 0 maxTestDuration := 2*testDuration + pauseDuration + 15*time.Minute diff --git a/messenger/messenger.go b/messenger/messenger.go index 1c48f714..e4a31dde 100644 --- a/messenger/messenger.go +++ b/messenger/messenger.go @@ -6,8 +6,10 @@ package messenger import ( "bytes" "context" + "fmt" "io/ioutil" "net/http" + "os" "strconv" "time" @@ -300,6 +302,8 @@ func sendLoop() { } } +var hostname, _ = os.Hostname() + func sendMessage(msg string) { if len(msg) > maxMessageLen { for { @@ -316,6 +320,7 @@ func sendMessage(msg string) { } return } + msg = fmt.Sprintf("%s: %s", hostname, msg) sendRawMessage(encodeMessage(msg)) } @@ -323,23 +328,6 @@ func sendRawMessage(msg []byte) { if webhookURL == "" || msgCh == nil { return } - /* - if len(msg) > maxMessageLen { - for { - l := maxMessageLen - 10 - if l > len(msg) { - l = len(msg) - } - msg1 := msg[:l] - msg = msg[l:] - sendMessage(msg1) - if len(msg) == 0 { - break - } - } - return - } - */ msgCh <- msg }