mgparser 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/bin/mgparser +90 -127
  2. data/lib/optparser.rb +4 -6
  3. data/lib/version.rb +1 -1
  4. metadata +3 -3
data/bin/mgparser CHANGED
@@ -7,6 +7,7 @@ require 'snmp'
7
7
  require 'optparse'
8
8
  require 'ostruct'
9
9
 
10
+ require 'call'
10
11
  require 'optparser'
11
12
  require 'snmp_gw'
12
13
 
@@ -14,137 +15,99 @@ $options = Option.parse(ARGV)
14
15
  $causes = {"1" => "Unallocated (unassigned) number",
15
16
  "2" => "No route to specified transit network (national use)",
16
17
  "3" => "No route to destination",
17
- "4" => "send special information tone",
18
- "5" => "misdialed trunk prefix (national use)",
19
- "6" => "channel unacceptable",
20
- "16" => "Normal hangup (one of the endpoints requested it)",
21
- "31" => "Busy",
22
- "101" =>"Message not compatible with call state"
18
+ "4" => "Send special information tone",
19
+ "5" => "Misdialed trunk prefix (national use)",
20
+ "6" => "Channel unacceptable",
21
+ "7" => "Call awarded, being delivered in an established channel",
22
+ "8" => "Preemption",
23
+ "9" => "Preemption - circuit reserved for reuse",
24
+ "16" => "Normal hangup (one of the endpoints requested it, if not, there are line problems)",
25
+ "17" => "User busy",
26
+ "18" => "No user responding",
27
+ "19" => "No answer from user (user alerted)",
28
+ "20" => "Subscriber absent",
29
+ "21" => "Call rejected",
30
+ "22" => "Number changed",
31
+ "26" => "Non-selected user clearing",
32
+ "27" => "Destination out of order",
33
+ "28" => "Invalid number format (address incomplete)",
34
+ "29" => "Facilities rejected",
35
+ "30" => "Response to STATUS INQUIRY",
36
+ "31" => "Normal unspecified (destination could be busy)",
37
+ "34" => "No circuit/channel available",
38
+ "35" => "Call queued",
39
+ "38" => "Network out of order(check your local ISDN connectionsline and line status)",
40
+ "39" => "Permanent frame mode connection out-of-service",
41
+ "40" => "Permanent frame mode connection operational",
42
+ "41" => "Temporary failure",
43
+ "42" => "Switching equipment congestion",
44
+ "43" => "Access information discarded",
45
+ "44" => "Requested circuit/channel not available",
46
+ "46" => "Precedence call blocked",
47
+ "47" => "Resource unavailable, unspecified",
48
+ "49" => "Quality of service not available",
49
+ "50" => "Requested facility not subscribed",
50
+ "52" => "Outgoing calls barred",
51
+ "53" => "Outgoing calls barred within cug",
52
+ "54" => "Incoming calls barre",
53
+ "55" => "Incoming calls barred within cug",
54
+ "57" => "Bearer capability not authorized",
55
+ "58" => "Bearer capability not presently available",
56
+ "62" => "Inconsistency in outgoing information element",
57
+ "63" => "Service or option not available. unspecified",
58
+ "65" => "Bearer capability not implemented",
59
+ "66" => "Channel type not implemented",
60
+ "69" => "Requested facility not implemented",
61
+ "70" => "Only restricted digital information bearer capability is available",
62
+ "79" => "Service or option not implemented unspecified",
63
+ "81" => "Invalid call reference value",
64
+ "82" => "Identified channel does not exist",
65
+ "83" => "A suspended call exists, but this call identify does not. this cause indicates that a call resume has been attempted with a call identity which differs from that in use for any presently suspended call(s)",
66
+ "84" => "Call identity in use",
67
+ "85" => "No call suspended",
68
+ "86" => "Call having the requested call identity has been cleared",
69
+ "87" => "User not a member of cug",
70
+ "88" => "Incompatible destination",
71
+ "90" => "Non-existent cug",
72
+ "91" => "Invalid transit network selection (national use)",
73
+ "95" => "Invalid message, unspecified",
74
+ "96" => "Mandatory information element is missing",
75
+ "97" => "Message type non-existent or not implemented",
76
+ "98" => "Message not compatible with call state or message type non-existent",
77
+ "99" => "Information element / parameter non-existent or not implemented",
78
+ "100" => "Invalid information element contents",
79
+ "101" => "Message not compatible with call state",
80
+ "102" => "Recovery on timer expiry",
81
+ "103" => "Parameter non-existent or not implemented - passed on (national use)",
82
+ "110" => "Message with unrecognized parameter discarded",
83
+ "111" => "Protocol error, unspecified",
84
+ "127" => "Intel-working, unspecified"
23
85
  }
