class AsteriskCallNotifier
Public Class Methods
new(csv_path: '/var/log/asterisk/cdr-csv/Master.csv', \ sps_address: nil, sps_port: 59000, sps_topic: 'asterisk')
click to toggle source
# 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 = sps_address ? SPSPub.new(address: sps_address, port: sps_port) : nil @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
Public Instance Methods
on_new_call(h)
click to toggle source
# File lib/asterisk_call_notifier.rb, line 28 def on_new_call(h) # custom defined end
start()
click to toggle source
# File lib/asterisk_call_notifier.rb, line 34 def start() t = Time.now # using the time we can ignore existing entries IO.popen(@command).each_line do |x| # anything after 5 seconds from start is new if Time.now > t + 5 then raw_call_entry = x.lines.last h = Hash[@headings.zip(CSV.parse(raw_call_entry).first)] json = h.to_json @sps.notice(@sps_topic + ': ' + json) if @sps on_new_call(h) end end end