update TODO, partially update error.c, rename module_get to modules_get, update config.lua
--
-- Helper functions
--
-- match all lines and output them as-is
local function logwatch_filter_all ()
return { pat=nil, fmt=nil }
end
-- match using a regex pattern, but output the full line
local function logwatch_filter_raw (pat)
return { pat=pat, fmt=nil }
end
-- match using a regexp pattern, and output a formatted line
local function logwatch_filter (pat, fmt)
return { pat=pat, fmt=fmt }
end
-- match auth.log sudo entries
local function logwatch_filter_sudo ()
return logwatch_filter(
"(?P<hostname>\\S+)\\s+sudo:\\s*(?P<username>\\S+) : TTY=(?P<tty>\\S+) ; PWD=(?P<pwd>.+?) ; USER=(?P<target_user>\\S+) ; COMMAND=(?P<command>.*)",
"{username}:{tty} - {target_user}@{hostname}:{pwd} - {command:r}"
)
end
--
-- Procedural config
--
local function apply_config (conf)
-- apply general
log_level(conf.log_level)
-- apply conf.name
client:set_defaults(conf.name.nickname, conf.name.username, conf.name.realname)
-- apply conf.networks
for network, settings in pairs(conf.networks) do
-- establish the irc_net
net = client:connect(network, settings.hostname)
-- join each channel
for i, channel in ipairs(settings.channels) do
net:join(channel)
end
end
-- apply conf.modules_path
if conf.modules_path then
modules:path(conf.modules_path)
end
-- apply conf.modules
for name, settings in pairs(conf.modules) do
-- load the module
module = modules:load(name, settings.path)
-- apply confs
for key, value in pairs(settings.conf) do
module:conf(key, value)
end
end
-- conf.mod_logwatch
if conf.mod_logwatch then
module = modules:load("logwatch")
for fifo_path, settings in pairs(conf.mod_logwatch) do
module:conf("source_fifo", fifo_path)
source_name = fifo_path
for filter_name, filter in pairs(settings.filters) do
module:conf("filter", filter_name, source_name, filter.pat, filter.fmt, settings.channel)
end
end
end
end
--
-- Declarative configuration settings
--
apply_config{
log_level = "DEBUG",
name = {
nickname = "SpBotDev",
username = "spbot-dev",
realname = "SpBot (development version)"
},
networks = {
PVLNet = {
hostname = "irc.fixme.fi",
channels = {
"#test"
}
},
},
modules_path = "src/modules",
modules = {
irc_log = {
conf = {
db_info = "dbname=spbot",
channel = "PVLNet/#test",
}
}
},
mod_logwatch = {
["test.fifo"] = {
channel = "PVLNet/#test",
filters = {
["test.foo"] = logwatch_filter_raw("foo"),
["test.sudo"] = logwatch_filter_sudo(),
}
},
},
}