Skip to content

Commit f2a598a

Browse files
authored
Trim the buffer before logging (#33)
1 parent a732716 commit f2a598a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

nrpe_exporter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"fmt"
56
"net"
67
"net/http"
@@ -68,9 +69,10 @@ func collectCommandMetrics(cmd string, conn net.Conn, logger log.Logger) (Comman
6869

6970
duration := time.Since(startTime).Seconds()
7071
ipaddr, _, err := net.SplitHostPort(conn.RemoteAddr().String())
72+
output := result.CommandBuffer[:]
7173
level.Info(logger).Log("msg", "Command returned", "command", cmd,
7274
"address", ipaddr, "duration", duration, "return_code", result.ResultCode,
73-
"command_output", fmt.Sprintf("%s", result.CommandBuffer[:]))
75+
"command_output", fmt.Sprintf("%s", bytes.Trim(output, "\x00")))
7476
statusOk := 1.0
7577
if result.ResultCode != 0 {
7678
statusOk = 0

0 commit comments

Comments
 (0)