Skip to content

Commit

Permalink
Add flag --event-time (--no-event-time) and vendorize deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Herbert Fischer committed Nov 14, 2017
1 parent ed6b676 commit 0f000d2
Show file tree
Hide file tree
Showing 794 changed files with 263,719 additions and 5 deletions.
63 changes: 63 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.3"

[[constraint]]
name = "github.com/stretchr/testify"
version = "1.1.4"

[[constraint]]
name = "gopkg.in/alecthomas/kingpin.v2"
version = "2.2.5"
10 changes: 8 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ func spacesToUnderscore(str string) string {
return strings.Replace(str, " ", "_", -1)
}

func (ev ipmiEvent) InfluxDB(checkName, hostname string) string {
func (ev ipmiEvent) InfluxDB(checkName, hostname string, eventTime bool) string {
var timestamp time.Time
if eventTime {
timestamp = ev.Time
} else {
timestamp = time.Now()
}
return fmt.Sprintf(
`%s,host=%s,event_type=%s,error_level=%s,sensor_name=%s event_id=%s,error_message="%s",state=%d %d`,
checkName, hostname, spacesToUnderscore(ev.Type), spacesToUnderscore(ev.Level), spacesToUnderscore(ev.Sensor),
ev.ID, ev.Message, ev.State, ev.Time.UnixNano())
ev.ID, ev.Message, ev.State, timestamp.UnixNano())
}

func newEmptyIPMIEvent() *ipmiEvent {
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/sirupsen/logrus"
logSys "github.com/sirupsen/logrus/hooks/syslog"
"gopkg.in/alecthomas/kingpin.v1"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
Expand All @@ -22,6 +22,7 @@ var (
debug = app.Flag("debug", "if set, enables debug logging").Default("false").Bool()
syslogHook = app.Flag("syslog", "if set, enables logging to syslog").Default("false").Bool()
deadman = app.Flag("deadman", "if set, this program will always print something").Default("false").Bool()
eventTime = app.Flag("event-time", "if set, the event time will be used instead of current time (Use --no-event-time to set to false)").Default("true").Bool()
ipmiSel = app.Flag("ipmi-sel", "Path of ipmi-sel").Default("/usr/sbin/ipmi-sel").String()
)

Expand Down Expand Up @@ -74,10 +75,10 @@ func main() {
logrus.Errorf("Could not parse line `%s`, err: `%s`", line, err)
continue
}
fmt.Println(ev.InfluxDB(*checkName, hostname))
fmt.Println(ev.InfluxDB(*checkName, hostname, *eventTime))
}
} else if *deadman {
ev := newEmptyIPMIEvent()
fmt.Println(ev.InfluxDB(*checkName, hostname))
fmt.Println(ev.InfluxDB(*checkName, hostname, *eventTime))
}
}
27 changes: 27 additions & 0 deletions vendor/github.com/alecthomas/template/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions vendor/github.com/alecthomas/template/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f000d2

Please sign in to comment.