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 +4 -4
- data/Gemfile.lock +4 -4
- data/corona.gemspec +1 -1
- data/lib/corona/cli.rb +2 -2
- data/lib/corona/core.rb +41 -22
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13a0a34b2f4fb806e785aa8228e713831e2c0897
|
4
|
+
data.tar.gz: 46830aec3debd98c44442d422aaed5fe489aa99d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
17
|
-
slop (3.
|
16
|
+
sequel (4.9.0)
|
17
|
+
slop (3.5.0)
|
18
18
|
snmp (1.1.1)
|
19
|
-
sqlite3 (1.3.
|
19
|
+
sqlite3 (1.3.9)
|
20
20
|
|
21
21
|
PLATFORMS
|
22
22
|
ruby
|
data/corona.gemspec
CHANGED
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
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
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
|
-
|
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
|
-
|
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.
|
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-
|
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.
|
127
|
+
rubygems_version: 2.0.14
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: device discovery via snmp polls
|