Archive for November, 2009

Use Adhearsion to check Asterisk

If you have a business depending on asterisk you need to be sure that everything is running. You could use Nagios or Monit to check if asterisk is running, but is it also working? What about your AGI Server? Is it doing what it’s supposed to do?

The best way to find out if this works would be to call and see if the call is accepted and if you get something back from your AGI server and you can do this with automatically with Adhearsion!

What you will need is a wav file containing a DTMF sequence. You can create one with Adobe Audition for example (aka Cooledit before Adobe took over). The Trial version is enough to create the DTMF. Use a 300ms pause at least the other settings didn’t really work for me. Also don’t forget to set your Asterisk server to dtmfmod=inband.

I created a new adhearsion project and used the Simon game as start of and modified it to look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
methods_for :dialplan do
  def check_call
    CheckCall.new(self).start
  end
end
 
class CheckCall
 
  def initialize(call)
    @call = call
    @number='12345'
  end
 
  def start
    collect_attempt
    verify_attempt
  end
 
  def collect_attempt
    @attempt = @call.input @number.length,
      :timeout => 10.seconds    
  end
 
  def verify_attempt
    if attempt_correct? 
		# do something here
    else
		# do something else
    end
  end
 
  def attempt_correct?
    @attempt == @number
  end
 
end

What this does is check if the called server sent the DTMF sequence 12345 and if not it would do something.

You cold for example use growl and/or prowl for notification or use some SMS service for notification like lcx.at (I know, shameless self promotion).

Also don’t forget to activate drb in your adhersion project, do this in startup.rb

config.enable_asterisk
config.asterisk.enable_ami :host => "localhost", :username => "amiuser", :password => "amipassowrd", :events => true
 
config.enable_drb :host => "0.0.0.0", :deny => "0.0.0.0", :allow => ["127.0.0.1", "213.123.118.123"]

Ok now all we need is the script that triggers the call. This could look like this:

require 'drb'
@adhearsion = DRbObject.new_with_uri "druby://localhost:9050"
result = @adhearsion.originate({ :channel   => "SIP/....", 
                                 :context   => "checkcall", 
                                 :exten 	=> '4000',
                                 :priority  => 1,
                                 :callerid  => "43123456789",
                                 :async => 'true',                                     
                                 :variable  => "call_launcher=true|sleep_time=3600" })

So, this is it. I know this isn’t really a copy & paste howto, some things are missing but I don’t want to repeat things that can be read in the adhearsion documentation.
Oh, what I forgot to mention, I use a separate server which runs Asterisk to do the checks, the checks are NOT done form the same server I am checking, but I think this should be obvious.
If you need a VPS with this Setup, or need someone to verify your VoIP Servers, feel free to contact me!

Long time no blog

A long time has passed since my last blog. But time is something I don’t really have right now. Actually even now I have some deadlines approaching and I should be rather working day and night then writing blogs but I thought it’s time to feed my blog a little bit.

So, my last blog I wanted to write was about our trip to Malaga, Spain. Well it didn’t start that good. As some might have heard Sky Europe is broke and disappeared completely from the market. But let me tell the whole story.

We arrived in Bratislava by bus and looked at the Delays, our flight was about 2 hours late. That was bad but it could be worse. The flight to Alicante was over 12 hours late. Anyway, even 2 hours can be terrible in Bratislava airport. It’s very small and you can’t do anything.
But finally we arrived in Malaga just to wait in a huge line to pick up our car from the Car Rental.
Here a hint for someone traveling to Malaga and Renting a car from Carjet (carjet.co.uk) or Goldcar Rental. The prices seem very cheap at the first look but keep in mind that Goldcar works with a Full/Empty policy. This means, you get the car with a full tank and have to return it empty and when you pick up the car you have to pay the full tank. A full tank for a Ford KA kosts about 35 euro (at least that was the most I paid during our holiday) and Goldcar charged 60 Euro. So in the end you are more expensive the Sixt for example. But enough about that.

So after the first two days of holiday I got a call from a friend who told me that Sky Europe isn’t flying anymore. He was Stuck in Greece and we where now stuck in Spain. Thanks to Air Berlin we did get tickets for the same day we planed to return to Vienna and they gave us the tickets a bit cheaper.
The irony is that before buying the tickets with Sky Europe we wanted to buy tickets with Air Berlin but somehow decided to Fly to Portugal and then finally changed our minds again and wanted to go to Malaga again and the Tickets with Sky Europe where a bit cheaper.

Well, we learned our lesson. The flight with Air Berlin was great, on time, you get something to drink, newspapers, food and the price is ok. The worst part of Skyeurope was always that they had delays, didn’t really care much about the fact that you had to pay for drinks or food. But sitting around in the airport for hours is a waste of time.