diff --git a/.travis.yml b/.travis.yml index a133059..c4c9639 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: go go: -- 1.5.3 +- 1.7.4 addons: apt: packages: diff --git a/args.go b/args.go index 3f91192..a3daa8c 100644 --- a/args.go +++ b/args.go @@ -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:"" 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:"" description:"emit a cronner_group: tag with Datadog events, does not get sent with statsd metrics"` @@ -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 } diff --git a/args_test.go b/args_test.go index 156eb8f..73483c0 100644 --- a/args_test.go +++ b/args_test.go @@ -64,7 +64,7 @@ func (t *TestSuite) Test_binArgs_parse(c *C) { "-V", } - verOut := fmt.Sprintf("cronner v%s built with %s\nCopyright 2015 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version()) + verOut := fmt.Sprintf("cronner v%s built with %s\nCopyright 2017 PagerDuty, Inc.; released under the BSD 3-Clause License\n", Version, runtime.Version()) output, err = args.parse(cli) c.Assert(err, IsNil) @@ -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", @@ -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") @@ -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", @@ -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") @@ -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", @@ -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)) diff --git a/cronner.go b/cronner.go index 82c8c48..c61984d 100644 --- a/cronner.go +++ b/cronner.go @@ -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 @@ -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 {