Select messages to show (IPC, DNSMANAGERd).

This commit is contained in:
Philippe Pittoli 2024-12-12 20:29:04 +01:00
parent 566581139a
commit 30d5f1d4a3
4 changed files with 48 additions and 17 deletions

View File

@ -34,14 +34,8 @@ accepted_domains:
#verbosity: 4 # [0-4], “0” being quiet and “4” meaning printing debug values #verbosity: 4 # [0-4], “0” being quiet and “4” meaning printing debug values
# IPC-related variables. By default, only print errors and exceptions. # By default, print everything except KEEPALIVE messages.
#print_ipc_timer: false #messages_to_mask: [KEEPALIVE]
#print_ipc_connection: false
#print_ipc_disconnection: false # IPC-related messages. By default, only print errors and exceptions.
#print_ipc_extra_socket: false #ipc_messages_to_show: [ERROR, EXCEPTION]
#print_ipc_message_received: false
#print_ipc_message_sent: false
#print_ipc_switch: false
#print_ipc_error: true
#print_ipc_exception: true
#print_keepalive: false

View File

@ -16,6 +16,13 @@ class Baguette::Configuration
# See tools/write-template-zone-file.cr # See tools/write-template-zone-file.cr
property template_directory : String = "/etc/dnsmanager/templates" property template_directory : String = "/etc/dnsmanager/templates"
# Handle messages to display and to mask.
# Messages to mask, to focus on what is important.
property messages_to_mask : Array(DNSMESSAGE) = [DNSMESSAGE::KEEPALIVE]
# Path to the log file. No log file = just print everything.
property log_file : String? = nil
def initialize def initialize
end end
end end

View File

@ -112,5 +112,9 @@ unless configuration.pass
exit 1 exit 1
end end
if path = configuration.log_file
Baguette::Log.log_path = path
end
service = DNSManager::Service.new configuration service = DNSManager::Service.new configuration
service.run service.run

View File

@ -4,6 +4,24 @@ require "baguette-crystal-base"
require "./config" require "./config"
require "./exceptions" require "./exceptions"
class Array(T)
def contains?(value : T)
(self.select { |x| x == value }).size > 0
end
end
# WIP: select (dynamically) messages to mask
module DNSManager
enum MESSAGE
KEEPALIVE
# TODO
end
end
alias IPCMESSAGE = Baguette::Configuration::IPC::MESSAGE
alias DNSMESSAGE = DNSManager::MESSAGE
class DNSManager::Service < IPC class DNSManager::Service < IPC
property configuration : Baguette::Configuration::DNSManager property configuration : Baguette::Configuration::DNSManager
getter storage : DNSManager::Storage getter storage : DNSManager::Storage
@ -11,6 +29,14 @@ class DNSManager::Service < IPC
property authd : AuthD::Client property authd : AuthD::Client
def should_display?(value : DNSMESSAGE)
(@configuration.messages_to_mask.select { |x| x == value }).size == 0
end
def should_display?(value : IPCMESSAGE)
@configuration.ipc_messages_to_show.contains? value
end
def initialize(@configuration) def initialize(@configuration)
super() super()
@storage = DNSManager::Storage.new @configuration.storage_directory, @configuration.recreate_indexes @storage = DNSManager::Storage.new @configuration.storage_directory, @configuration.recreate_indexes
@ -128,7 +154,7 @@ class DNSManager::Service < IPC
if response.is_a? DNSManager::Response::Error if response.is_a? DNSManager::Response::Error
Baguette::Log.warning "fd #{"%4d" % event.fd} (#{duration}) #{reqname} >> #{response_name} (#{response.reason})" Baguette::Log.warning "fd #{"%4d" % event.fd} (#{duration}) #{reqname} >> #{response_name} (#{response.reason})"
else else
if reqname != "KeepAlive" || @configuration.print_keepalive if reqname != "KeepAlive" || should_display? DNSMESSAGE::KEEPALIVE
Baguette::Log.debug "fd #{"%4d" % event.fd} (#{duration}) #{reqname} >> #{response_name}" Baguette::Log.debug "fd #{"%4d" % event.fd} (#{duration}) #{reqname} >> #{response_name}"
end end
end end
@ -141,20 +167,20 @@ class DNSManager::Service < IPC
begin begin
case event.type case event.type
when LibIPC::EventType::Timer when LibIPC::EventType::Timer
Baguette::Log.debug "Timer." if @configuration.print_ipc_timer Baguette::Log.debug "Timer." if should_display? IPCMESSAGE::TIMER
when LibIPC::EventType::Connection when LibIPC::EventType::Connection
Baguette::Log.debug "New connection!" if @configuration.print_ipc_connection Baguette::Log.debug "New connection!" if should_display? IPCMESSAGE::CONNECTION
when LibIPC::EventType::Disconnection when LibIPC::EventType::Disconnection
Baguette::Log.debug "Disconnection from #{event.fd}." if @configuration.print_ipc_disconnection Baguette::Log.debug "Disconnection from #{event.fd}." if should_display? IPCMESSAGE::DISCONNECTION
@logged_users.delete event.fd @logged_users.delete event.fd
when LibIPC::EventType::MessageTx when LibIPC::EventType::MessageTx
Baguette::Log.debug "Message sent to #{event.fd}." if @configuration.print_ipc_message_sent Baguette::Log.debug "Message sent to #{event.fd}." if should_display? IPCMESSAGE::TX
when LibIPC::EventType::MessageRx when LibIPC::EventType::MessageRx
Baguette::Log.debug "Message received from #{event.fd}." if @configuration.print_ipc_message_received Baguette::Log.debug "Message received from #{event.fd}." if should_display? IPCMESSAGE::RX
handle_request event handle_request event
else else