Class: AsteriskCallNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/asterisk_call_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(csv_path: '/var/log/asterisk/cdr-csv/Master.csv', sps_address: nil, sps_port: 59000, sps_topic: 'asterisk') ⇒ AsteriskCallNotifier

Returns a new instance of AsteriskCallNotifier.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/asterisk_call_notifier.rb', line 14

def initialize(csv_path: '/var/log/asterisk/cdr-csv/Master.csv', \
                  sps_address: nil, sps_port: 59000, sps_topic: 'asterisk')

  @csv_path = csv_path

  @sps = SPSPub.new(address: sps_address, port: sps_port)
  @sps_topic = sps_topic

  @command = 'tail -n 1 -f ' + csv_path
  @headings = i(accountcode src dst dcontet clid channel dstchannel
         lastapp lastdata start answer end duration billsec disposition
                                                             amaflags astid)
end

Instance Method Details

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/asterisk_call_notifier.rb', line 28

def start()

  #FileUtils.mv @csv_path, @csv_path + '.old'
  #File.write @csv_path, ''
  t = Time.now # using the time we can ignore existing entries

  IO.popen(@command).each_line do |x| 
    
    if Time.now > t + 10 then
      raw_call_entry = x.lines.last
      json = Hash[@headings.zip(CSV.parse(raw_call_entry).first)].to_json
      @sps.notice @sps_topic+ ': ' + json
    end
  end

end