asterisk_mini_statement 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b84d84acf68553f1234ec8e3fdb9bb47219bdfcb
4
+ data.tar.gz: 19193af36e377171fbd39e6ebd85346581fd6d8e
5
+ SHA512:
6
+ metadata.gz: 0fc862e796765e1d7f791bc91ad3eccba1e789719ab55113a52f9fe4f0729c627357a9d5fc25d1d5bb62971c0398c8e342d5d756d8a01b03aceaff1e4fc1e196
7
+ data.tar.gz: 8eb5d29518c8d00c8dfdfb121542a6f49efcdff30fc344cadaebed6b7e5797c24d274c36a65ec98d9dc05e8b80b54fc2fb317ee9e21266e858aa09f160d299fb
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: asterisk_mini_statement.rb
4
+
5
+
6
+ require 'csv'
7
+ require 'polyrex'
8
+ require 'subunit'
9
+
10
+ class AsteriskMiniStatement
11
+
12
+ attr_reader :to_xml
13
+
14
+ def initialize(cdr_file='/var/log/asterisk/cdr-csv/Master.csv',
15
+ startdate: (Date.today - 8).strftime("%d-%b-%Y"),
16
+ enddate: (Date.today - 1).strftime("%d-%b-%Y"),
17
+ telno: 'unknown', outgoing_regex: /SIP\/(\d+)@sipgate,30,tr/)
18
+
19
+ sdate = Date.parse startdate
20
+ edate = Date.parse enddate
21
+
22
+ s = File.read cdr_file
23
+
24
+ headings = %i(accountcode src dst dcontet clid channel dstchannel
25
+ lastapp lastdata start answer end duration billsec disposition
26
+ amaflags astid)
27
+
28
+ a = s.lines.map {|line| Hash[headings.zip(CSV.parse(line).first)] }
29
+
30
+
31
+ a2 = a.select do |x|
32
+ date = Date.parse(x[:start])
33
+ date >= sdate and date <= edate and x[:disposition] == 'ANSWERED'
34
+ end
35
+
36
+ a3 = a2.group_by {|x| Date.parse(x[:start]) }
37
+
38
+ px = Polyrex.new('calls[telno, period]/day[date]/item[time, telno,' +
39
+ ' io, dur]')
40
+
41
+ px.summary.period = "%s - %s" % [sdate.strftime("%d/%m/%Y"),
42
+ edate.strftime("%d/%m/%Y")]
43
+ px.summary.telno = telno
44
+
45
+ a3.each do |day, items|
46
+
47
+ px.create_day({date: day.strftime("%d-%b-%Y")}) do |create|
48
+
49
+ items.each do |x|
50
+
51
+ outgoing = x[:lastdata][outgoing_regex,1]
52
+
53
+ io, telno = if outgoing then
54
+ io = ['out', outgoing]
55
+ else
56
+ telno = ['in', x[:clid][/"([^"]+)/,1]]
57
+ end
58
+
59
+ raw_a = Subunit.new(units={minutes:60, hours:60},
60
+ seconds: x[:duration].to_i).to_a
61
+
62
+ a = raw_a.zip(%w(h m s)).inject([]) do |r, x|
63
+ val, label = x
64
+ val > 0 ? r << (val.to_s + label) : r
65
+ end.take 2
66
+
67
+ create.item(time: x[:start], telno: telno, io: io, dur: a.join(' ') )
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ @to_xml = px.to_xml pretty: true
75
+
76
+ end
77
+
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asterisk_mini_statement
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE2MDUxNTE4NTgwMFoXDTE3MDUxNTE4NTgwMFowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBg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15 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: subunit
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.2'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.4
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.2'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.2.4
56
+ - !ruby/object:Gem::Dependency
57
+ name: polyrex
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.1'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 1.1.1
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '1.1'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.1
76
+ description:
77
+ email: james@r0bertson.co.uk
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/asterisk_mini_statement.rb
83
+ homepage: https://github.com/jrobertson/asterisk_mini_statement
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Project under development to output a mini statement of recent telephone
107
+ calls from the Asterisk Call Detail Records (cdr-csv/Master.csv) file.
108
+ test_files: []
metadata.gz.sig ADDED
Binary file