Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
Added statd host argument
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecloutier-pd committed Jan 26, 2017
1 parent 60ee6e7 commit 2b6155b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion args.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type binArgs struct {
CmdArgs []string // this is not a command line flag, also parsed results
LockDir string `short:"d" long:"lock-dir" default:"/var/lock" description:"the directory where lock files will be placed"`
AllEvents bool `short:"e" long:"event" description:"emit a start and end datadog event"`
StatsdHost string `short:"H" long:"statsd-host" value-name:"<host>" description:"destination host to send datadog metrics"`
FailEvent bool `short:"E" long:"event-fail" description:"only emit an event on failure"`
LogFail bool `short:"F" long:"log-fail" description:"when a command fails, log its full output (stdout/stderr) to the log directory using the UUID as the filename"`
EventGroup string `short:"G" long:"event-group" value-name:"<group>" description:"emit a cronner_group:<group> tag with Datadog events, does not get sent with statsd metrics"`
Expand Down Expand Up @@ -70,7 +71,7 @@ func (a *binArgs) parse(args []string) (string, error) {
}

if a.Version {
out := fmt.Sprintf("cronner v%s built with %s\nCopyright 2015 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version())
out := fmt.Sprintf("cronner v%s built with %s\nCopyright 2017 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version())
return out, nil
}

Expand Down
6 changes: 6 additions & 0 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"-F",
"-G", "test_group",
"-g", "metric_group",
"-H", 'test_host',
"-k",
"-l", "test",
"-L", "info",
Expand All @@ -146,6 +147,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.LogFail, Equals, true)
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.Lock, Equals, true)
c.Check(args.Label, Equals, "test")
c.Check(args.LogLevel, Equals, "info")
Expand All @@ -169,6 +171,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"--log-fail",
"--event-group", "test_group",
"--group", "metric_group",
"--statsd-host", 'test_host',
"--lock",
"--label", "test",
"--log-path", "/var/log/testcronner",
Expand All @@ -191,6 +194,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.LogFail, Equals, true)
c.Check(args.EventGroup, Equals, "test_group")
c.Check(args.Group, Equals, "metric_group")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.Lock, Equals, true)
c.Check(args.Label, Equals, "test")
c.Check(args.LogPath, Equals, "/var/log/testcronner")
Expand All @@ -214,6 +218,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
"--group=metric_group",
"--label=test",
"--log-path=/var/log/testcronner",
"--statsd-host=test_host"
"--log-level=info",
"--namespace=testcronner",
"--warn-after=42",
Expand All @@ -231,6 +236,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) {
c.Check(args.Group, Equals, "metric_group")
c.Check(args.Label, Equals, "test")
c.Check(args.LogPath, Equals, "/var/log/testcronner")
c.Check(args.StatsdHost, Equals, "test_host")
c.Check(args.LogLevel, Equals, "info")
c.Check(args.Namespace, Equals, "testcronner")
c.Check(args.WarnAfter, Equals, uint64(42))
Expand Down
9 changes: 7 additions & 2 deletions cronner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// Version is the program's version string
const Version = "0.2.5"
const Version = "0.2.6"

type cmdHandler struct {
gs *godspeed.Godspeed
Expand Down Expand Up @@ -46,7 +46,12 @@ func main() {
}

// build a Godspeed client
gs, err := godspeed.NewDefault()
var gs *godspeed.Godspeed
if opts.StatsdHost == "" {
gs, err = godspeed.NewDefault()
} else {
gs, err = godspeed.New(opts.StatsdHost, godspeed.DefaultPort, false)
}

// make sure nothing went wrong with Godspeed
if err != nil {
Expand Down

0 comments on commit 2b6155b

Please sign in to comment.