Skip to content

Instantly share code, notes, and snippets.

@cloudvoxcode
Created May 6, 2010 15:54
Show Gist options
  • Save cloudvoxcode/392285 to your computer and use it in GitHub Desktop.
Save cloudvoxcode/392285 to your computer and use it in GitHub Desktop.
Asterisk AMI event listener - connect, read, & output
#!/usr/bin/ruby
# connect to Asterisk AMI port, authenticate, and print all AMI event messages
# as they're received.
# more or for Asterisk hosting: http://help.cloudvox.com/
# version: 2010-05-04
require 'socket'
unless ARGV.length == 4
puts 'usage: ruby ./ami_listener.rb hostname port username password'
puts 'example: ruby ./ami_listener.rb ami.cloudvox.com 12345 manager ubers3kr3t'
exit(2)
end
begin
t = TCPSocket.new(ARGV[0], ARGV[1])
rescue
puts "Could not connect: #{$!}"
exit(3)
end
# banner
puts t.gets
t.print "Action: login\r\nUsername: #{ARGV[2]}\r\nSecret: #{ARGV[3]}\r\n\r\n"
while true
puts t.gets
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment