corona 0.0.2 → 0.0.5

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: 8dbac544706aa6c8804d989307768c20ed0e5149
4
+ data.tar.gz: efe2c5e74b075d7fa8206c2ce0413221aaf6e345
5
+ SHA512:
6
+ metadata.gz: d00f70284e1d0049d153d83b9c24ae3a49191235fc714fd80f049ba4ab4e2689d2c54aeca1a6e7182d238a064035ea92ff048f6a6f574a36f25bd94e96b4648f
7
+ data.tar.gz: 8426a763a70f6d6529b4dff2d8b9e0ba77be47893454fba3d9e91be55408bf1992e281622002457a4a5e4b2751b5fada89bd6dad0c7b516a17f4ed6be785e8cd
data/Gemfile CHANGED
@@ -1,14 +1,3 @@
1
1
  source 'https://rubygems.org'
2
- #ruby '2.0.0'
3
2
 
4
- gem 'sequel'
5
- gem 'sqlite3'
6
- gem 'snmp'
7
-
8
- group :development do
9
- gem 'pry'
10
- end
11
-
12
- group :test do
13
- gem 'rspec'
14
- end
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,32 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ corona (0.0.5)
5
+ sequel
6
+ snmp
7
+ sqlite3
8
+
1
9
  GEM
2
10
  remote: https://rubygems.org/
3
11
  specs:
4
- coderay (1.0.9)
5
- diff-lcs (1.2.3)
6
- method_source (0.8.2)
7
- pry (0.9.10)
8
- coderay (~> 1.0.5)
9
- method_source (~> 0.8)
10
- slop (~> 3.3.1)
11
- rspec (2.14.1)
12
- rspec-core (~> 2.14.0)
13
- rspec-expectations (~> 2.14.0)
14
- rspec-mocks (~> 2.14.0)
15
- rspec-core (2.14.5)
16
- rspec-expectations (2.14.2)
17
- diff-lcs (>= 1.1.3, < 2.0)
18
- rspec-mocks (2.14.3)
19
- sequel (3.42.0)
20
- slop (3.3.2)
21
- snmp (1.1.0)
22
- sqlite3 (1.3.7)
12
+ rspec-core (2.14.7)
13
+ sequel (4.7.0)
14
+ snmp (1.1.1)
15
+ sqlite3 (1.3.8)
23
16
 
24
17
  PLATFORMS
25
18
  ruby
26
19
 
27
20
  DEPENDENCIES
28
- pry
29
- rspec
30
- sequel
31
- snmp
32
- sqlite3
21
+ corona!
22
+ rspec-core
data/Rakefile CHANGED
@@ -1,35 +1,47 @@
1
1
  begin
2
+ require 'rake/testtask'
2
3
  require 'bundler'
3
- require 'rspec/core/rake_task'
4
4
  Bundler.setup
5
5
  rescue LoadError
6
- warn 'missing dependencies'
7
- raise
6
+ warn 'bunler missing'
8
7
  exit 42
9
8
  end
10
9
 
11
10
  gemspec = eval(File.read(Dir['*.gemspec'].first))
11
+ file = [gemspec.name, gemspec.version].join('-') + '.gem'
12
12
 
13
- desc 'Validate the gemspec'
13
+ desc 'Validate gemspec'
14
14
  task :gemspec do
15
15
  gemspec.validate
16
16
  end
17
17
 
18
- RSpec::Core::RakeTask.new(:spec)
18
+ desc 'Run minitest'
19
+ task :test do
20
+ Rake::TestTask.new do |t|
21
+ t.libs.push "lib"
22
+ t.test_files = FileList['spec/*_spec.rb']
23
+ t.verbose = true
24
+ end
25
+ end
19
26
 
20
- desc "Build gem locally"
21
- task :build => [:spec, :gemspec] do
27
+ desc 'Build gem'
28
+ task :build do
22
29
  system "gem build #{gemspec.name}.gemspec"
23
- FileUtils.mkdir_p "gems"
24
- FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "gems"
30
+ FileUtils.mkdir_p 'gems'
31
+ FileUtils.mv file, 'gems'
25
32
  end
26
33
 
27
- desc "Install gem locally"
34
+ desc 'Install gem'
28
35
  task :install => :build do
29
- system "sudo sh -c \'umask 022; gem install gems/#{gemspec.name}-#{gemspec.version}\'"
36
+ system "sudo -E sh -c \'umask 022; gem install gems/#{file}\'"
30
37
  end
31
38
 
32
- desc "Clean automatically generated files"
39
+ desc 'Remove gems'
33
40
  task :clean do
34
- FileUtils.rm_rf "gems"
41
+ FileUtils.rm_rf 'gems'
42
+ end
43
+
44
+ desc 'Push to rubygems'
45
+ task :push do
46
+ system "gem push gems/#{file}"
35
47
  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.2'
3
+ s.version = '0.0.5'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
@@ -15,4 +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
19
  end
data/lib/corona/core.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'corona/log'
2
2
  require 'corona/config/core'
3
3
  require 'corona/snmp'
4
- require 'corona/db'
4
+ require 'corona/db/db'
5
+ require 'corona/model'
5
6
  require 'ipaddr'
6
7
  require 'resolv'
7
8
 
@@ -55,8 +56,8 @@ module Corona
55
56
  def process opt
56
57
  opt = normalize_opt opt
57
58
  record = mkrecord opt
58
- old_by_ip, old_by_sysname = @db.old record[:id], record[:oid_sysName]
59
-
59
+ old_by_ip, old_by_sysname = @db.old record[:ip], record[:oid_sysName]
60
+
60
61
  # unique box having non-unique sysname
61
62
  # old_by_sysname = false if record[:oid_sysDescr].match 'Application Control Engine'
62
63
 
@@ -104,14 +105,14 @@ module Corona
104
105
  elsif new_int_pref == 100 and old_int_pref == 99
105
106
  # neither old or new interface is known good MGMT interface
106
107
  if SNMP.new(old_by_sysname[:ip]).sysdescr
107
- # if old IP works, don't update
108
+ # if old IP works, don't update
108
109
  Log.debug "#{record[:ip]} not updating, previously seen as #{old_by_sysname[:ip]}"
109
110
  else
110
111
  Log.info "#{record[:ip]} updating, old #{old_by_sysname[:ip]} is dead"
111
112
  @db.update record, [:oid_sysName, old_by_sysname[:oid_sysName]]
112
113
  end
113
114
 
114
- elsif new_int_pref >= old_int_pref
115
+ elsif new_int_pref >= old_int_pref
115
116
  # nothing to do, we have better entry
116
117
  Log.debug "#{record[:ip]} already seen as superior via #{old_by_sysname[:ip]}"
117
118
 
@@ -122,10 +123,9 @@ module Corona
122
123
 
123
124
  def mkrecord opt
124
125
  {
125
- :id => opt[:ip].to_i,
126
126
  :ip => opt[:ip].to_s,
127
127
  :ptr => ip2name(opt[:ip].to_s),
128
- :model => model(opt),
128
+ :model => Model.map(opt[:oids][:sysDescr]),
129
129
  :oid_ifDescr => opt[:int],
130
130
  :oid_sysName => opt[:oids][:sysName],
131
131
  :oid_sysLocation => opt[:oids][:sysLocation],
@@ -142,25 +142,6 @@ module Corona
142
142
  Resolv.getname ip rescue ip
143
143
  end
144
144
 
145
- def model opt
146
- case opt[:oids][:sysDescr]
147
- when /Cisco Catalyst operating System/
148
- 'catos'
149
- when /cisco/i, /Application Control Engine/i
150
- 'ios'
151
- when /JUNOS/
152
- 'junos'
153
- when /^NetScreen/, /^SSG-\d+/
154
- 'screenos'
155
- when /IronWare/
156
- 'ironware'
157
- when /^Summit/
158
- 'xos'
159
- when /^\d+[A-Z]\sEthernet Switch$/
160
- 'powerconnect'
161
- end
162
- end
163
-
164
145
  def resolve_networks
165
146
  [CFG.poll, CFG.ignore].map do |nets|
166
147
  if nets.respond_to? :each
@@ -0,0 +1,31 @@
1
+ module Corona
2
+ class DB
3
+ require 'sequel'
4
+ require 'sqlite3'
5
+ def initialize
6
+ Sequel::Model.plugin :schema
7
+ @db = Sequel.sqlite(CFG.db, :max_connections => 1, :pool_timeout => 60)
8
+ require_relative 'model'
9
+ end
10
+
11
+ def add record
12
+ record[:first_seen] = record[:last_seen] = Time.now.utc
13
+ record[:active] = true
14
+ Log.debug "adding: #{record}"
15
+ Device.new(record).save
16
+ end
17
+
18
+ def update record, where
19
+ record[:last_seen] = Time.now.utc
20
+ record[:active] = true
21
+ Log.debug "updating (where: #{where}): #{record}"
22
+ Device[where.first.to_sym => where.last].update record
23
+ end
24
+
25
+ def old ip, oid_sysName
26
+ ip = Device[:ip => ip]
27
+ sysName = Device[:oid_sysName => oid_sysName]
28
+ [ip, sysName]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module Corona
2
+ class DB
3
+ class Device < Sequel::Model
4
+ set_schema do
5
+ primary_key :id
6
+ String :ip
7
+ String :ptr
8
+ String :model
9
+ String :oid_ifDescr
10
+ Boolean :active
11
+ Time :first_seen
12
+ Time :last_seen
13
+ String :oid_sysName
14
+ String :oid_sysLocation
15
+ String :oid_sysDescr
16
+ end
17
+ create_table unless table_exists?
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module Corona
2
+ class Model
3
+ def self.map sysDescr
4
+ case sysDescr
5
+ when /Cisco Catalyst Operating System/i
6
+ 'catos'
7
+ when /Cisco Controller/
8
+ 'aireos'
9
+ when /IOS XR/
10
+ 'iosxr'
11
+ when /NX-OS/
12
+ 'nxos'
13
+ when /cisco/i, /Application Control Engine/i
14
+ 'ios'
15
+ when /JUNOS/
16
+ 'junos'
17
+ when /^NetScreen/, /^SSG-\d+/
18
+ 'screenos'
19
+ when /Arista Networks EOS/
20
+ 'eos'
21
+ when /IronWare/
22
+ 'ironware'
23
+ when /^Summit/
24
+ 'xos'
25
+ when /^Alcatel-Lucent/
26
+ 'aos'
27
+ when /ProCurve/ # ProCurve OS does not seem to have name?
28
+ 'procurve'
29
+ when /^\d+[A-Z]\sEthernet Switch$/
30
+ 'powerconnect'
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/corona/snmp.rb CHANGED
@@ -27,7 +27,7 @@ module Corona
27
27
  oid = [oid].flatten.join('.')
28
28
  begin
29
29
  @snmp.get(oid).each_varbind { |vb| return vb }
30
- rescue ::SNMP::RequestTimeout
30
+ rescue ::SNMP::RequestTimeout, Errno::EACCES
31
31
  return false
32
32
  end
33
33
  end
@@ -42,7 +42,7 @@ module Corona
42
42
  end
43
43
  end
44
44
  end
45
- rescue ::SNMP::RequestTimeout
45
+ rescue ::SNMP::RequestTimeout, Errno::EACCES
46
46
  return false
47
47
  end
48
48
  result
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Saku Ytti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-10 00:00:00.000000000 Z
11
+ date: 2014-03-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sequel
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: snmp
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,20 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-core
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
58
65
  requirements:
59
66
  - - '>='
60
67
  - !ruby/object:Gem::Version
@@ -79,34 +86,32 @@ files:
79
86
  - lib/corona/config/bootstrap.rb
80
87
  - lib/corona/config/core.rb
81
88
  - lib/corona/core.rb
82
- - lib/corona/db.rb
89
+ - lib/corona/db/db.rb
90
+ - lib/corona/db/model.rb
83
91
  - lib/corona/log.rb
92
+ - lib/corona/model.rb
84
93
  - lib/corona/snmp.rb
85
94
  homepage: http://github.com/ytti/corona
86
95
  licenses: []
96
+ metadata: {}
87
97
  post_install_message:
88
98
  rdoc_options: []
89
99
  require_paths:
90
100
  - lib
91
101
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
102
  requirements:
94
103
  - - '>='
95
104
  - !ruby/object:Gem::Version
96
105
  version: '0'
97
- segments:
98
- - 0
99
- hash: 1830848294566328575
100
106
  required_rubygems_version: !ruby/object:Gem::Requirement
101
- none: false
102
107
  requirements:
103
108
  - - '>='
104
109
  - !ruby/object:Gem::Version
105
110
  version: '0'
106
111
  requirements: []
107
112
  rubyforge_project: corona
108
- rubygems_version: 1.8.25
113
+ rubygems_version: 2.0.3
109
114
  signing_key:
110
- specification_version: 3
115
+ specification_version: 4
111
116
  summary: device discovery via snmp polls
112
117
  test_files: []
data/lib/corona/db.rb DELETED
@@ -1,50 +0,0 @@
1
- module Corona
2
- class DB
3
- require 'sequel'
4
- require 'sqlite3'
5
- def initialize
6
- @db = Sequel.sqlite(CFG.db, :max_connections => 1, :pool_timeout => 60)
7
-
8
- @db.create_table :device do
9
- primary_key :id
10
- String :ip
11
- String :ptr
12
- String :model
13
- String :oid_ifDescr
14
- Boolean :active
15
- Time :first_seen
16
- Time :last_seen
17
- String :oid_sysName
18
- String :oid_sysLocation
19
- String :oid_sysDescr
20
- end unless @db.table_exists? :device
21
- end
22
-
23
- # http://sequel.rubyforge.org/rdoc/files/doc/cheat_sheet_rdoc.html
24
- #
25
-
26
- def add record
27
- record[:first_seen] = record[:last_seen] = Time.now.utc
28
- record[:active] = true
29
- #Log.debug "adding: #{record}"
30
- @db[:device].insert record
31
- end
32
-
33
- def update record, where
34
- record[:last_seen] = Time.now.utc
35
- record[:active] = true
36
- #Log.debug "updating (where: #{where}): #{record}"
37
- @db[:device].where('? == ?', where.first, where.last).update record
38
- end
39
-
40
- def [] primary_key
41
- @db[:device].where('id == ?', primary_key).first
42
- end
43
-
44
- def old primary_key, oid_sysName
45
- ip = self[primary_key]
46
- sysName = @db[:device].where('oid_sysName == ?', oid_sysName).first
47
- [ip, sysName]
48
- end
49
- end
50
- end