Skip to content

Commit

Permalink
Fix condition when there are no errors on ipmi
Browse files Browse the repository at this point in the history
  • Loading branch information
Herbert committed Jun 28, 2017
1 parent c317970 commit 9019bd4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
import (
"bytes"
"fmt"
"io"
"log/syslog"
"os"
"os/exec"
Expand All @@ -19,6 +20,7 @@ var (
appName = path.Base(os.Args[0])
app = kingpin.New(appName, "A command-line checker for IPMI checks using ipmi-sel, by CrossEngage")
checkName = app.Flag("name", "check name").Default(appName).String()
debug = app.Flag("debug", "if set, enables debug log on stderr").Default("false").Bool()
ipmiSel = app.Flag("ipmi-sel", "Path of ipmi-sel").Default("/usr/sbin/ipmi-sel").String()
)

Expand All @@ -35,7 +37,12 @@ func main() {
if err != nil {
log.Fatal(err)
}
log.SetOutput(slog)

if *debug {
log.SetOutput(io.MultiWriter(slog, os.Stderr))
} else {
log.SetOutput(slog)
}

cmd := exec.Command(*ipmiSel, "--output-event-state", "--comma-separated-output", "--no-header-output")
var stdout, stderr bytes.Buffer
Expand All @@ -46,15 +53,22 @@ func main() {
}

outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
slog.Debug(fmt.Sprintf("%s: stdout `%s`, stderr `%s`", *ipmiSel, outStr, errStr))
log.Printf("%s: stdout `%s`, stderr `%s`", *ipmiSel, outStr, errStr)

outStr = strings.TrimSpace(outStr)
lines := strings.Split(outStr, "\n")
if len(lines) >= 0 {
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
log.Println("Got empty line from output of ipmi-sel.")
continue
}
log.Printf("Line: `%s`\n", line)
ev, err := newIPMIEvent(line)
log.Printf("Event: %#v\n", ev)
if err != nil {
slog.Err(fmt.Sprintf("Could not parse `%s` stdout: `%s`", line, outStr))
log.Printf("Could not parse `%s` stdout: `%s`", line, outStr)
}
fmt.Println(ev.InfluxDB(*checkName, hostname))
}
Expand Down

0 comments on commit 9019bd4

Please sign in to comment.