dns_one 0.4.41 → 0.4.42

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: 2805a586bb24e693a6bcd96a71b3c6624c2e7522
4
- data.tar.gz: 809f9ee00f0b0b44c891a35a56f113bdb39e8c82
3
+ metadata.gz: 720e329fe952ba684c4e6001246b8b238dd00d06
4
+ data.tar.gz: e9a0cfe54c495ecb29c34215fe76f8eb1a4b7f21
5
5
  SHA512:
6
- metadata.gz: c3b7b3ea1cf801beceb0c57d301e52de456a54d1857aaab3f5d617027e6ab450ed5a99f7c985e81e2e5164d48dfcf14a5ff4f7f07bc846eb2fea3e65ce2c7cdf
7
- data.tar.gz: 13e4d4318b16d309db3e1cc5bec5a0d50bc6fe22c66e6ff827be2cc1171828b562013cbe6d4fe9350c83a9a19ab24e44e8f65742b12c9c4d08de03df871ea8ae
6
+ metadata.gz: 98905e1e4e821f5261d526b2b3e5bf386622dc601dc0a4b86b6896a04f0756cc2d62b81f269ace6816fef6ec84dd4d502d829e31fd535e96dca6f9b8ef5c4bf7
7
+ data.tar.gz: a0442761bcfb01eae650db2c9d9121a6854f545ac80116a93750eeb990921372a561dec99c0dd24783a121430ab5ae2ca119c2f4bf78ef3dd929605740ab0ef2
@@ -27,16 +27,12 @@ require "dns_one/stat"
27
27
 
28
28
  module DnsOne; class DnsOne
29
29
 
30
- DEFAULT_LOG_FILE = "/var/log/dns_one.log"
31
30
  DEFAULT_CONF_FILE = '/etc/dns_one/conf.yml'
32
31
  WORK_DIR = "/var/local/dns_one"
33
32
  CONF_DIR = "/etc/dns_one"
34
- SYSLOG_NAME = 'dns_one'
35
33
 
36
- def initialize conf_file: nil, log_file: nil, work_dir: nil
37
- cmd_log_file = log_file
38
- log_file ||= DEFAULT_LOG_FILE
39
- Log.setup log_file, SYSLOG_NAME
34
+ def initialize conf_file: nil, work_dir: nil
35
+ Log.setup
40
36
 
41
37
  conf_file ||= DEFAULT_CONF_FILE
42
38
  @conf_all = parse_conf conf_file
@@ -44,15 +40,6 @@ module DnsOne; class DnsOne
44
40
 
45
41
  work_dir ||= WORK_DIR
46
42
 
47
- # Redefine log file if set in conf file
48
- unless cmd_log_file
49
- if f = @conf[:log_file].presence
50
- unless Log.change_log_file f
51
- Log.w "Unable to change logfile to #{f}. Will continue with #{Log.log_file_desc}."
52
- end
53
- end
54
- end
55
-
56
43
  begin
57
44
  Dir.chdir work_dir
58
45
  rescue => e
@@ -74,8 +61,7 @@ module DnsOne; class DnsOne
74
61
 
75
62
  OpenStruct.new(
76
63
  main: {
77
- work_dir: conf[:config][:work_dir],
78
- log_file: conf[:config][:log_file]
64
+ work_dir: conf[:config][:work_dir]
79
65
  },
80
66
  server: {
81
67
  run_as: conf[:config][:run_as]
@@ -12,12 +12,10 @@ class DnsOne::CLI < Thor
12
12
 
13
13
  desc "run", "run server"
14
14
  option :conf
15
- option :log
16
15
  option :work_dir
17
16
  def run_srv
18
17
  DnsOne::DnsOne.new(
19
18
  conf_file: options[:conf],
20
- log_file: options[:log],
21
19
  work_dir: options[:work_dir]
22
20
  ).start
23
21
  end
@@ -1,5 +1,7 @@
1
1
 
2
2
  class Log < Logger
3
+ SYSLOG_MIN_SEVERITY = Logger::WARN
4
+
3
5
  class << self
4
6
 
5
7
  # 'def [d|i|w|e|f] msg' for DEBUG INFO WARN ERROR FATAL
@@ -11,19 +13,17 @@ class Log < Logger
11
13
  end
12
14
  end
13
15
 
14
- def setup file, syslog_name, syslog_min_severity = Logger::WARN
15
- @syslog_min_severity = syslog_min_severity
16
- @syslog = Syslog::Logger.new syslog_name
17
- @log_file = setfile file
16
+ def setup
17
+ @syslog = Syslog::Logger.new "dns_one"
18
+ @log_file = setfile "/var/log/dns_one.log"
18
19
  @logger = Logger.new @log_file
20
+ @logger.level = Logger::INFO
19
21
  end
20
22
 
21
- def change_log_file file
22
- new_log_file = setfile file, allow_stdout: false
23
- if new_log_file and new_log_file != @log_file
24
- @log_file = new_log_file
25
- @logger = Logger.new @log_file
26
- end
23
+ def ruby_dns_logger
24
+ l = Logger.new setfile("/var/log/dns_one_rubydns.log")
25
+ l.level = Logger::WARN
26
+ l
27
27
  end
28
28
 
29
29
  def exc e
@@ -47,13 +47,11 @@ class Log < Logger
47
47
 
48
48
  private
49
49
 
50
- def setfile file, allow_stdout: true
51
- if [STDOUT, STDERR].include? file or
52
- File.writable? file or
53
- File.writable? File.dirname(file)
50
+ def setfile file
51
+ if File.writable?(file) or File.writable?(File.dirname(file))
54
52
  file
55
- elsif allow_stdout
56
- STDOUT
53
+ else
54
+ STDERR
57
55
  end
58
56
  end
59
57
 
@@ -62,7 +60,7 @@ class Log < Logger
62
60
 
63
61
  @logger.send met_name, msg
64
62
 
65
- if severity >= @syslog_min_severity
63
+ if severity >= SYSLOG_MIN_SEVERITY
66
64
  @syslog.send met_name, msg
67
65
  end
68
66
 
@@ -22,7 +22,7 @@ module DnsOne; class Server
22
22
  conf = @conf
23
23
  stat = nil
24
24
 
25
- RubyDNS::run_server(listen: dns_daemon_interfaces, logger: Log.logger) do
25
+ RubyDNS::run_server(listen: dns_daemon_interfaces, logger: Log.ruby_dns_logger) do
26
26
  on(:start) do
27
27
  if RExec.current_user == 'root'
28
28
  run_as = conf[:run_as] || DEFAULT_RUN_AS
@@ -36,6 +36,7 @@ module DnsOne; class Server
36
36
 
37
37
  match(/(.+)/) do |t| # transaction
38
38
  rcode = :NoError
39
+ resp_log = []
39
40
 
40
41
  begin
41
42
  domain_name = t.question.to_s
@@ -48,6 +49,7 @@ module DnsOne; class Server
48
49
  t.fail! :NoError
49
50
  else
50
51
  records.each do |rec|
52
+ resp_log << rec
51
53
  t.respond! *[rec.val].flatten, {resource_class: rec.res_class, section: rec.section}
52
54
  end
53
55
  end
@@ -60,6 +62,7 @@ module DnsOne; class Server
60
62
  end
61
63
 
62
64
  stat.save rcode, t.resource_class, from_cache
65
+ Util.log_result ip_address, domain_name, t.resource_class, rcode, resp_log
63
66
 
64
67
  raise e if e
65
68
  end
@@ -1,6 +1,7 @@
1
1
  module DnsOne; class Stat
2
2
  DB_FNAME = "stat.db"
3
- SQL_PROF = false
3
+ META_STAT_ON = false
4
+ META_STAT_FILE = '/tmp/dnsone_sql_prof.log'
4
5
 
5
6
  def initialize conf = {}
6
7
  @conf = conf
@@ -12,7 +13,7 @@ module DnsOne; class Stat
12
13
  end
13
14
 
14
15
  def save rcode, req_resource, cache
15
- Log.i "saving stat (user: #{ `id -un #{Process.uid}`.strip })"
16
+ Log.d "saving stat (user: #{ `id -un #{Process.uid}`.strip })"
16
17
  rsql(
17
18
  "INSERT INTO responses (time, rcode, req_resource, cache) VALUES (?, ?, ?, ?)",
18
19
  [
@@ -159,21 +160,19 @@ module DnsOne; class Stat
159
160
  end
160
161
 
161
162
  def rsql *sql
162
- if SQL_PROF
163
- t0 = Time.now
164
- end
165
-
163
+ t0 = Time.now if META_STAT_ON
166
164
  res = @db.execute *sql
165
+ meta_stats t0, sql if META_STAT_ON
166
+ res
167
+ end
167
168
 
168
- if SQL_PROF
169
- @sql_profiler ||= Logger.new '/tmp/dnsone_sql_prof.log'
170
- time = Time.now.strftime '%y%m%d-%H%M%S.%L'
171
- dur = "%.3f" % ((Time.now - t0) * 1000.0)
172
- _sql = [sql].flatten[0].gsub /\n+/, ' '
173
- @sql_profiler.info "#{time} #{dur} #{_sql}"
174
- end
169
+ def meta_stats t0, sql
170
+ time = Time.now.strftime '%y%m%d-%H%M%S.%L'
171
+ dur = "%.3f" % ((Time.now - t0) * 1000.0)
172
+ sql = [sql].flatten[0].gsub /\s+/, ' '
175
173
 
176
- res
174
+ @meta_stats_log ||= Logger.new META_STAT_FILE
175
+ @meta_stats_log.info "#{time} #{dur} #{sql}"
177
176
  end
178
177
 
179
178
  end; end
@@ -30,4 +30,22 @@ module DnsOne; class Util; class << self
30
30
  constant.to_s.split('::').last
31
31
  end
32
32
 
33
+ def log_result ip_address, domain_name, res_class, rcode, resp_log
34
+ fields = []
35
+
36
+ fields << domain_name
37
+ fields << Util.last_mod(res_class)
38
+ fields << rcode
39
+ fields << resp_log.map{ |rec|
40
+ Util.last_mod(rec.res_class) +
41
+ ':' +
42
+ [rec.val].flatten.join(',')
43
+ }.join(';')
44
+ fields << ip_address
45
+
46
+ fields.map!{|v| v.blank? ? '-' : v}
47
+
48
+ Log.i "result: #{ fields.join ' ' }"
49
+ end
50
+
33
51
  end; end; end
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.41"
2
+ VERSION = "0.4.42"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.41
4
+ version: 0.4.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler