From 019ed04945aa50e4b71761e21df7b77441f21386 Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Thu, 30 Jul 2020 16:17:54 +0430 Subject: [PATCH] feat: add stderr to check script error logging --- internal/collector/collector.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/collector/collector.go b/internal/collector/collector.go index fa1c596..d580bf5 100644 --- a/internal/collector/collector.go +++ b/internal/collector/collector.go @@ -1,6 +1,7 @@ package collector import ( + "bytes" "os/exec" "strconv" "sync" @@ -181,9 +182,13 @@ func (k *KeepalivedCollector) Collect(ch chan<- prometheus.Metric) { func (k *KeepalivedCollector) checkScript(vip string) bool { script := k.scriptPath + " " + vip - out, err := exec.Command("/bin/sh", "-c", script).Output() + cmd := exec.Command("/bin/sh", "-c", script) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Run() if err != nil { - logrus.WithFields(logrus.Fields{"VIP": vip, "output": string(out)}).WithError(err).Error("Check script failed") + logrus.WithFields(logrus.Fields{"VIP": vip, "stdout": stdout.String(), "stderr": stderr.String()}).WithError(err).Error("Check script failed") return false } return true