Skip to content

Commit

Permalink
Merge pull request #40 from cafebazaar/check-script
Browse files Browse the repository at this point in the history
feat: add stderr to check script error logging
  • Loading branch information
mehdy authored Jul 31, 2020
2 parents 78e575e + 019ed04 commit c984ec4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/collector/collector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collector

import (
"bytes"
"os/exec"
"strconv"
"sync"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c984ec4

Please sign in to comment.