Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify packet to allow self defined pattern #63

Merged
merged 4 commits into from Feb 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -16,3 +16,4 @@ test/tmp
test/version_tmp
tmp
.DS_Store
.ruby-version
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -81,4 +81,16 @@ set :notifier_statsd_options, {
}
```

You can define the pattern that will be used to define the key.
In the example the key will be 'test.deployment.example'

```rb
set :application, 'example'
set :stage, 'test'

set :notifier_statsd_options, {
:pattern => "#{stage}.deployment.#{application}"
}
```

The `nc` ([Netcat](http://netcat.sourceforge.net/)) command is used to send messages to statsd and must be installed on the remote hosts. This is installed by default on most Unix machines.
16 changes: 11 additions & 5 deletions lib/capistrano/notifier/statsd.rb
Expand Up @@ -38,11 +38,17 @@ def options
end

def packet
if stage
"#{application}.#{stage}.deploy:#{with}"
else
"#{application}.deploy:#{with}"
end
"#{pattern}:#{with}"
end

def pattern
options.fetch(:pattern){
if stage
"#{application}.#{stage}.deploy"
else
"#{application}.deploy"
end
}
end

def port
Expand Down
17 changes: 17 additions & 0 deletions spec/capistrano/notifier/statsd_spec.rb
Expand Up @@ -78,4 +78,21 @@
end
end
end

context "with a pattern" do
before :each do
configuration.load do
set :application, 'example'
set :stage, 'test'
set :notifier_statsd_options, {
:pattern => "#{stage}.deployment.#{application}"
}
end
end

it "creates a packet" do
subject.send(:packet).should == "test.deployment.example:1|c"
end

end
end