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

Commit

Permalink
Merge pull request #56 from PagerDuty/add-statd-host-arg
Browse files Browse the repository at this point in the history
Added statd host argument
  • Loading branch information
andrecloutier-pd authored Jan 27, 2017
2 parents 60ee6e7 + ce0621c commit b355fd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.5.3
- 1.7.4
addons:
apt:
packages:
Expand Down
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
8 changes: 7 additions & 1 deletion args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down 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 b355fd0

Please sign in to comment.