ipcad2squid 1.0
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.
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +17 -0
- data/bin/ipcad2squid +28 -0
- data/bin/ipcad2squid.rb +28 -0
- data/ipcad2squid.gemspec +18 -0
- data/lib/ipcad2squid.rb +33 -0
- data/spec/input1.txt +35 -0
- data/spec/input2.txt +17 -0
- data/spec/ipcad2squid_spec.rb +38 -0
- metadata +77 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
output.txt
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem 'rspec'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
GEM
|
2
|
+
specs:
|
3
|
+
diff-lcs (1.1.3)
|
4
|
+
rspec (2.12.0)
|
5
|
+
rspec-core (~> 2.12.0)
|
6
|
+
rspec-expectations (~> 2.12.0)
|
7
|
+
rspec-mocks (~> 2.12.0)
|
8
|
+
rspec-core (2.12.1)
|
9
|
+
rspec-expectations (2.12.0)
|
10
|
+
diff-lcs (~> 1.1.3)
|
11
|
+
rspec-mocks (2.12.0)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
rspec
|
data/bin/ipcad2squid
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'ipcad2squid'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
optparse = OptionParser.new do|opts|
|
9
|
+
opts.banner = "Usage: #{__FILE__} [-1] [-2] [-n] [-o] [-h]"
|
10
|
+
opts.separator "Options"
|
11
|
+
|
12
|
+
# Define the options, and what they do
|
13
|
+
opts.on( '-1', '--cmd1 COMMAND', 'Command to show accounting information') { |value| options[:cmd1] = value }
|
14
|
+
opts.on( '-2', '--cmd2 COMMAND', 'Command to show accounting checkpoint information') { |value| options[:cmd2] = value }
|
15
|
+
opts.on( '-n', '--network SUBNET', 'Subnet for filtering (like 192.168.0)') { |value| options[:net] = value }
|
16
|
+
opts.on( '-o', '--output COMMAND', 'Log file to append output') { |value| options[:filename] = value }
|
17
|
+
|
18
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
19
|
+
print opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
optparse.parse!
|
25
|
+
|
26
|
+
ipcad2squid = Ipcad2squid.new(options)
|
27
|
+
ipcad2squid.clear
|
28
|
+
ipcad2squid.write_to_file
|
data/bin/ipcad2squid.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Ipcad2squid
|
4
|
+
attr_reader :cmd1, :cmd2, :net, :ttime, :filename
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@cmd1 = options[:cmd1] || 'netkit-rsh localhost sh ip accounting'
|
8
|
+
@cmd2 = options[:cmd2] || 'netkit-rsh localhost show ip accounting checkpoint'
|
9
|
+
@net = options[:net] || '192.168.0'
|
10
|
+
@filename = options[:filename] || '/var/log/squid/access.log'
|
11
|
+
@ttime = `#{@cmd1}`.split("\n").grep(/saved/) { |saved| saved.split.last }.first rescue '0'
|
12
|
+
end
|
13
|
+
|
14
|
+
def output
|
15
|
+
# get all data for subnet
|
16
|
+
accounting_data = `#{@cmd2}`.split("\n").grep(/#{@net}/)
|
17
|
+
|
18
|
+
# parse and output data
|
19
|
+
accounting_data.map do |raw_data|
|
20
|
+
data = raw_data.split
|
21
|
+
"#{@ttime}.000 1 #{data[1]} TCP_MISS/200 #{data[3]} CONNECT #{data[0]}:#{data[4]} - DIRECT/#{data[1]} -"
|
22
|
+
end.join("\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
def write_to_file
|
26
|
+
File.open(@filename, "w") { |file| file.write(output) }
|
27
|
+
end
|
28
|
+
end
|
data/ipcad2squid.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ipcad2squid'
|
3
|
+
s.version = '1.0'
|
4
|
+
s.date = '2013-01-03'
|
5
|
+
s.summary = "Convert ipcad logs to squid logs"
|
6
|
+
s.description = "Simple gem for converting and appending output from ipcad to squid logs formats"
|
7
|
+
s.authors = ["drakmail", "xPadla"]
|
8
|
+
s.email = 'drakmail@delta.pm'
|
9
|
+
|
10
|
+
s.files = `git ls-files`.split($\)
|
11
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
|
15
|
+
s.homepage = 'https://github.com/drakmail/ipcad2squid'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
end
|
data/lib/ipcad2squid.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Ipcad2squid
|
4
|
+
attr_reader :cmd1, :cmd2, :net, :ttime, :filename
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@cmd1 = options[:cmd1] || 'netkit-rsh localhost sh ip accounting'
|
8
|
+
@cmd2 = options[:cmd2] || 'netkit-rsh localhost show ip accounting checkpoint'
|
9
|
+
@net = options[:net] || '192.168.0'
|
10
|
+
@filename = options[:filename] || '/var/log/squid/access.log'
|
11
|
+
@ttime = `#{@cmd1}`.split("\n").grep(/saved/) { |saved| saved.split.last }.first rescue '0'
|
12
|
+
end
|
13
|
+
|
14
|
+
def output
|
15
|
+
# get all data for subnet
|
16
|
+
accounting_data = `#{@cmd2}`.split("\n").grep(/#{@net}/)
|
17
|
+
|
18
|
+
# parse and output data
|
19
|
+
accounting_data.map do |raw_data|
|
20
|
+
data = raw_data.split
|
21
|
+
"#{@ttime}.000 1 #{data[1]} TCP_MISS/200 #{data[3]} CONNECT #{data[0]}:#{data[4]} - DIRECT/#{data[1]} -"
|
22
|
+
end.join("\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear
|
26
|
+
# move statistics to checkpoint and clear
|
27
|
+
`netkit-rsh localhost clear ip accounting` rescue puts "Couldn't clear ip accounting"
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_to_file
|
31
|
+
File.open(@filename, "a") { |file| file.write(output) }
|
32
|
+
end
|
33
|
+
end
|
data/spec/input1.txt
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Source Destination Packets Bytes
|
2
|
+
46.164.195.254 192.168.0.4 6 482
|
3
|
+
46.211.50.159 192.168.0.4 8 982
|
4
|
+
37.79.42.154 192.168.0.4 8 833
|
5
|
+
2.60.65.237 192.168.0.4 3036 138029
|
6
|
+
46.72.241.99 192.168.0.4 1952 87998
|
7
|
+
109.163.216.19 192.168.0.4 15647 820192
|
8
|
+
89.151.133.15 192.168.0.4 2476 107309
|
9
|
+
217.77.210.254 192.168.0.4 6297 349723
|
10
|
+
178.234.136.81 192.168.0.4 4201 190600
|
11
|
+
95.84.27.95 192.168.0.4 3133 177640
|
12
|
+
80.237.79.145 192.168.0.4 4514 207135
|
13
|
+
2.95.65.135 192.168.0.4 2713 124989
|
14
|
+
95.26.194.158 192.168.0.4 1929 105813
|
15
|
+
46.63.33.34 192.168.0.4 1907 85985
|
16
|
+
78.106.82.110 192.168.0.4 787 42540
|
17
|
+
213.242.8.251 192.168.0.4 2976 137730
|
18
|
+
193.169.220.4 192.168.0.4 2983 178493
|
19
|
+
46.119.234.141 192.168.0.4 1077 48768
|
20
|
+
212.41.32.108 192.168.0.4 6485 299184
|
21
|
+
94.240.217.90 192.168.0.4 1301 56842
|
22
|
+
91.209.51.219 192.168.0.4 3105 137373
|
23
|
+
46.63.188.28 192.168.0.4 1456 82986
|
24
|
+
46.36.27.18 192.168.0.4 5125 277574
|
25
|
+
95.106.233.58 192.168.0.4 4890 258475
|
26
|
+
|
27
|
+
Accounting data age is 4
|
28
|
+
Accounting data age exact 271
|
29
|
+
Accounting data saved 1357223673
|
30
|
+
Interface u1: received ??, 5 m average 47888 bytes/sec, 934 pkts/sec, dropped ??
|
31
|
+
Flow entries made: 452
|
32
|
+
Memory usage: 0% (61472 from 10485760)
|
33
|
+
Free slots for rsh clients: 9
|
34
|
+
IPCAD uptime is 6:18
|
35
|
+
shell-12 uptime is 1 day 3:26
|
data/spec/input2.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Source Destination Packets Bytes
|
2
|
+
37.112.138.228 192.168.0.4 1 345
|
3
|
+
46.211.100.123 192.168.0.4 3 200
|
4
|
+
185.2.107.224 192.168.0.4 1 77
|
5
|
+
89.187.33.17 192.168.0.4 2 112
|
6
|
+
193.169.220.4 192.168.0.4 3496 209636
|
7
|
+
46.119.234.141 192.168.0.4 1225 55490
|
8
|
+
212.41.32.108 192.168.0.4 6973 321808
|
9
|
+
94.240.217.90 192.168.0.4 1568 68301
|
10
|
+
91.209.51.219 192.168.0.4 3106 137413
|
11
|
+
46.63.188.28 192.168.0.4 1456 82986
|
12
|
+
46.36.27.18 192.168.0.4 5631 305248
|
13
|
+
95.106.233.58 192.168.0.4 5372 284271
|
14
|
+
|
15
|
+
Accounting data age is 5
|
16
|
+
Accounting data age exact 335
|
17
|
+
Accounting data saved 1357223737
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ipcad2squid'
|
2
|
+
|
3
|
+
CMD1 = 'cat spec/input1.txt'
|
4
|
+
CMD2 = 'cat spec/input2.txt'
|
5
|
+
|
6
|
+
describe Ipcad2squid do
|
7
|
+
subject(:script) {Ipcad2squid.new(:cmd1 => CMD1, :cmd2 => CMD2)}
|
8
|
+
|
9
|
+
context 'Passing commands' do
|
10
|
+
subject(:script) {Ipcad2squid.new(:cmd1 => CMD1, :cmd2 => CMD2, :filename => 'output.txt')}
|
11
|
+
its(:cmd1) { should == CMD1 }
|
12
|
+
its(:cmd2) { should == CMD2 }
|
13
|
+
its(:filename) { should == 'output.txt' }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'Default commands' do
|
17
|
+
subject(:script) {Ipcad2squid.new}
|
18
|
+
its(:cmd1) { should == 'netkit-rsh localhost sh ip accounting' }
|
19
|
+
its(:cmd2) { should == 'netkit-rsh localhost show ip accounting checkpoint' }
|
20
|
+
its(:filename) { should == '/var/log/squid/access.log' }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'Integration testing' do
|
24
|
+
its(:ttime) { should == '1357223673' }
|
25
|
+
its(:output) { should include('1357223673.000 1 192.168.0.4 TCP_MISS/200 77 CONNECT 185.2.107.224: - DIRECT/192.168.0.4 -') }
|
26
|
+
its(:output) { should include('1357223673.000 1 192.168.0.4 TCP_MISS/200 55490 CONNECT 46.119.234.141: - DIRECT/192.168.0.4 -') }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'File IO' do
|
30
|
+
it 'shoud write output to file' do
|
31
|
+
file = mock('file')
|
32
|
+
File.should_receive(:open).with("/var/log/squid/access.log", "a").and_yield(file)
|
33
|
+
file.should_receive(:write).with(script.output)
|
34
|
+
script.write_to_file
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipcad2squid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- drakmail
|
9
|
+
- xPadla
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
description: Simple gem for converting and appending output from ipcad to squid logs
|
32
|
+
formats
|
33
|
+
email: drakmail@delta.pm
|
34
|
+
executables:
|
35
|
+
- ipcad2squid
|
36
|
+
- ipcad2squid.rb
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- .gitignore
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- bin/ipcad2squid
|
44
|
+
- bin/ipcad2squid.rb
|
45
|
+
- ipcad2squid.gemspec
|
46
|
+
- lib/ipcad2squid.rb
|
47
|
+
- spec/input1.txt
|
48
|
+
- spec/input2.txt
|
49
|
+
- spec/ipcad2squid_spec.rb
|
50
|
+
homepage: https://github.com/drakmail/ipcad2squid
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.23
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Convert ipcad logs to squid logs
|
74
|
+
test_files:
|
75
|
+
- spec/input1.txt
|
76
|
+
- spec/input2.txt
|
77
|
+
- spec/ipcad2squid_spec.rb
|