Skip to content

Commit a6e463c

Browse files
authored
Log the results of *all* commands (#31)
* Log the results of *all* commands * Also log the address
1 parent c434ac1 commit a6e463c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ $(ARCHES):
2323
@echo docker buildx build --platform linux/$@ --build-arg ARCH=$@ -t $(IMAGETAG) .
2424
@docker buildx build --platform linux/$@ --build-arg ARCH=$@ -t $(IMAGETAG) .
2525
@id=$$(docker create canonical/nrpe-exporter:latest) && \
26-
sudo docker cp $$id:/bin/nrpe_exporter ./nrpe_exporter-$@ && \
27-
(docker rm $$id > /dev/null)
26+
sudo docker cp $$id:/bin/nrpe_exporter ./nrpe_exporter-$@ && \
27+
(docker rm $$id > /dev/null)
2828
@docker rmi $(IMAGETAG) > /dev/null 2>&1
2929
@docker image prune --filter="label=canonical=buildenv" --force > /dev/null 2>&1
3030
@echo Finished: binary is at ./nrpe_exporter-$@

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.4

nrpe_exporter.go

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

33
import (
4+
"fmt"
45
"net"
56
"net/http"
67
"os"
@@ -66,11 +67,13 @@ func collectCommandMetrics(cmd string, conn net.Conn, logger log.Logger) (Comman
6667
}
6768

6869
duration := time.Since(startTime).Seconds()
69-
level.Debug(logger).Log("msg", "Command returned", "command", cmd, "duration", duration, "result", result.ResultCode)
70+
ipaddr, _, err := net.SplitHostPort(conn.RemoteAddr().String())
71+
level.Info(logger).Log("msg", "Command returned", "command", cmd,
72+
"address", ipaddr, "duration", duration, "return_code", result.ResultCode,
73+
"command_output", fmt.Sprintf("%s", result.CommandBuffer))
7074
statusOk := 1.0
7175
if result.ResultCode != 0 {
7276
statusOk = 0
73-
level.Debug(logger).Log("msg", "Status code did not equal 0", "status code", result.ResultCode)
7477
}
7578
return CommandResult{duration, statusOk, &result}, nil
7679
}

0 commit comments

Comments
 (0)