24
-
25
- module SyslogServer
26
-
27
- def post_init
28
- puts "Media Gateway is connected!"
86
+
87
+ if $options.list[:logfile]
88
+ if FileTest::exist?($options.list[:logfile])
89
+ data = IO.readlines($options.list[:logfile])
90
+ call = Call.new(data)
91
+ else
92
+ puts "File not found"
29
93
  end
94
+ else
95
+ module SyslogServer
30
96
 
31
- def receive_data(data)
32
-
33
- trace = data.gsub(/<191>syslog: /,"")
34
- @callprogr_counter = 0
35
- @matched = 0
36
-
37
- trace.each do |line|
38
-
39
- if line =~ /Unicast RECV Setup/
40
- @inbound = true
41
-
42
- elsif line =~ /CallRouter \[.*\] Src=/
43
- @caller = line.scan(/e164=(\d{1,})/).first
44
-
45
- elsif line =~ /CallRouter \[.*\] Dst\d\/2/
46
- @called = line.scan(/e164=(\d{1,})/).first
47
-
48
-
49
- elsif line =~ /UseNextDestination - Call \d{1,}-\d{1,}/
50
- id = line.scan(/UseNextDestination - Call \d{1,}-(\d{1,})/).first
51
- if @matched < 1
52
- if @inbound == true
53
- @matched += 1
54
- else
55
- puts "Call ID: #{id} - Caller: #{@caller}"
56
- puts "Call ID: #{id} - Called: #{@called}"
57
- end
58
- else
59
- puts "Call ID: #{id} - Caller: #{@caller}"
60
- puts "Call ID: #{id} - Called: #{@called}"
61
- @matched = 0
62
- end
63
-
64
- elsif line =~ /CallManager \[.*\] C\d{1,} - Send CallSetupA/
65
- id = line.scan(/C(\d{1,})/).first
66
- if @inbound == true
67
- puts "Call ID: #{id} - <== ISDN setup received"
68
- else
69
- puts "Call ID: #{id} - ==> ISDN setup sent"
70
- end
71
- @inbound = false
72
-
73
- elsif line =~ /"Proceeding Indication" .* for state CallSetup./
74
- @progress_indication = true
75
-
76
- elsif line =~ /CallManager \[.*\] C\d{1,} - CallProgressA\(2\)/
77
- @callprogr_counter += 1
78
- id = line.scan(/C(\d{1,})/).first
79
-
80
- if @progress_indication == true
81
- #puts "Call ID: #{id} - <== \"Proceeding indication\" received from operator"
82
- @progress_indication = false
83
- else
84
- if @callprogr_counter >= 3
85
- puts "Call ID: #{id} - <== The call will be probably answered by operator\'s voicemail or is being forwarded"
86
- @callprogr_counter = 0
87
- else
88
- puts "Call ID: #{id} - <== \"Call Progress\" received from operator"
89
- end
90
- end
91
-
92
- elsif line =~ /CallManager \[.*\] C\d{1,} - CallProgressA\(3\)/
93
- id = line.scan(/C(\d{1,})/).first
94
- puts "Call ID: #{id} - ==> \"Call Progress\" sent to the operator"
95
-
96
-
97
- elsif line =~ /CallManager \[.*\] C\d{1,} - CallProgressA\(1\)/
98
- id = line.scan(/C(\d{1,})/).first
99
- puts "Call ID: #{id} - <== Destination number is ringing"
100
-
101
-
102
- elsif line =~ /CallManager \[.*\] C\d{1,} - CallConnectA/
103
- id = line.scan(/C(\d{1,})/).first
104
- puts "Call ID: #{id} - Call has been answered!"
97
+ def post_init
98
+ puts "Media Gateway is connected!"
99
+ end
105
100
 
106
-
107
- elsif line =~ /CallManager \[.*\] C\d{1,} - CallMessageA\(2\)/
108
- id = line.scan(/C(\d{1,})/).first
109
- @isdn_inbound_disconnect = true
110
-
111
-
112
- elsif line =~ /CallManager \[.*\] C\d{1,} - Send CallReleaseA\(\d{1,}\)/
113
- id = line.scan(/C(\d{1,})/).first
114
- cause = line.scan(/Send CallReleaseA\((\d{1,})/).first
115
-
116
- if @isdn_inbound_disconnect == true
117
- puts "Call ID: #{id} - <== Operator requested hangup with cause: \"#{$causes[cause.first]}\""
118
- @isdn_inbound_disconnect = false
119
- else
120
- puts "Call ID: #{id} - ==> Gateway sent hangup with cause: \"#{$causes[cause.first]}\""
121
- end
122
-
123
- end
101
+ def receive_data(data)
102
+ call = Call.new(data)
103
+ end
124
104
  end
125
-
126
- end
127
- end
128
105
 
129
- #We initialize eventmachine
130
- EventMachine::run do
131
- host = UDPSocket.open {|s| s.connect($options.list[:ipaddr],30000); s.addr.last }
132
- port = $options.list[:port]
133
- snmpgw = SnmpGw.new($options.list[:port],$options.list[:ipaddr],$options.list[:snmp])
134
- EventMachine::open_datagram_socket host, port, SyslogServer
106
+ #We initialize eventmachine
107
+ EventMachine::run do
108
+ host = UDPSocket.open {|s| s.connect($options.list[:ipaddr],30000); s.addr.last }
109
+ port = $options.list[:port]
110
+ snmpgw = SnmpGw.new($options.list[:port],$options.list[:ipaddr],$options.list[:snmp])
111
+ EventMachine::open_datagram_socket host, port, SyslogServer
112
+ end
135
113
  end
136
-
137
-
138
-
139
- #class Parser
140
- # def initialize(file)
141
- # if FileTest::exist?(file)
142
- # file_lines = IO.readlines(file)
143
- # analyzer(file_lines)
144
- # else
145
- # puts "File not found"
146
- # end
147
- # end
148
- #
149
- #parser = Parser.new(ARGV.first)
150
- #parser
data/lib/optparser.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- class Option
2
+ require "version"
3
3
 
4
+ class Option
5
+
4
6
  #
5
7
  # Return a structure describing the options.
6
8
  #
@@ -44,10 +46,6 @@
44
46
  options.list[:logfile] = logfile
45
47
  end
46
48
 
47
- # Boolean switch.
48
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
49
- options.verbose = v
50
- end
51
49
 
52
50
  opts.separator ""
53
51
  opts.separator "Common options:"
@@ -61,7 +59,7 @@
61
59
 
62
60
  # Another typical switch to print the version.
63
61
  opts.on_tail("--version", "Show version") do
64
- puts OptionParser::Version.join('.')
62
+ puts Mgparser::VERSION::STRING
65
63
  exit
66
64
  end
67
65
  end
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module Mgparser
2
2
  module VERSION
3
3
  MAJOR = 0 unless defined? MAJOR
4
4
  MINOR = 1 unless defined? MINOR
5
- TINY = 1 unless defined? TINY
5
+ TINY = 3 unless defined? TINY
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.') unless defined? STRING
8
8
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mgparser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dawid Pogorzelski