14

We are running asterisk with 8 port FXO. FXO connects to our old PBX (Samsung Office Serv 100).

Now we want to record all calls routed through FXO (if it was dialed to outside or comming from outside).

Here is the diagram

           |------|---------------------------------
           |      |--------------24 Lines ---------- Other clasic Phones
PRI------  | PBX  |---------------------------------
           |      |
           |      |
           |      |-----------|---------|
           |      |--8 lines--|         |---------         
           |      |-----------|Asterisk |---------- 50 SIP phone
           |------|           |         |----------
                              |---------|----------

Is there a simple way to do this?

Manjoor
  • 3,761
  • 10
  • 40
  • 65

3 Answers3

27

Are you running plain Asterisk? If so you can modify your dial plan to start 'monitoring' the channel, which will record the call.

The monitor command's documentation: http://www.voip-info.org/wiki/view/Asterisk+cmd+monitor

Just for the sake of completion, here's the documentation:

[root@localhost ~]# asterisk -rx 'core show application monitor'

  -= Info about application 'Monitor' =-

[Synopsis]
Monitor a channel

[Description]
  Monitor([file_format[:urlbase],[fname_base],[options]]):
Used to start monitoring a channel. The channel's input and output
voice packets are logged to files until the channel hangs up or
monitoring is stopped by the StopMonitor application.
  file_format           optional, if not set, defaults to "wav"
  fname_base            if set, changes the filename used to the one specified.
  options:
    m   - when the recording ends mix the two leg files into one and
          delete the two leg files.  If the variable MONITOR_EXEC is set, the
          application referenced in it will be executed instead of
          soxmix and the raw leg files will NOT be deleted automatically.
          soxmix or MONITOR_EXEC is handed 3 arguments, the two leg files
          and a target mixed file name which is the same as the leg file names
          only without the in/out designator.
          If MONITOR_EXEC_ARGS is set, the contents will be passed on as
          additional arguments to MONITOR_EXEC
          Both MONITOR_EXEC and the Mix flag can be set from the
          administrator interface

    b   - Don't begin recording unless a call is bridged to another channel
    i   - Skip recording of input stream (disables m option)
    o   - Skip recording of output stream (disables m option)

By default, files are stored to /var/spool/asterisk/monitor/.

Returns -1 if monitor files can't be opened or if the channel is already
monitored, otherwise 0.

And here's a sample way you can use it:

; This fake context records all outgoing calls to /var/spool/asterisk/monitor in wav format.
[fake-outgoing-context]
exten => s,1,Answer()
exten => s,n,Monitor(wav,,b)
exten => s,n,Dial(DAHDI/g0/${EXTEN})
exten => s,n,Hangup()

Obviously you'd have to make changes to my code, but hopefully that gives you a good idea.

rdegges
  • 27,994
  • 16
  • 73
  • 100
10

A real life example is


    exten => _87X,1,NoOp()
    exten => _87X,n,MixMonitor(${UNIQUEID}.wav,ab)
    exten => _87X,n,Dial(SIP/${EXTEN},45)
    exten => _87X,n,StopMixMonitor()
    exten => _87X,n,Hangup()

It's good practise to always have NoOp - the first rule must start with 1, this way you can interchange the rules with the n step any way you want.

It's always best to use MixMonitor as opposed to Monitor - Monitor only records inbound or outbound audio - MixMonitor uses both.

Also wav is quite a good choice as a format - I also use a script to transform the wav files to OGG at the end of the day - the best compromise between size / quality and licensing issues.

With regards to the arguments

a is append b is bridge (good for production - it will only record when the call is answered - not good for debugging)

With regards to StopMixMonitor(), I'm just being thorough, but for examples there are cases in which you would like to stop the recording, for example:


    ...
    exten => _39[5-9],n,Dial(SIP/${EXTEN},45)
    exten => _39[5-9],n,GotoIf($["${DIALSTATUS}" = "BUSY"]?busy:unavailable)
    exten => _39[5-9],n(busy),NoOp()
    exten => _39[5-9],n,StopMixMonitor()
    exten => _39[5-9],n,Voicemail(${EXTEN},u)
    exten => _39[5-9],n,Hangup()
    exten => _39[5-9],n(unavailble),NoOp()
    exten => _39[5-9],n,StopMixMonitor()
    exten => _39[5-9],n,Hangup()
    ...

In this example, you would stop the recording of the voice mail interaction.

Hope this will bring some light on the matter.

nmirceac
  • 301
  • 2
  • 7
  • How do you transform wav files to OGG in a script? Thanks in advance! – Ben Dec 25 '17 at 06:03
  • Hey @Ben --- Many tools are available, but one that will work out of the box is SOX --- /usr/bin/nice -n 19 /usr/bin/sox -e signed-intege -b 16 -t raw -r 8000 SOURCE_FILE_PATH.wav DESTINATION_PATH.ogg --- Make a script that will get your source file paths for you and also make sure their mtime is 2-3 minutes in the past - this way you won't start converting unfinished recordings. If the SOX conversion is successful, you can then delete the .wav. – nmirceac Feb 05 '18 at 10:07
5

Depending on the specifications of your Asterisk box you might find this hack useful too. Create a rather large ramdisk and mount /var/spool/asterisk/monitor to it. That way Asterisk records to memory not disk. Then write a script under cron to move the recordings to permanent storage every 15-30 minutes or so.

vbcrlfuser
  • 181
  • 7
  • uhm.. any experience with running the ramdisk in a production env.? I'm really interested in this ideea – Radu094 Sep 02 '10 at 09:18
  • absolutely, without it would not be able to concurrently record as many channels/calls as we currently do without thrashing the hard disk, 60+ simultaneous calls recorded no problems what so ever, but done direct to disk kills the server – vbcrlfuser Feb 19 '11 at 04:40
  • 1
    @radu094, for ramdisk (it works great) all you need is something like "tmpfs /var/spool/asterisk/monitor tmpfs defaults,size=1024m 1 1" in your /etc/fstab. You should also consider a cronjob that would move the recordings to a persistent storage, but don't forget to only move the file where the mtime is smaller than the current timestamp from which you subtract 2-3 minutes (to be sure you are not moving recordings that are currently being written). Hope this helps... 5 years later....... – nmirceac Dec 01 '15 at 22:05