Skip to content

Commit

Permalink
Add deadman flag and fix value of state now that the meaning is act…
Browse files Browse the repository at this point in the history
…ually (0 for OK, 1 for error)
  • Loading branch information
Herbert committed Jun 29, 2017
1 parent 41beb5d commit f29b68b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ build:
go build -v


dist: $(PLATFORMS)
cleanup_dist:
rm -rfv $(DIST_DIR)
mkdir -p $(DIST_DIR)

dist: cleanup_dist $(PLATFORMS)
$(PLATFORMS):
$(eval GOOS := $(firstword $(subst -, ,$@)))
$(eval GOARCH := $(lastword $(subst -, ,$@)))
mkdir -p $(DIST_DIR)
env GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(DIST_DIR)/$(APPNAME).$(RELEASE).$@

md5: dist
Expand Down
4 changes: 2 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func newIPMIEvent(stdout string) (*ipmiEvent, error) {

func (ev ipmiEvent) InfluxDB(checkName, hostname string) string {
return fmt.Sprintf(
`%s,host=%s,event_id=%s,error_level=%s,event_type=%s event_date="%s",event_time="%s",error_level="%s",sensor_name="%s",event_type="%s",error_message="%s",state=%d\n`,
`%s,host=%s,event_id=%s,error_level=%s,event_type=%s event_date="%s",event_time="%s",error_level="%s",sensor_name="%s",event_type="%s",error_message="%s",state=%d`,
checkName, hostname, ev.ID, ev.Level, ev.Type, ev.Time.Format("Jan-02-2006"), ev.Time.Format("03:04:05"), ev.Level, ev.Sensor, ev.Type, ev.Message, ev.State,
)
}
Expand All @@ -65,6 +65,6 @@ func newEmptyIPMIEvent() *ipmiEvent {
Type: "OK",
Level: "OK",
Message: "No errors",
State: 1,
State: 0,
}
}
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
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()
deadman = app.Flag("deadman", "if set, this program will always print something").Default("false").Bool()
ipmiSel = app.Flag("ipmi-sel", "Path of ipmi-sel").Default("/usr/sbin/ipmi-sel").String()
)

Expand Down Expand Up @@ -53,13 +54,13 @@ func main() {
outStr, errStr := string(stdout.Bytes()), string(stderr.Bytes())
log.Printf("%s: stdout `%s`, stderr `%s`", *ipmiSel, outStr, errStr)
if err := cmd.Run(); err != nil {
log.Printf("Got error running `%s`: `%s`\n", *ipmiSel, err)
os.Exit(0)
log.Printf("Got error running `%s`: `%s`\n", *ipmiSel, err) // purposely do not quit
}

outStr = strings.TrimSpace(outStr)
lines := strings.Split(outStr, "\n")
if len(lines) >= 0 {
lines := strings.Split(strings.TrimSpace(outStr), "\n")
log.Printf("%#v\n", lines)

if len(lines) >= 0 && lines[0] != "" {
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
Expand All @@ -74,7 +75,7 @@ func main() {
}
fmt.Println(ev.InfluxDB(*checkName, hostname))
}
} else {
} else if *deadman {
ev := newEmptyIPMIEvent()
fmt.Println(ev.InfluxDB(*checkName, hostname))
}
Expand Down

0 comments on commit f29b68b

Please sign in to comment.