corona 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/corona.gemspec +1 -1
- data/lib/corona/cli.rb +17 -6
- data/lib/corona/core.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05542efc8878a1c42874c4a0fb32badca922a9b5
|
4
|
+
data.tar.gz: 0758f35f168258f9c9db2f98eb5855517fbfbbbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f47ae73a9939219ea5cb37314d64b5a9c826d6822eef1246f9061a0e97150c8f2ed266aeb2981b87991b30972fcfd1b9241412f2755e78794f4f29900bdfec8c
|
7
|
+
data.tar.gz: 37e81fa4f1bf58cb8867945409b13f498540169a5899a96c94d59af26e3e77143ed9b58dd314bab8d21442bd258993f403804ab9771cc6b27f3e49cbeb4e9bd3
|
data/Gemfile.lock
CHANGED
data/corona.gemspec
CHANGED
data/lib/corona/cli.rb
CHANGED
@@ -8,7 +8,9 @@ module Corona
|
|
8
8
|
if @opts[:poll]
|
9
9
|
Corona.new :cidr=>@opts[:poll]
|
10
10
|
elsif @opts[:remove]
|
11
|
-
|
11
|
+
remove_records @opts[:remove]
|
12
|
+
elsif @opts['purge-old']
|
13
|
+
remove_old @opts['purge-old']
|
12
14
|
else
|
13
15
|
Corona.new
|
14
16
|
end
|
@@ -28,16 +30,26 @@ module Corona
|
|
28
30
|
on 'd', 'debug', 'Debugging on'
|
29
31
|
on 'p=', 'poll', 'Poll CIDR [argument]'
|
30
32
|
on 'r=', 'remove', 'Remove [argument] from DB'
|
31
|
-
on 'm=', 'max-delete', "Maximum number to
|
33
|
+
on 'm=', 'max-delete', "Maximum number to delete, default #{MAX_DELETE}"
|
34
|
+
on 'o=', 'purge-old', 'Remove records order than [argument] days'
|
32
35
|
on 's', 'simulate', 'Simulate, do not change DB'
|
33
36
|
end
|
34
37
|
[opts.parse!, opts]
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
|
40
|
+
def remove_records name
|
41
|
+
DB.new
|
42
|
+
delete_records DB::Device.filter(Sequel.like(:ptr, "%#{name}%")).all
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_old days
|
46
|
+
old = (Time.now.utc - days.to_i * 24 * 60 * 60)
|
39
47
|
DB.new
|
40
|
-
|
48
|
+
delete_records DB::Device.filter{last_seen < old}.all
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete_records devs
|
52
|
+
max_del = @opts['max-delete'] ? @opts['max-delete'] : MAX_DELETE
|
41
53
|
if devs.size > max_del.to_i
|
42
54
|
puts 'Too many matching devices:'
|
43
55
|
devs.each do |dev|
|
@@ -52,6 +64,5 @@ module Corona
|
|
52
64
|
end
|
53
65
|
end
|
54
66
|
end
|
55
|
-
|
56
67
|
end
|
57
68
|
end
|
data/lib/corona/core.rb
CHANGED
@@ -19,6 +19,11 @@ module Corona
|
|
19
19
|
|
20
20
|
def initialize opts={}
|
21
21
|
cidr = opts.delete :cidr
|
22
|
+
@output = opts.delete :output
|
23
|
+
if not @output
|
24
|
+
@output = Logger.new $stdout
|
25
|
+
@output.formatter = proc { |_ ,_ ,_ , msg| msg + "\n" }
|
26
|
+
end
|
22
27
|
poll, ignores = resolve_networks cidr
|
23
28
|
@mutex = Mutex.new
|
24
29
|
@db = DB.new
|
@@ -64,7 +69,7 @@ module Corona
|
|
64
69
|
|
65
70
|
if not old_by_sysname and not old_by_ip
|
66
71
|
# all new device
|
67
|
-
|
72
|
+
@output.info "ptr [%s] sysName [%s] ip [%s]" % [record[:ptr], record[:oid_sysName], record[:ip]]
|
68
73
|
Log.info "#{record[:ip]} added"
|
69
74
|
@db.add record
|
70
75
|
|