dns_one 0.4.30 → 0.4.31

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: 5bd90da7f26c043c1061527a8d6c317b323a1d63
4
- data.tar.gz: 594f84fea313f5092620752731e463bb5b40562c
3
+ metadata.gz: 86b8305fbb1e6d4c2eec401c5b67ace08e282c2b
4
+ data.tar.gz: 4cf1e386c035351ba310619da3221df4ba7bd212
5
5
  SHA512:
6
- metadata.gz: aafba801a40a381693c2fb347668dae193323084ce98af5fc6e424f65ba2a50d37e9f8cba27174970a765ec0d67e4ecdb07a6ecbf3c799f2b7287219cd2c82b3
7
- data.tar.gz: d1f868608bd2267eb2451aee3af246f56f2b958a7d15cbe7773eaf2a6bf412892ce621033cd23560daf554c13b99fda7889d30b646b761ccead708287e964f69
6
+ metadata.gz: 536fb7c338ac4ea364a86601c5c9292e20150306b733b7d7992172a252b5cd84079828d42c755a420fa724cdf22249f7465df1eb73923ed14803feddeec6dce3
7
+ data.tar.gz: 8c15909797901a1ac9e88482faeca08e70d6d57ea25334d07aaab878011f0bf0776f207492a310927886c229bb57212facfcb2294ac521b1c7cbf1955ea35cfb
data/.gitignore CHANGED
@@ -13,4 +13,7 @@
13
13
 
14
14
  dev_conf.yml
15
15
 
16
- *.gem
16
+ *.gem
17
+
18
+ stat.db
19
+ test.db
data/lib/dns_one/cli.rb CHANGED
@@ -3,7 +3,6 @@ require "thor"
3
3
  require 'sqlite3'
4
4
  require "dns_one"
5
5
  require "dns_one/setup"
6
- require "dns_one/stat"
7
6
 
8
7
  class DnsOne::CLI < Thor
9
8
 
@@ -59,11 +58,6 @@ class DnsOne::CLI < Thor
59
58
 
60
59
  desc "stats", "show counters"
61
60
  def stats
62
- stat = DnsOne::Stat.new(db_file: 'stat.db')
63
- [
64
- stat.get_counts(:rcode),
65
- stat.get_counts(:req_resource),
66
- stat.get_counts(:cache)
67
- ]
61
+ DnsOne::Stat.print
68
62
  end
69
63
  end
@@ -15,7 +15,7 @@ module DnsOne; class Server
15
15
  def initialize conf, conf_zone_search
16
16
  @conf = conf
17
17
  @zone_search = ZoneSearch.instance.setup conf_zone_search
18
- @stat = Stat.new(db_file: 'stat.db')
18
+ @stat = Stat.new
19
19
  end
20
20
 
21
21
  def run
@@ -30,6 +30,7 @@ module DnsOne; class Server
30
30
  RExec.change_user run_as
31
31
  end
32
32
  Log.i "Running as #{RExec.current_user}"
33
+ File.chown DnsOne::DnsOne::STAT_DB, RExec.current_user
33
34
  end
34
35
 
35
36
  match(/(.+)/) do |t| # transaction
data/lib/dns_one/setup.rb CHANGED
@@ -64,6 +64,7 @@ module DnsOne; class Setup
64
64
  def mkdirs
65
65
  FileUtils.mkdir_p DnsOne::CONF_DIR
66
66
  FileUtils.mkdir_p DnsOne::WORK_DIR
67
+ File.chmod 0755, DnsOne::WORK_DIR
67
68
  end
68
69
 
69
70
  def setup_finished_msg
data/lib/dns_one/stat.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  module DnsOne; class Stat
2
+ DB_FNAME = "stat.db"
2
3
 
3
4
  def initialize conf = {}
4
5
  @conf = conf
6
+
7
+ # Setup logger and current working dir
8
+ DnsOne.new
9
+
5
10
  ensure_db
6
11
  end
7
12
 
@@ -42,6 +47,49 @@ module DnsOne; class Stat
42
47
  counts
43
48
  end
44
49
 
