summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/event/dump_variables.lua
blob: 96eb8f7222f33513a4b5bfb8a60b99c8d9359831 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- Gemeinschaft 5 module: dump_variables event handler class
-- (c) AMOOMA GmbH 2012-2013
-- 

module(...,package.seeall)


function handler_class()
  return DumpVariables
end


DumpVariables = {}


function DumpVariables.new(self, arg)
  arg = arg or {}
  object = arg.object or {}
  setmetatable(object, self);
  self.__index = self;
  self.log = arg.log;
  self.class = 'DumpVariables'
  self.dump_file = arg.file or '/var/log/freeswitch/variables';

  return object;
end


function DumpVariables.event_handlers(self)
  return { CHANNEL_CREATE = { [true] = self.channel_data } }
end


function DumpVariables.channel_data(self, event)
  local sequence = event:getHeader('Event-Sequence');
  local direction = event:getHeader('Call-Direction');

  if not direction or direction ~= 'inbound' then
    return;
  end

  local file = io.open(self.dump_file, 'w');
  if not file then
    self.log:error('[', event.sequence, '] DUMP_VARIABLES - could not open file for writing: ', self.dump_file);
    return;
  end

  self.log:debug('[', event.sequence, '] DUMP_VARIABLES - dumping channel data to: ', self.dump_file);

  file:write(event:serialize(), '\n');
  file:close();
end