mgparser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/LICENSE +220 -0
- data/README.markdown +24 -0
- data/bin/mgparser +150 -0
- data/lib/optparser.rb +73 -0
- data/lib/snmp_gw.rb +26 -0
- data/lib/version.rb +33 -0
- data/mgparser.gemspec +37 -0
- metadata +115 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
3
|
+
|
4
|
+
0. This License applies to any program or other work which contains
|
5
|
+
a notice placed by the copyright holder saying it may be distributed
|
6
|
+
under the terms of this General Public License. The "Program", below,
|
7
|
+
refers to any such program or work, and a "work based on the Program"
|
8
|
+
means either the Program or any derivative work under copyright law:
|
9
|
+
that is to say, a work containing the Program or a portion of it,
|
10
|
+
either verbatim or with modifications and/or translated into another
|
11
|
+
language. (Hereinafter, translation is included without limitation in
|
12
|
+
the term "modification".) Each licensee is addressed as "you".
|
13
|
+
|
14
|
+
Activities other than copying, distribution and modification are not
|
15
|
+
covered by this License; they are outside its scope. The act of
|
16
|
+
running the Program is not restricted, and the output from the Program
|
17
|
+
is covered only if its contents constitute a work based on the
|
18
|
+
Program (independent of having been made by running the Program).
|
19
|
+
Whether that is true depends on what the Program does.
|
20
|
+
|
21
|
+
1. You may copy and distribute verbatim copies of the Program's
|
22
|
+
source code as you receive it, in any medium, provided that you
|
23
|
+
conspicuously and appropriately publish on each copy an appropriate
|
24
|
+
copyright notice and disclaimer of warranty; keep intact all the
|
25
|
+
notices that refer to this License and to the absence of any warranty;
|
26
|
+
and give any other recipients of the Program a copy of this License
|
27
|
+
along with the Program.
|
28
|
+
|
29
|
+
You may charge a fee for the physical act of transferring a copy, and
|
30
|
+
you may at your option offer warranty protection in exchange for a fee.
|
31
|
+
|
32
|
+
2. You may modify your copy or copies of the Program or any portion
|
33
|
+
of it, thus forming a work based on the Program, and copy and
|
34
|
+
distribute such modifications or work under the terms of Section 1
|
35
|
+
above, provided that you also meet all of these conditions:
|
36
|
+
|
37
|
+
a) You must cause the modified files to carry prominent notices
|
38
|
+
stating that you changed the files and the date of any change.
|
39
|
+
|
40
|
+
b) You must cause any work that you distribute or publish, that in
|
41
|
+
whole or in part contains or is derived from the Program or any
|
42
|
+
part thereof, to be licensed as a whole at no charge to all third
|
43
|
+
parties under the terms of this License.
|
44
|
+
|
45
|
+
c) If the modified program normally reads commands interactively
|
46
|
+
when run, you must cause it, when started running for such
|
47
|
+
interactive use in the most ordinary way, to print or display an
|
48
|
+
announcement including an appropriate copyright notice and a
|
49
|
+
notice that there is no warranty (or else, saying that you provide
|
50
|
+
a warranty) and that users may redistribute the program under
|
51
|
+
these conditions, and telling the user how to view a copy of this
|
52
|
+
License. (Exception: if the Program itself is interactive but
|
53
|
+
does not normally print such an announcement, your work based on
|
54
|
+
the Program is not required to print an announcement.)
|
55
|
+
|
56
|
+
These requirements apply to the modified work as a whole. If
|
57
|
+
identifiable sections of that work are not derived from the Program,
|
58
|
+
and can be reasonably considered independent and separate works in
|
59
|
+
themselves, then this License, and its terms, do not apply to those
|
60
|
+
sections when you distribute them as separate works. But when you
|
61
|
+
distribute the same sections as part of a whole which is a work based
|
62
|
+
on the Program, the distribution of the whole must be on the terms of
|
63
|
+
this License, whose permissions for other licensees extend to the
|
64
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
65
|
+
|
66
|
+
Thus, it is not the intent of this section to claim rights or contest
|
67
|
+
your rights to work written entirely by you; rather, the intent is to
|
68
|
+
exercise the right to control the distribution of derivative or
|
69
|
+
collective works based on the Program.
|
70
|
+
|
71
|
+
In addition, mere aggregation of another work not based on the Program
|
72
|
+
with the Program (or with a work based on the Program) on a volume of
|
73
|
+
a storage or distribution medium does not bring the other work under
|
74
|
+
the scope of this License.
|
75
|
+
|
76
|
+
3. You may copy and distribute the Program (or a work based on it,
|
77
|
+
under Section 2) in object code or executable form under the terms of
|
78
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
79
|
+
|
80
|
+
a) Accompany it with the complete corresponding machine-readable
|
81
|
+
source code, which must be distributed under the terms of Sections
|
82
|
+
1 and 2 above on a medium customarily used for software interchange; or,
|
83
|
+
|
84
|
+
b) Accompany it with a written offer, valid for at least three
|
85
|
+
years, to give any third party, for a charge no more than your
|
86
|
+
cost of physically performing source distribution, a complete
|
87
|
+
machine-readable copy of the corresponding source code, to be
|
88
|
+
distributed under the terms of Sections 1 and 2 above on a medium
|
89
|
+
customarily used for software interchange; or,
|
90
|
+
|
91
|
+
c) Accompany it with the information you received as to the offer
|
92
|
+
to distribute corresponding source code. (This alternative is
|
93
|
+
allowed only for noncommercial distribution and only if you
|
94
|
+
received the program in object code or executable form with such
|
95
|
+
an offer, in accord with Subsection b above.)
|
96
|
+
|
97
|
+
The source code for a work means the preferred form of the work for
|
98
|
+
making modifications to it. For an executable work, complete source
|
99
|
+
code means all the source code for all modules it contains, plus any
|
100
|
+
associated interface definition files, plus the scripts used to
|
101
|
+
control compilation and installation of the executable. However, as a
|
102
|
+
special exception, the source code distributed need not include
|
103
|
+
anything that is normally distributed (in either source or binary
|
104
|
+
form) with the major components (compiler, kernel, and so on) of the
|
105
|
+
operating system on which the executable runs, unless that component
|
106
|
+
itself accompanies the executable.
|
107
|
+
|
108
|
+
If distribution of executable or object code is made by offering
|
109
|
+
access to copy from a designated place, then offering equivalent
|
110
|
+
access to copy the source code from the same place counts as
|
111
|
+
distribution of the source code, even though third parties are not
|
112
|
+
compelled to copy the source along with the object code.
|
113
|
+
|
114
|
+
4. You may not copy, modify, sublicense, or distribute the Program
|
115
|
+
except as expressly provided under this License. Any attempt
|
116
|
+
otherwise to copy, modify, sublicense or distribute the Program is
|
117
|
+
void, and will automatically terminate your rights under this License.
|
118
|
+
However, parties who have received copies, or rights, from you under
|
119
|
+
this License will not have their licenses terminated so long as such
|
120
|
+
parties remain in full compliance.
|
121
|
+
|
122
|
+
5. You are not required to accept this License, since you have not
|
123
|
+
signed it. However, nothing else grants you permission to modify or
|
124
|
+
distribute the Program or its derivative works. These actions are
|
125
|
+
prohibited by law if you do not accept this License. Therefore, by
|
126
|
+
modifying or distributing the Program (or any work based on the
|
127
|
+
Program), you indicate your acceptance of this License to do so, and
|
128
|
+
all its terms and conditions for copying, distributing or modifying
|
129
|
+
the Program or works based on it.
|
130
|
+
|
131
|
+
6. Each time you redistribute the Program (or any work based on the
|
132
|
+
Program), the recipient automatically receives a license from the
|
133
|
+
original licensor to copy, distribute or modify the Program subject to
|
134
|
+
these terms and conditions. You may not impose any further
|
135
|
+
restrictions on the recipients' exercise of the rights granted herein.
|
136
|
+
You are not responsible for enforcing compliance by third parties to
|
137
|
+
this License.
|
138
|
+
|
139
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
140
|
+
infringement or for any other reason (not limited to patent issues),
|
141
|
+
conditions are imposed on you (whether by court order, agreement or
|
142
|
+
otherwise) that contradict the conditions of this License, they do not
|
143
|
+
excuse you from the conditions of this License. If you cannot
|
144
|
+
distribute so as to satisfy simultaneously your obligations under this
|
145
|
+
License and any other pertinent obligations, then as a consequence you
|
146
|
+
may not distribute the Program at all. For example, if a patent
|
147
|
+
license would not permit royalty-free redistribution of the Program by
|
148
|
+
all those who receive copies directly or indirectly through you, then
|
149
|
+
the only way you could satisfy both it and this License would be to
|
150
|
+
refrain entirely from distribution of the Program.
|
151
|
+
|
152
|
+
If any portion of this section is held invalid or unenforceable under
|
153
|
+
any particular circumstance, the balance of the section is intended to
|
154
|
+
apply and the section as a whole is intended to apply in other
|
155
|
+
circumstances.
|
156
|
+
|
157
|
+
It is not the purpose of this section to induce you to infringe any
|
158
|
+
patents or other property right claims or to contest validity of any
|
159
|
+
such claims; this section has the sole purpose of protecting the
|
160
|
+
integrity of the free software distribution system, which is
|
161
|
+
implemented by public license practices. Many people have made
|
162
|
+
generous contributions to the wide range of software distributed
|
163
|
+
through that system in reliance on consistent application of that
|
164
|
+
system; it is up to the author/donor to decide if he or she is willing
|
165
|
+
to distribute software through any other system and a licensee cannot
|
166
|
+
impose that choice.
|
167
|
+
|
168
|
+
This section is intended to make thoroughly clear what is believed to
|
169
|
+
be a consequence of the rest of this License.
|
170
|
+
|
171
|
+
8. If the distribution and/or use of the Program is restricted in
|
172
|
+
certain countries either by patents or by copyrighted interfaces, the
|
173
|
+
original copyright holder who places the Program under this License
|
174
|
+
may add an explicit geographical distribution limitation excluding
|
175
|
+
those countries, so that distribution is permitted only in or among
|
176
|
+
countries not thus excluded. In such case, this License incorporates
|
177
|
+
the limitation as if written in the body of this License.
|
178
|
+
|
179
|
+
9. The Free Software Foundation may publish revised and/or new versions
|
180
|
+
of the General Public License from time to time. Such new versions will
|
181
|
+
be similar in spirit to the present version, but may differ in detail to
|
182
|
+
address new problems or concerns.
|
183
|
+
|
184
|
+
Each version is given a distinguishing version number. If the Program
|
185
|
+
specifies a version number of this License which applies to it and "any
|
186
|
+
later version", you have the option of following the terms and conditions
|
187
|
+
either of that version or of any later version published by the Free
|
188
|
+
Software Foundation. If the Program does not specify a version number of
|
189
|
+
this License, you may choose any version ever published by the Free Software
|
190
|
+
Foundation.
|
191
|
+
|
192
|
+
10. If you wish to incorporate parts of the Program into other free
|
193
|
+
programs whose distribution conditions are different, write to the author
|
194
|
+
to ask for permission. For software which is copyrighted by the Free
|
195
|
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
196
|
+
make exceptions for this. Our decision will be guided by the two goals
|
197
|
+
of preserving the free status of all derivatives of our free software and
|
198
|
+
of promoting the sharing and reuse of software generally.
|
199
|
+
|
200
|
+
NO WARRANTY
|
201
|
+
|
202
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
203
|
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
204
|
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
205
|
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
206
|
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
207
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
208
|
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
209
|
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
210
|
+
REPAIR OR CORRECTION.
|
211
|
+
|
212
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
213
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
214
|
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
215
|
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
216
|
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
217
|
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
218
|
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
219
|
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
220
|
+
POSSIBILITY OF SUCH DAMAGES.
|
data/README.markdown
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
MGParser
|
2
|
+
========
|
3
|
+
|
4
|
+
MGParser (MGP) is a tool which makes analysis of Mediatrix ISDN gateways debug a much simpler task.
|
5
|
+
|
6
|
+
Documentation
|
7
|
+
=============
|
8
|
+
|
9
|
+
TODO
|
10
|
+
<pre><code>
|
11
|
+
Usage: MGParser.rb [options]
|
12
|
+
|
13
|
+
Specific options:
|
14
|
+
-p, --port PORT Port number on which receive syslog (default is 514)
|
15
|
+
-s, --snmpport PORT Gateway SNMP port number (default is 161)
|
16
|
+
-i, --ipaddr IPADDR Media Gateway IP
|
17
|
+
-l, --logfile LOGFILE Log file to analyze
|
18
|
+
-v, --[no-]verbose Run verbosely
|
19
|
+
|
20
|
+
Common options:
|
21
|
+
-h, --help Show this message
|
22
|
+
--version Show version
|
23
|
+
|
24
|
+
</code></pre>
|
data/bin/mgparser
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), ".", "lib"))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'eventmachine'
|
6
|
+
require 'snmp'
|
7
|
+
require 'optparse'
|
8
|
+
require 'ostruct'
|
9
|
+
|
10
|
+
require 'optparser'
|
11
|
+
require 'snmp_gw'
|
12
|
+
|
13
|
+
$options = Option.parse(ARGV)
|
14
|
+
$causes = {"1" => "Unallocated (unassigned) number",
|
15
|
+
"2" => "No route to specified transit network (national use)",
|
16
|
+
"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"
|
23
|
+
}
|
24
|
+
|
25
|
+
module SyslogServer
|
26
|
+
|
27
|
+
def post_init
|
28
|
+
puts "Media Gateway is connected!"
|
29
|
+
end
|
30
|
+
|
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!"
|
105
|
+
|
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
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
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
|
135
|
+
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
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
class Option
|
3
|
+
|
4
|
+
#
|
5
|
+
# Return a structure describing the options.
|
6
|
+
#
|
7
|
+
def self.parse(args)
|
8
|
+
|
9
|
+
# The options specified on the command line will be collected in *options*.
|
10
|
+
# We set default values here.
|
11
|
+
options = OpenStruct.new
|
12
|
+
#A hash containing all command-line arguments with some default values
|
13
|
+
options.list = {:port =>"514", :snmp => "161"}
|
14
|
+
options.verbose = false
|
15
|
+
|
16
|
+
opts = OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: MGParser.rb [options]"
|
18
|
+
|
19
|
+
opts.separator ""
|
20
|
+
opts.separator "Specific options:"
|
21
|
+
|
22
|
+
|
23
|
+
#Syslog port number
|
24
|
+
opts.on("-p", "--port PORT",
|
25
|
+
"Port number on which receive syslog (default is 514)") do |port|
|
26
|
+
options.list[:port] = port
|
27
|
+
end
|
28
|
+
|
29
|
+
#Gateway SNMP port number
|
30
|
+
opts.on("-s", "--snmpport PORT",
|
31
|
+
"Gateway SNMP port number (default is 161)") do |snmp|
|
32
|
+
options.list[:snmp] = snmp
|
33
|
+
end
|
34
|
+
|
35
|
+
#gateway's ip address
|
36
|
+
opts.on("-i", "--ipaddr IPADDR",
|
37
|
+
"Media Gateway IP") do |ipaddr|
|
38
|
+
options.list[:ipaddr] = ipaddr
|
39
|
+
end
|
40
|
+
|
41
|
+
#log file
|
42
|
+
opts.on("-l", "--logfile LOGFILE",
|
43
|
+
"Log file to analyze") do |logfile|
|
44
|
+
options.list[:logfile] = logfile
|
45
|
+
end
|
46
|
+
|
47
|
+
# Boolean switch.
|
48
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
49
|
+
options.verbose = v
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.separator ""
|
53
|
+
opts.separator "Common options:"
|
54
|
+
|
55
|
+
# No argument, shows at tail. This will print an options summary.
|
56
|
+
# Try it and see!
|
57
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
58
|
+
puts opts
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
|
62
|
+
# Another typical switch to print the version.
|
63
|
+
opts.on_tail("--version", "Show version") do
|
64
|
+
puts OptionParser::Version.join('.')
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.parse!(args)
|
70
|
+
options
|
71
|
+
end # parse()
|
72
|
+
|
73
|
+
end # class OptparseExample
|
data/lib/snmp_gw.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'snmp'
|
5
|
+
include SNMP
|
6
|
+
|
7
|
+
#This object will be used during eventmachine init procedure, it will set the correct ip and port of remote syslog on the gateway
|
8
|
+
class SnmpGw
|
9
|
+
attr_accessor :port, :ipaddr, :snmp
|
10
|
+
|
11
|
+
def initialize(port, ipaddr, snmp)
|
12
|
+
begin
|
13
|
+
manager = Manager.new(:Host => ipaddr,:Port => snmp)
|
14
|
+
local_ip = UDPSocket.open {|s| s.connect($options.list[:ipaddr],30001); s.addr.last }
|
15
|
+
diagnosticTracesEnable = VarBind.new("1.3.6.1.4.1.4935.1000.100.200.100.1100.1.10000.100.0", SNMP::Integer.new("1"))
|
16
|
+
syslogRemoteHost = VarBind.new("1.3.6.1.4.1.4935.1000.100.200.100.1100.1.100.100.0", OctetString.new("#{local_ip}:#{$options.list[:port]}"))
|
17
|
+
manager.set(diagnosticTracesEnable)
|
18
|
+
manager.set(syslogRemoteHost)
|
19
|
+
manager.close
|
20
|
+
rescue Errno::EHOSTUNREACH, Errno::EHOSTDOWN
|
21
|
+
puts "Host Unreachable!"
|
22
|
+
abort""
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mgparser
|
2
|
+
module VERSION
|
3
|
+
MAJOR = 0 unless defined? MAJOR
|
4
|
+
MINOR = 1 unless defined? MINOR
|
5
|
+
TINY = 0 unless defined? TINY
|
6
|
+
|
7
|
+
STRING = [MAJOR, MINOR, TINY].join('.') unless defined? STRING
|
8
|
+
end
|
9
|
+
|
10
|
+
class PkgVersion
|
11
|
+
include Comparable
|
12
|
+
|
13
|
+
attr_reader :major, :minor, :revision
|
14
|
+
|
15
|
+
def initialize(version="")
|
16
|
+
@major, @minor, @revision, @build = version.split(".").map(&:to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
def <=>(other)
|
20
|
+
return @major <=> other.major if ((@major <=> other.major) != 0)
|
21
|
+
return @minor <=> other.minor if ((@minor <=> other.minor) != 0)
|
22
|
+
return @revision <=> other.revision if ((@revision <=> other.revision) != 0)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.sort
|
26
|
+
self.sort!{|a,b| a <=> b}
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
@major.to_s + "." + @minor.to_s + "." + @revision.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/mgparser.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "lib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mgparser"
|
7
|
+
s.version = Mgparser::VERSION::STRING
|
8
|
+
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.authors = ["Dawid Pogorzelski"]
|
11
|
+
|
12
|
+
s.date = Date.today.to_s
|
13
|
+
s.description = "MGParser (MGP) is a tool which makes analysis of Mediatrix ISDN gateways debug a much simpler task."
|
14
|
+
s.email = "dawid.pogorzelski@mybushido.com"
|
15
|
+
s.executables = ["mgparser"]
|
16
|
+
|
17
|
+
s.files = %w{
|
18
|
+
README.markdown
|
19
|
+
bin/mgparser
|
20
|
+
mgparser.gemspec
|
21
|
+
lib/version.rb
|
22
|
+
lib/optparser.rb
|
23
|
+
lib/snmp_gw.rb
|
24
|
+
LICENSE
|
25
|
+
Gemfile
|
26
|
+
}
|
27
|
+
|
28
|
+
s.has_rdoc = false
|
29
|
+
s.homepage = "https://github.com/dawid999/MGParser"
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.summary = "MGParser (MGP) is a tool which makes analysis of Mediatrix ISDN gateways debug a much simpler task."
|
32
|
+
|
33
|
+
# Runtime dependencies
|
34
|
+
s.add_runtime_dependency("bundler", [">= 1.0.10"])
|
35
|
+
s.add_runtime_dependency("eventmachine")
|
36
|
+
s.add_runtime_dependency("snmp")
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mgparser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dawid Pogorzelski
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-20 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 10
|
33
|
+
version: 1.0.10
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: eventmachine
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: snmp
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :runtime
|
63
|
+
version_requirements: *id003
|
64
|
+
description: MGParser (MGP) is a tool which makes analysis of Mediatrix ISDN gateways debug a much simpler task.
|
65
|
+
email: dawid.pogorzelski@mybushido.com
|
66
|
+
executables:
|
67
|
+
- mgparser
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- README.markdown
|
74
|
+
- bin/mgparser
|
75
|
+
- mgparser.gemspec
|
76
|
+
- lib/version.rb
|
77
|
+
- lib/optparser.rb
|
78
|
+
- lib/snmp_gw.rb
|
79
|
+
- LICENSE
|
80
|
+
- Gemfile
|
81
|
+
homepage: https://github.com/dawid999/MGParser
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.7.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: MGParser (MGP) is a tool which makes analysis of Mediatrix ISDN gateways debug a much simpler task.
|
114
|
+
test_files: []
|
115
|
+
|