50
+ def self.print
51
+ stat = new(db_file: DnsOne::DnsOne::STAT_DB, readonly: true)
52
+ %w(rcode req_resource cache).each do |key|
53
+ puts "--- #{key} ---"
54
+ stat.get_counts(key.to_sym).each_pair do |k, v|
55
+ _k = case key
56
+ when 'rcode'
57
+ stat.rcodes[k]
58
+ when 'req_resource'
59
+ stat.request_resources[k]
60
+ when 'cache'
61
+ k == 0 ? :miss : :hit
62
+ end
63
+ puts "#{_k || k}\t#{v}"
64
+ end
65
+ end
66
+ end
67
+
68
+ def rcodes
69
+ unless defined? @@rcodes
70
+ @@rcodes = Hash[
71
+ Resolv::DNS::RCode.constants.map{|c|
72
+ [
73
+ Resolv::DNS::RCode.const_get(c),
74
+ const_underscore(c)
75
+ ]
76
+ }
77
+ ]
78
+ end
79
+ @@rcodes
80
+ end
81
+
82
+ def request_resources
83
+ unless defined? @@request_resources
84
+ @@request_resources = {}
85
+ %w(A AAAA ANY CNAME HINFO MINFO MX NS PTR SOA TXT WKS).each do |res|
86
+ val = Object.const_get("Resolv::DNS::Resource::IN::#{res}")::TypeValue
87
+ @@request_resources[val] = res.downcase
88
+ end
89
+ end
90
+ @@request_resources
91
+ end
92
+
45
93
  private
46
94
 
47
95
  def validate_counter counter
@@ -64,8 +112,16 @@ module DnsOne; class Stat
64
112
 
65
113
  def ensure_db
66
114
  new_db = !File.exists?(db_file)
67
- @db = SQLite3::Database.new db_file
68
- create_tables if new_db
115
+
116
+ opts = {}
117
+ opts[:readonly] = true if @conf[:readonly]
118
+
119
+ @db = SQLite3::Database.new db_file, opts
120
+
121
+ if new_db
122
+ File.chmod 0644, db_file
123
+ create_tables
124
+ end
69
125
  end
70
126
 
71
127
  def create_tables
@@ -80,20 +136,16 @@ module DnsOne; class Stat
80
136
  );
81
137
  SQL
82
138
 
83
- sqls << <<-SQL
84
- CREATE INDEX responses_time ON responses (time);
85
- SQL
86
-
87
- sqls << <<-SQL
88
- CREATE INDEX responses_rcode ON responses (rcode);
139
+ sqls << <<-SQL
140
+ CREATE INDEX responses_time_rcode ON responses (time, rcode);
89
141
  SQL
90
142
 
91
- sqls << <<-SQL
92
- CREATE INDEX responses_req_resource ON responses (req_resource);
143
+ sqls << <<-SQL
144
+ CREATE INDEX responses_time_req_resource ON responses (time, req_resource);
93
145
  SQL
94
146
 
95
- sqls << <<-SQL
96
- CREATE INDEX responses_cache ON responses (cache);
147
+ sqls << <<-SQL
148
+ CREATE INDEX responses_time_cache ON responses (time, cache);
97
149
  SQL
98
150
 
99
151
  sqls.each{|sql| @db.execute sql }
@@ -101,18 +153,7 @@ module DnsOne; class Stat
101
153
 
102
154
 
103
155
  def db_file
104
- @conf[:db_file]
105
- end
106
-
107
- def request_resources
108
- unless defined? @@request_resources
109
- @@request_resources = {}
110
- %w(A AAAA ANY CNAME HINFO MINFO MX NS PTR SOA TXT WKS).each do |res|
111
- val = Object.const_get("Resolv::DNS::Resource::IN::#{res}")::TypeValue
112
- @@request_resources[val] = res.downcase
113
- end
114
- end
115
- @@request_resources
156
+ DB_FNAME
116
157
  end
117
158
 
118
159
  def const_underscore name
@@ -125,18 +166,5 @@ module DnsOne; class Stat
125
166
  name
126
167
  end
127
168
 
128
- def rcodes
129
- unless @@rcodes
130
- @@rcodes = Hash[
131
- Resolv::DNS::RCode.constants.map{|c|
132
- [
133
- Resolv::DNS::RCode.const_get(c),
134
- const_underscore(c)
135
- ]
136
- }
137
- ]
138
- end
139
- @@rcodes
140
- end
141
169
  end; end
142
170
 
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.30"
2
+ VERSION = "0.4.31"
3
3
  end
data/lib/dns_one.rb CHANGED
@@ -23,6 +23,7 @@ require "dns_one/core_ext/hash"
23
23
  require "dns_one/log"
24
24
  require "dns_one/util"
25
25
  require "dns_one/server"
26
+ require "dns_one/stat"
26
27
 
27
28
  module DnsOne; class DnsOne
28
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.30
4
+ version: 0.4.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato