Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuga committed Dec 20, 2009
0 parents commit b0c6516
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 0 deletions.
44 changes: 44 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
This package includes an AMQP icon from www.amqp.org, the AMQP public website.
The icon is distributed under the following license, obtained from
http://www.amqp.org/confluence/display/AMQP/Terms+of+Use. This license
does not apply to the software, which is public domain.

Terms and Conditions

AS USED HEREIN, THE TERM "YOU" SHALL MEAN ANY VISITOR TO THE WEBSITE.

PLEASE READ THESE TERMS AND CONDITIONS CAREFULLY. BY ACCESSING THIS WEBSITE YOU
AGREE TO BE BOUND BY THE TERMS AND CONDITIONS BELOW. THESE TERMS AND CONDITIONS
ARE SUBJECT TO CHANGE WITHOUT NOTICE, FROM TIME TO TIME IN OUR SOLE DISCRETION.
WE WILL NOTIFY YOU OF AMENDMENTS TO THESE TERMS AND CONDITIONS BY POSTING THEM
TO THIS WEBSITE. IF YOU DO NOT AGREE WITH THESE TERMS AND CONDITIONS, PLEASE DO
NOT ACCESS THIS WEBSITE.

You are strictly prohibited from unauthorized use of our systems or this
website, including but not limited to unauthorized entry into our systems,
misuse of passwords, or misuse of any information posted to this website.
Copyright Notice

© Copyright 2005-2009 AMQP Working Group. All rights reserved.

The participants in the AMQP Working Group (collectively the "AMQP Working
Group") are:

Bank of America, N.A., Barclays Bank PLC, Cisco Systems, Credit Suisse, Deutsche
Börse Systems, Envoy Technologies Inc.,Goldman Sachs, IONA Technologies PLC,
iMatix Corporation sprl.,JPMorgan Chase Bank Inc. N.A, Microsoft Corporation,
Novell, Rabbit Technologies Ltd., Red Hat Inc., Solace Systems Inc., Tervela
Inc., TWIST Process Innovations Ltd, WS02 Inc. and 29West Inc.

The works of authorship contained in this website, including but not limited to
all design, text, and images, are owned, or used under license by the AMQP
Working Group.

AMQP Working Group hereby grants you a limited copyright license to download,
evaluate, copy and distribute posted and available documents and related
graphics delivered from this AMQP Working Group website ("Content") provided
that you: (1) include the above copyright notice in all copies; (2) do not
modify the Content; and (3) use the Content for evaluation purposes or for
inclusion in collateral materials (i.e. advertising, articles, product briefs,
marketing and sales materials) on AMQP technology; except where the Content
bears a license with more favourable terms.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GrowlAMQP

Display AMQP messages in growl.

The built in binary, 'growlamqp', will run out-of-the-box to report
messages with non-binary data. It looks like this:

### growlamqp example
$ growlamqp -e amq.direct -k my.key.name
$

If your data requires post-processing, or you only want to see some data,
write a wrapper script. Return whatever you want and growl will print it.
Return nil and it won't print it.

### queuemon

# queuemon
#!/usr/bin/env ruby
require 'growlamqp'
require 'bert'

GrowlAMQP.monitor! do | msg |
BERT.decode(msg)
end

The file 'queuemon' is now a workable executable,
complete with config files, command line options,
and more. Enjoy.
28 changes: 28 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Please note that this only applies to the software in this package.
An additional image has been added, distribued under the accompanying
LICENSE file.

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
7 changes: 7 additions & 0 deletions bin/growlamqp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

# i know, its so evil, etc, etc
require 'rubygems'
require 'growlamqp'

GrowlAMQP.monitor!
9 changes: 9 additions & 0 deletions examples/bert-decode
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby

$: . unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
require 'bert'
require 'growlamqp'

GrowlAMQP.monitor! do | msg |
BERT.decode(msg)
end
9 changes: 9 additions & 0 deletions examples/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env ruby

$: . unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
require 'bert'
require 'growlamqp'

GrowlAMQP.monitor!(:host => "example.org") do | msg |
msg
end
122 changes: 122 additions & 0 deletions lib/growlamqp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@

require 'amqp'
require 'mq'
require 'growl'
require 'daemons'


module GrowlAMQP

# monitor a given AMQP stream
# the given_opts may contain options for AMQP.start!
# and also :queue, :exchange, :vhost, :user, :pass,
# :routing_key, :file, and :ontop.
def monitor!(given_opts = nil, &block)

# default options
opts = {}
unless given_opts
opts[:exchange] = 'amq.fanout'
opts[:queue] = 'amqpgrowl'
end

parser = OptionParser.new do | o |
o.banner = "Usage: #{File.basename($0)} [OPTIONS] <start|stop>"
o.banner = "Relay AMQP messages via growl. Handy for debugging AMQP applications."

o.on('-q','--queue <queue>','The name of the AMQP queue to subscribe to') do | queue |
opts[:queue] = queue
end

o.on('-e','--exchange <exchange>','The name of the AMQP exchange to bind to. Can be specified multiple times') do | exch |
opts[:exchange] = exch
end

o.on('-k','--key <routing key>','The routing key to bind to (on diret and topic exchanges)') do | key |
opts[:key] = key
end

o.on('-v','--vhost <vhost>','The name of the AMQP vhost to connect to') do | vhost |
opts[:vhost] = vhost
end

o.on('-r','--remote <host>','The AMQP broker hostname') do | host |
opts[:host] = host
end

o.on('-u','--user <user>','AMQP username') do | user |
opts[:user] = user
end

o.on('-p','--pass <pass>','AMQP password') do | pass |
opts[:pass] = pass
end

o.on('-c','--file <filename>',"Use the given configuration file for options") do | file |
opts[:file] = file
end

o.on('-t','--ontop','Stay on top (does not daemonize)') do
opts[:ontop] = true
end

o.on('-s','--stop','Stop daemon') do
opts[:command] = "stop"
end

o.on('-h','--help','This help screen') do | nix |
puts o
abort ""
end

end

parser.parse!

# overwrite file options with CLI options
if opts[:file]
opts = YAML.load_file(opts[:file]).merge(opts)
end

# overwrite given options with CLI options
opts = given_opts.merge(opts) if given_opts

opts[:proc] = block || nil
opts[:command] ||= "start"
daemons_argv = [opts[:command]]

unless opts[:command] == "stop"
puts "Want to save this options? Use this as a configuration file, and use -f to find it next time."
puts YAML.dump(opts.reject { |k, v| [:proc,:command].include? k})
end

opts[:icon] = File.expand_path(File.join(File.dirname(__FILE__), '..', 'resources','amqp.jpg'))

Daemons.run_proc("growlamqp", { :multiple => true,
:ARGV => daemons_argv,
:ontop => opts[:ontop]
} ) do
trap(:INT) do AMQP.stop { EM.stop_event_loop }; abort "" end
AMQP.start(opts) do

queue = MQ::Queue.new(MQ.new,opts[:queue], :autodelete => true)
queue.bind(opts[:exchange], :routing_key => opts[:key])

queue.subscribe do | header, body |

message = opts[:proc] ? opts[:proc].call(body) : body
if ! message.nil?
Growl.notify do | m |
m.image = opts[:icon]
m.message = message
end
end

end
end

end
end
module_function :monitor!

end
Binary file added resources/amqp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0c6516

Please sign in to comment.