corona 0.0.5 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dbac544706aa6c8804d989307768c20ed0e5149
4
- data.tar.gz: efe2c5e74b075d7fa8206c2ce0413221aaf6e345
3
+ metadata.gz: 7e49adab5f337e985451474bbe92fafb21843669
4
+ data.tar.gz: db98d73fb163e1b7ade57187f6d1b13fcc0bdd4b
5
5
  SHA512:
6
- metadata.gz: d00f70284e1d0049d153d83b9c24ae3a49191235fc714fd80f049ba4ab4e2689d2c54aeca1a6e7182d238a064035ea92ff048f6a6f574a36f25bd94e96b4648f
7
- data.tar.gz: 8426a763a70f6d6529b4dff2d8b9e0ba77be47893454fba3d9e91be55408bf1992e281622002457a4a5e4b2751b5fada89bd6dad0c7b516a17f4ed6be785e8cd
6
+ metadata.gz: f3135206c5e6c516028e6c7eb7a0a24d97418d7da354d89bac8567786318c576eb6616111ba545fa0c1afe74e17a807baea64a31d3c8bb6bf8b55bc9525f716c
7
+ data.tar.gz: ba8bac0dfb90302c83bc07d6ce06bc23e8c96c824fe6a5793629b4b9ea93b93e99deccc2cca8380f2188c36886b05c4599e805030e51ec5c73add8c62732921c
data/Gemfile.lock CHANGED
@@ -1,16 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- corona (0.0.5)
4
+ corona (0.0.8)
5
5
  sequel
6
+ slop
6
7
  snmp
7
8
  sqlite3
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- rspec-core (2.14.7)
13
13
  sequel (4.7.0)
14
+ slop (3.4.7)
14
15
  snmp (1.1.1)
15
16
  sqlite3 (1.3.8)
16
17
 
@@ -19,4 +20,3 @@ PLATFORMS
19
20
 
20
21
  DEPENDENCIES
21
22
  corona!
22
- rspec-core
data/bin/corona CHANGED
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'corona'
4
-
5
- Corona.new
3
+ begin
4
+ require 'corona/cli'
5
+ Corona::CLI.new.run
6
+ rescue => error
7
+ warn "#{error}"
8
+ raise if Corona::CFG.debug
9
+ end
data/corona.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'corona'
3
- s.version = '0.0.5'
3
+ s.version = '0.0.8'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
15
15
  s.add_dependency 'sequel'
16
16
  s.add_dependency 'sqlite3'
17
17
  s.add_dependency 'snmp'
18
- s.add_development_dependency 'rspec-core'
18
+ s.add_dependency 'slop'
19
19
  end
data/lib/corona/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Corona
2
+ class CLI
3
+ require 'corona'
4
+ require 'slop'
5
+
6
+ def run cidr=@cidr
7
+ Corona.new :cidr=>cidr
8
+ end
9
+
10
+ private
11
+
12
+ def initialize
13
+ args, opts = opts_parse
14
+ @cidr = args.shift
15
+ CFG.debug = true if opts[:debug]
16
+ end
17
+
18
+ def opts_parse
19
+ opts = Slop.parse(:help=>true) do
20
+ banner 'Usage: corona [cidr]'
21
+ on 'd', 'debug', 'Debugging on'
22
+ end
23
+ [opts.parse!, opts]
24
+ end
25
+
26
+ end
27
+ end
data/lib/corona/core.rb CHANGED
@@ -8,8 +8,8 @@ require 'resolv'
8
8
 
9
9
  module Corona
10
10
  class << self
11
- def new
12
- Core.new
11
+ def new opts={}
12
+ Core.new opts
13
13
  end
14
14
  end
15
15
 
@@ -17,15 +17,16 @@ module Corona
17
17
 
18
18
  private
19
19
 
20
- def initialize
21
- poll, ignore = resolve_networks
22
- @mutex = Mutex.new
23
- @db = DB.new
24
- threads = []
20
+ def initialize opts={}
21
+ cidr = opts.delete :cidr
22
+ poll, ignores = resolve_networks cidr
23
+ @mutex = Mutex.new
24
+ @db = DB.new
25
+ threads = []
25
26
  Thread.abort_on_exception = true
26
27
  poll.each do |net|
27
28
  net.to_range.each do |ip|
28
- next if ignore.any? { |ignore| ignore.include? ip }
29
+ next if ignores.any? { |ignore| ignore.include? ip }
29
30
  while threads.size >= CFG.threads
30
31
  threads.delete_if { |thread| not thread.alive? }
31
32
  sleep 0.01
@@ -125,16 +126,17 @@ module Corona
125
126
  {
126
127
  :ip => opt[:ip].to_s,
127
128
  :ptr => ip2name(opt[:ip].to_s),
128
- :model => Model.map(opt[:oids][:sysDescr]),
129
+ :model => Model.map(opt[:oids][:sysDescr], opt[:oids][:sysObjectID]),
129
130
  :oid_ifDescr => opt[:int],
130
131
  :oid_sysName => opt[:oids][:sysName],
131
132
  :oid_sysLocation => opt[:oids][:sysLocation],
132
133
  :oid_sysDescr => opt[:oids][:sysDescr],
134
+ :oid_sysObjectID => opt[:oids][:sysObjectID].join('.'),
133
135
  }
