dns_one 0.4.58 → 0.4.59

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: 49a375ba0d00d988d0896ad81ee8abe5708dfe73
4
- data.tar.gz: 708b5e4145684b5da2f11d0e9d536e2b3502029c
3
+ metadata.gz: 9f7aff37d7886eb30db71113afa0e7eb6fe5bb8a
4
+ data.tar.gz: 896af67a899b60acde6bc43a71a5830ccdeed3bf
5
5
  SHA512:
6
- metadata.gz: 75e4535b90cf3e394476309ad03f88df039708fe521503ac6228fd8b433fff839cd730835207fd60dbcdd52ea8ce0fbb1caf982f6f7619491c5a3796bcdd42b5
7
- data.tar.gz: 36902a2b7a18d68371983e7c9ee36ad7dd0122f71b63f869d3d23824fe721debeecf2c78876f3db9d238184466e0b4cd98b2d3799f23431ff331e07b43afad6b
6
+ metadata.gz: bdb9fd6536e5a3a808320e6fc56481e77610a0838852e0d3bc14cb0f65d5acf78b3dc224b1dcf7c3fb307e28a05a6bf31d8a09863513e3f9ceed69096907d8a3
7
+ data.tar.gz: cb5f9daf3bfd0fc324662239587bd7fab045b3f781559f7b413d059e99ed2dda9f719ddea20ca2b1b5f4f8501d126485fc16290ddfd8f626dee673ad55ff675f
@@ -4,6 +4,7 @@ require "dns_one/zone_search"
4
4
  module DnsOne; class Server
5
5
 
6
6
  DEFAULT_RUN_AS = "dnsone"
7
+ DEFAULT_LOG_RESULT_SOCKET_FILE = '/tmp/dns_one_log_result.sock'
7
8
 
8
9
  DNS_DAEMON_INTERFACES = [
9
10
  [:udp, "0.0.0.0", 53],
@@ -15,12 +16,20 @@ module DnsOne; class Server
15
16
  def initialize conf, conf_zone_search
16
17
  @conf = conf
17
18
  @zone_search = ZoneSearch.instance.setup conf_zone_search
19
+ if conf[:log_result_socket]
20
+ @log_result_mutex = Mutex.new
21
+ launch_log_result_socket
22
+ end
18
23
  end
19
24
 
20
25
  def run
21
26
  zone_search = @zone_search
22
27
  conf = @conf
23
28
  stat = nil
29
+ if conf[:log_result_socket]
30
+ log_result = @log_result
31
+ log_result_mutex = @log_result_mutex
32
+ end
24
33
 
25
34
  RubyDNS::run_server(listen: dns_daemon_interfaces, logger: Log.ruby_dns_logger) do
26
35
  on(:start) do
@@ -69,6 +78,25 @@ module DnsOne; class Server
69
78
  Util.log_result ip_address, domain_name, t.resource_class, rcode, resp_log, from_cache
70
79
  end
71
80
 
81
+ if conf[:log_result_socket]
82
+ log_result_mutex.synchronize {
83
+ log_result[:requests] ||= 0
84
+ log_result[:requests] += 1
85
+
86
+ log_result[:cache] ||= 0
87
+ log_result[:cache] += 1 if from_cache
88
+
89
+ log_result[:rcode] ||= {}
90
+ log_result[:rcode][rcode] ||= 0
91
+ log_result[:rcode][rcode] += 1
92
+
93
+ req_resource = Util.last_mod t.resource_class
94
+ log_result[:req_resource] ||= {}
95
+ log_result[:req_resource][req_resource] ||= 0
96
+ log_result[:req_resource][req_resource] += 1
97
+ }
98
+ end
99
+
72
100
  raise e if e
73
101
  end
74
102
 
@@ -93,4 +121,30 @@ module DnsOne; class Server
93
121
  end
94
122
  end
95
123
 
124
+ def launch_log_result_socket
125
+ log_result = @log_result
126
+ log_result_mutex = @log_result_mutex
127
+ sock = Thread.new do
128
+ Socket.unix_server_loop(conf[:log_result_socket_file] || DEFAULT_LOG_RESULT_SOCKET_FILE) do |sock, addr|
129
+ Log.i "opened unix socket #{sock}"
130
+ Thread.new do
131
+ loop do
132
+ begin
133
+ log_result_mutex.synchronize {
134
+ sock.write "#{ log_result.to_json }\n"
135
+ }
136
+ rescue Errno::EPIPE => e
137
+ break
138
+ rescue => e
139
+ Log.e e
140
+ break
141
+ end
142
+ Thread.pass
143
+ sleep 0.1
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+
96
150
  end; end
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.58"
2
+ VERSION = "0.4.59"
3
3
  end
data/lib/dns_one.rb CHANGED
@@ -64,9 +64,10 @@ module DnsOne; class DnsOne
64
64
  work_dir: conf[:config][:work_dir]
65
65
  },
66
66
  server: {
67
- run_as: conf[:config][:run_as],
68
- log_results: (conf[:config][:log_results] == '1'),
69
- save_stats: (conf[:config][:save_stats] == '1')
67
+ run_as: conf[:config][:run_as],
68
+ log_results: (conf[:config][:log_results] == '1'),
69
+ save_stats: (conf[:config][:save_stats] == '1'),
70
+ log_result_socket_file: (conf[:config][:log_result_socket_file] == '1')
70
71
  },
71
72
  zone_search: {
72
73
  ignore_subdomains: conf[:config][:ignore_subdomains],
data/util/sample_conf.yml CHANGED
@@ -6,6 +6,8 @@ config:
6
6
  # log_file: /var/log/dns_one.log # optional, defaults to /var/log/dns_one.log
7
7
  log_results: 0
8
8
  save_stats: 0
9
+ log_result_socket: 1
10
+ # log_result_socket_file: /tmp/dns_one_log_result.sock
9
11
 
10
12
  backend:
11
13
  ##############
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.58
4
+ version: 0.4.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato