Class: AsteriskCallNotifier
- Inherits:
-
Object
- Object
- AsteriskCallNotifier
- Defined in:
- lib/asterisk_call_notifier.rb
Instance Method Summary collapse
-
#initialize(csv_path: '/var/log/asterisk/cdr-csv/Master.csv', sps_address: nil, sps_port: 59000, sps_topic: 'asterisk') ⇒ AsteriskCallNotifier
constructor
A new instance of AsteriskCallNotifier.
- #on_new_call(h) ⇒ Object
- #start ⇒ Object
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 = 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 |
Instance Method Details
#on_new_call(h) ⇒ Object
28 29 30 31 32 |
# File 'lib/asterisk_call_notifier.rb', line 28 def on_new_call(h) # custom defined end |
#start ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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 |