134
136
  end
135
137
 
136
138
  def normalize_opt opt
137
- opt[:oids][:sysName].sub! /-re[1-9]\./, '-re0.'
139
+ opt[:oids][:sysName].sub!(/-re[1-9]\./, '-re0.')
138
140
  opt
139
141
  end
140
142
 
@@ -142,14 +144,15 @@ module Corona
142
144
  Resolv.getname ip rescue ip
143
145
  end
144
146
 
145
- def resolve_networks
146
- [CFG.poll, CFG.ignore].map do |nets|
147
+ def resolve_networks cidr
148
+ cidr = cidr ? [cidr].flatten : CFG.poll
149
+ [cidr, CFG.ignore].map do |nets|
147
150
  if nets.respond_to? :each
148
151
  nets.map { |net| IPAddr.new net }
149
152
  else
150
153
  out = []
151
154
  File.read(nets).each_line do |net|
152
- net = net.match /^([\d.\/]+)/
155
+ net = net.match(/^([\d.\/]+)/)
153
156
  out.push IPAddr.new net[1] if net
154
157
  end
155
158
  out
@@ -13,6 +13,7 @@ module Corona
13
13
  String :oid_sysName
14
14
  String :oid_sysLocation
15
15
  String :oid_sysDescr
16
+ String :oid_sysObjectID
16
17
  end
17
18
  create_table unless table_exists?
18
19
  end
data/lib/corona/model.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Corona
2
2
  class Model
3
- def self.map sysDescr
3
+ def self.map sysDescr, sysObjectID
4
4
  case sysDescr
5
5
  when /Cisco Catalyst Operating System/i
6
6
  'catos'
@@ -22,12 +22,27 @@ module Corona
22
22
  'ironware'
23
23
  when /^Summit/
24
24
  'xos'
25
+ when /TiMOS/
26
+ 'timos'
27
+ when /^Alcatel-Lucent \S+ [789]\./ #aos <7 is vxworks, >=7 is linux
28
+ 'aos7'
29
+ when /^AOS-W/
30
+ 'aosw'
25
31
  when /^Alcatel-Lucent/
26
32
  'aos'
33
+ when /^AX Series/
34
+ 'acos'
27
35
  when /ProCurve/ # ProCurve OS does not seem to have name?
28
36
  'procurve'
29
37
  when /^\d+[A-Z]\sEthernet Switch$/
30
38
  'powerconnect'
39
+ else
40
+ case sysObjectID
41
+ when Regexp.new('^' + Regexp.quote('1.3.6.1.4.1.12356.'))
42
+ 'fortios' # 1.3.6.1.4.1.12356.101.1.10004
43
+ else
44
+ 'unsupported'
45
+ end
31
46
  end
32
47
  end
33
48
  end
data/lib/corona/snmp.rb CHANGED
@@ -2,14 +2,15 @@ module Corona
2
2
  class SNMP
3
3
  DB_OID = {
4
4
  :sysDescr => '1.3.6.1.2.1.1.1.0',
5
- :sysLocation => '1.3.6.1.2.1.1.6.0',
5
+ :sysObjectID => '1.3.6.1.2.1.1.2.0',
6
6
  :sysName => '1.3.6.1.2.1.1.5.0',
7
+ :sysLocation => '1.3.6.1.2.1.1.6.0',
7
8
  }
8
9
  OID = {
10
+ :ifDescr => '1.3.6.1.2.1.2.2.1.2',
9
11
  :ipCidrRouteIfIndex => '1.3.6.1.2.1.4.24.4.1.5', # addr.255.255.255.255.0.0.0.0.0
10
12
  :ipAdEntIfIndex => '1.3.6.1.2.1.4.20.1.2', # addr
11
13
  :ipAddressIfIndex => '1.3.6.1.2.1.4.34.1.3', # 1,2 (uni,any) . 4,16 (size) . addr
12
- :ifDescr => '1.3.6.1.2.1.2.2.1.2',
13
14
  }
14
15
  UNICAST = 1
15
16
  IPV4 = 4
@@ -54,7 +55,7 @@ module Corona
54
55
  r = @snmp.get_bulk 0, BULK_MAX, oid
55
56
  r.varbind_list.each do |vb|
56
57
  oid = vb.name.to_str
57
- (last = true; break) if not oid.match /^#{Regexp.quote root}/
58
+ (last = true; break) if not oid.match(/^#{Regexp.quote root}/)
58
59
  vbs.push vb
59
60
  end
60
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-07 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec-core
56
+ name: slop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -83,6 +83,7 @@ files:
83
83
  - bin/corona
84
84
  - corona.gemspec
85
85
  - lib/corona.rb
86
+ - lib/corona/cli.rb
86
87
  - lib/corona/config/bootstrap.rb
87
88
  - lib/corona/config/core.rb
88
89
  - lib/corona/core.rb