corona 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8a730fb90e6e3cb07e7ec195ecac7473a40a2fd
4
- data.tar.gz: 3f8d44209ae05c40c6276f6f241a3252842ee4c4
3
+ metadata.gz: 05542efc8878a1c42874c4a0fb32badca922a9b5
4
+ data.tar.gz: 0758f35f168258f9c9db2f98eb5855517fbfbbbc
5
5
  SHA512:
6
- metadata.gz: f44d1f153235dff6f0da01527abde190c4ee2591e2f44ea0e3f08072c653d0928dd156ea1ec065d559955277bd5a5401524eb264c1109948b080cd950977d857
7
- data.tar.gz: 010693ac9b69c6691f707ecb8cbe5534a0709413238a95f420ce7ff5cfe5da3ef01df649296075a76099ea0292205113633fce0a0023af822286b8bcbc581695
6
+ metadata.gz: f47ae73a9939219ea5cb37314d64b5a9c826d6822eef1246f9061a0e97150c8f2ed266aeb2981b87991b30972fcfd1b9241412f2755e78794f4f29900bdfec8c
7
+ data.tar.gz: 37e81fa4f1bf58cb8867945409b13f498540169a5899a96c94d59af26e3e77143ed9b58dd314bab8d21442bd258993f403804ab9771cc6b27f3e49cbeb4e9bd3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- corona (0.0.9)
4
+ corona (0.0.10)
5
5
  sequel
6
6
  slop
7
7
  snmp
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.9'
3
+ s.version = '0.0.10'
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
@@ -8,7 +8,9 @@ module Corona
8
8
  if @opts[:poll]
9
9
  Corona.new :cidr=>@opts[:poll]
10
10
  elsif @opts[:remove]
11
- remove_from_db @opts[:remove]
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 detel, default #{MAX_DELETE}"
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 remove_from_db name
38
- max_del = @opts['max-delete'] ? @opts['max-delete'] : MAX_DELETE
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
- devs = DB::Device.filter(Sequel.like(:ptr, "%#{name}%")).all
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
- puts "ptr [%s] sysName [%s] ip [%s]" % [record[:ptr], record[:oid_sysName], record[:ip]]
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti