corona 0.0.12 → 0.0.13

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: feaba7651c162b75ed4377d5a53dcc6f92dee768
4
- data.tar.gz: 509307e0e7c99b34d5ca6f00355651209b6b58d1
3
+ metadata.gz: 13a0a34b2f4fb806e785aa8228e713831e2c0897
4
+ data.tar.gz: 46830aec3debd98c44442d422aaed5fe489aa99d
5
5
  SHA512:
6
- metadata.gz: 9e9f8c5ecc6ef91cfdcb8f88ea7ad6a4b0ed2e5157c14401354d99db1be5f7aa860ed7cf4da75fc006b43a8e6cc958ee91c5ab54ba9114d8b4aa67b4860d3da4
7
- data.tar.gz: 15957e33cf5288771f4f597b392805a61fd224b86e1c90a5791488a8d2dc9559bdfccaf1323da9a72efde2992c789f26ec08cc62d106b54f757a30ee7f6c6b6f
6
+ metadata.gz: ea8d5b6d6b1a48155eb4eab2381257c211e576caa78609db4816f12af22e942135a9db1c43cb026dc7307b3b6826a36de26336b066ab67dd5506f6dd3841734a
7
+ data.tar.gz: 11424afb5f63c87b3529470adec9d5e3edef6822ff6450f3c5a8c4d4c922ec38e8f65d82322420288c8429eafcd7e0f941f552fda29d8709a6d9499aefaee2d2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- corona (0.0.12)
4
+ corona (0.0.13)
5
5
  asetus
6
6
  sequel
7
7
  slop
@@ -13,10 +13,10 @@ GEM
13
13
  specs:
14
14
  asetus (0.0.7)
15
15
  slop
16
- sequel (4.7.0)
17
- slop (3.4.7)
16
+ sequel (4.9.0)
17
+ slop (3.5.0)
18
18
  snmp (1.1.1)
19
- sqlite3 (1.3.8)
19
+ sqlite3 (1.3.9)
20
20
 
21
21
  PLATFORMS
22
22
  ruby
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.12'
3
+ s.version = '0.0.13'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
data/lib/corona/cli.rb CHANGED
@@ -7,13 +7,13 @@ module Corona
7
7
 
8
8
  def run
9
9
  if @opts[:poll]
10
- Corona.new :cidr=>@opts[:poll]
10
+ Corona.new(:cidr=>@opts[:poll]).run
11
11
  elsif @opts[:remove]
12
12
  remove_records @opts[:remove]
13
13
  elsif @opts['purge-old']
14
14
  remove_old @opts['purge-old']
15
15
  else
16
- Corona.new
16
+ Corona.new.run
17
17
  end
18
18
  end
19
19
 
data/lib/corona/core.rb CHANGED
@@ -11,15 +11,21 @@ module Corona
11
11
  def new opts={}
12
12
  Core.new opts
13
13
  end
14
+
15
+ def poll opts={}
16
+ host = opts.delete :host
17
+ raise CoronaError, '\'host\' not given' unless host
18
+ corona = new opts
19
+ result = corona.poll Resolv.getaddress(host)
20
+ corona.mkrecord result if result
21
+ end
14
22
  end
15
23
 
16
24
  class Core
17
25
 
18
- private
19
-
20
- def initialize opts={}
21
- cidr = opts.delete :cidr
22
- @output = opts.delete :output
26
+ def run
27
+ cidr = @opts.delete :cidr
28
+ @output = @opts.delete :output
23
29
  if not @output
24
30
  @output = Logger.new $stdout
25
31
  @output.formatter = proc { |_ ,_ ,_ , msg| msg + "\n" }
@@ -36,19 +42,23 @@ module Corona
36
42
  threads.delete_if { |thread| not thread.alive? }
37
43
  sleep 0.01
38
44
  end
39
- threads << Thread.new { poll ip }
45
+ threads << Thread.new do
46
+ result = poll ip
47
+ @mutex.synchronize { process result } if result
48
+ end
40
49
  end
41
50
  end
42
51
  threads.each { |thread| thread.join }
43
52
  end
44
53
 
45
54
  def poll ip
46
- snmp = SNMP.new ip.to_s
55
+ result = nil
56
+ snmp = SNMP.new ip.to_s, @community
47
57
  oids = snmp.dbget
48
58
  if oids
49
59
  if index = snmp.ip2index(ip.to_s)
50
60
  if int = snmp.ifdescr(index)
51
- @mutex.synchronize { process :oids=>oids, :int=>int.downcase, :ip=>ip }
61
+ result = {:oids=>oids, :int=>int.downcase, :ip=>ip}
52
62
  else
53
63
  Log.warn "no ifDescr for #{index} at #{ip}"
54
64
  end
@@ -57,6 +67,28 @@ module Corona
57
67
  end
58
68
  end
59
69
  snmp.close
70
+ result
71
+ end
72
+
73
+ def mkrecord opt
74
+ {
75
+ :ip => opt[:ip].to_s,
76
+ :ptr => ip2name(opt[:ip].to_s),
77
+ :model => Model.map(opt[:oids][:sysDescr], opt[:oids][:sysObjectID]),
78
+ :oid_ifDescr => opt[:int],
79
+ :oid_sysName => opt[:oids][:sysName],
80
+ :oid_sysLocation => opt[:oids][:sysLocation],
81
+ :oid_sysDescr => opt[:oids][:sysDescr],
82
+ :oid_sysObjectID => opt[:oids][:sysObjectID].join('.'),
83
+ }
84
+ end
85
+
86
+ private
87
+
88
+ def initialize opts={}
89
+ @opts = opts
90
+ @community = opts.delete :community
91
+ @community ||= CFG.community
60
92
  end
61
93
 
62
94
  def process opt
@@ -110,7 +142,7 @@ module Corona
110
142
 
111
143
  elsif new_int_pref == 100 and old_int_pref == 99
112
144
  # neither old or new interface is known good MGMT interface
113
- if SNMP.new(old_by_sysname[:ip]).sysdescr
145
+ if SNMP.new(old_by_sysname[:ip], @community).sysdescr
114
146
  # if old IP works, don't update
115
147
  Log.debug "#{record[:ip]} not updating, previously seen as #{old_by_sysname[:ip]}"
116
148
  else
@@ -127,19 +159,6 @@ module Corona
127
159
  end
128
160
  end
129
161
 
130
- def mkrecord opt
131
- {
132
- :ip => opt[:ip].to_s,
133
- :ptr => ip2name(opt[:ip].to_s),
134
- :model => Model.map(opt[:oids][:sysDescr], opt[:oids][:sysObjectID]),
135
- :oid_ifDescr => opt[:int],
136
- :oid_sysName => opt[:oids][:sysName],
137
- :oid_sysLocation => opt[:oids][:sysLocation],
138
- :oid_sysDescr => opt[:oids][:sysDescr],
139
- :oid_sysObjectID => opt[:oids][:sysObjectID].join('.'),
140
- }
141
- end
142
-
143
162
  def normalize_opt opt
144
163
  opt[:oids][:sysName].sub!(/-re[1-9]\./, '-re0.')
145
164
  opt
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.12
4
+ version: 0.0.13
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-04-15 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project: corona
127
- rubygems_version: 2.0.3
127
+ rubygems_version: 2.0.14
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: device discovery via snmp polls