Move manager logs into syslog (#1190)

This commit is contained in:
Tim Wilkinson 2024-05-05 23:11:57 -07:00 committed by GitHub
parent 9a319f08c9
commit 4b13d5969f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 118 deletions

View File

@ -1,85 +0,0 @@
--[[
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
Copyright (C) 2021 Tim Wilkinson
See Contributors file for additional contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional Terms:
Additional use restrictions exist on the AREDN(TM) trademark and logo.
See AREDNLicense.txt for more info.
Attributions to the AREDN Project must be retained in the source code.
If importing this code into a new or existing project attribution
to the AREDN project must be added to the source code.
You must not misrepresent the origin of the material contained within.
Modified versions must be modified to attribute to the original source
and be marked in reasonable ways as differentiate it from the original
version
--]]
local log = {}
log.__index = log
function log.open(name, maxsize)
local l = {}
setmetatable(l, log)
l.logfile = name
l.logmax = maxsize
l.logf = nil
l.prefix = nil
return l
end
function log:write(str)
if not self.logf then
self.logf = io.open(self.logfile, "a")
end
local pstr = ""
if self.prefix then
pstr = self.prefix .. ": "
end
self.logf:write(string.format("%s: %s%s\n", os.date("%m/%d %H:%M:%S", os.time()), pstr, str))
if self.logf:seek() > self.logmax then
self:flush(true)
end
end
function log:flush(archive)
if self.logf then
self.logf:close()
self.logf = nil
if archive then
local old = self.logfile .. '.0'
if nixio.fs.stat(old) then
os.remove(old)
end
os.rename(self.logfile, old)
end
end
end
function log:close()
self:flush()
end
if not aredn then
aredn = {}
end
aredn.log = log
return log

View File

@ -41,7 +41,6 @@ require("nixio")
require("aredn.utils")
require("iwinfo")
require("aredn.hardware")
require("aredn.log")
require("aredn.olsr")
require("luci.jsonc")
require("ubus")
@ -68,8 +67,6 @@ function exit_app()
coroutine.yield('exit')
end
mainlog = aredn.log.open("/tmp/manager.log", 8000)
-- Load management tasks
local tasks = {}
for name in nixio.fs.dir("/usr/local/bin/mgr")
@ -91,11 +88,10 @@ do
for i, task in ipairs(tasks)
do
if task.time <= os.time() then
mainlog.prefix = task.name
nixio.openlog("manager." .. task.name)
local status, newdelay = coroutine.resume(task.routine)
if not status then
mainlog:write(newdelay) -- error message
mainlog:flush()
nixio.syslog("err", newdelay)
task.routine = coroutine.create(task.app)
task.time = 120 + os.time() -- 2 minute restart delay
elseif not newdelay then
@ -103,12 +99,11 @@ do
elseif newdelay == "exit" then
task.routine = null
task.time = math.huge
mainlog:write("Terminating manager task: " .. task.name)
mainlog:flush()
nixio.syslog("notice", "Terminating manager task: " .. task.name)
else
task.time = newdelay + os.time()
end
mainlog.prefix = nil
nixio.closelog()
end
end
table.sort(tasks, function(a,b) return a.time < b.time end)

View File

@ -57,7 +57,7 @@ function W.get_config(verbose)
for address in addresses:gmatch("(%S+)") do
if address:match("^%d+%.%d+%.%d+%.%d+$") then
if verbose then
mainlog:write("pinging " .. address)
nixio.syslog("debug", "pinging " .. address)
end
ping_addresses[#ping_addresses + 1] = address
end
@ -67,7 +67,7 @@ function W.get_config(verbose)
local mydaemons = c:get("aredn", "@watchdog[0]", "daemons") or default_daemons
for daemon in mydaemons:gmatch("(%S+)") do
if verbose then
mainlog:write("monitor " .. daemon)
nixio.syslog("debug", "monitor " .. daemon)
end
daemons[#daemons + 1] = daemon
end
@ -101,7 +101,7 @@ function W.start()
local wd = io.open("/dev/watchdog", "w")
if not wd then
mainlog:write("Watchdog failed to start: Cannot open /dev/watchdog\n")
nixio.syslog("err", "Watchdog failed to start: Cannot open /dev/watchdog\n")
ub:call("system", "watchdog", { stop = false })
exit_app()
return
@ -124,7 +124,7 @@ function W.start()
if time.min >= 55 and (time.hour + 1) % 24 == config.daily then
daily_reboot_armed = true
elseif daily_reboot_armed and time.hour == config.daily then
mainlog:write("reboot")
nixio.syslog("notice", "reboot")
os.execute(REBOOT .. " >/dev/null 2>&1")
daily_reboot_armed = false
else
@ -138,7 +138,7 @@ function W.start()
for _, daemon in ipairs(config.daemons)
do
if os.execute(PIDOF .. " " .. daemon .. " > /dev/null ") ~= 0 then
mainlog:write("pidof " .. daemon .. " failed")
nixio.syslog("err", "pidof " .. daemon .. " failed")
success = false
break
end
@ -156,7 +156,7 @@ function W.start()
success = true
break
else
mainlog:write("ping " .. address .. " failed")
nixio.syslog("err", "ping " .. address .. " failed")
end
end
if not success then
@ -169,7 +169,7 @@ function W.start()
wd:write("1")
wd:flush()
else
mainlog:write("failed")
nixio.syslog("err", "failed")
end
wait_for_ticks(math.max(0, tick - (os.time() - now)))

View File

@ -81,23 +81,17 @@ if boardid:match("mikrotik") and boardid:match("ac") then
mikrotik_ac = true
end
local logfile = "/tmp/wireless_monitor.log"
if not file_exists(logfile) then
io.open(logfile, "w+"):close()
end
local log = aredn.log.open(logfile, 8000)
-- Various forms of network resets --
function M.reset_network(mode)
log:write("reset_network: " .. mode)
nixio.syslog("notice", "reset_network: " .. mode)
if mode == "rejoin" then
-- Only observered on Mikrotik AC devices
if mikrotik_ac then
os.execute(IW .. " " .. wifi .. " ibss leave > /dev/null 2>&1")
os.execute(IW .. " " .. wifi .. " ibss join " .. ssid .. " " .. frequency .. " fixed-freq > /dev/null 2>&1")
else
log:write("-- ignoring (mikrotik ac only)")
nixio.syslog("notice", "-- ignoring (mikrotik ac only)")
end
elseif mode == "scan-quick" then
os.execute(IW .. " " .. wifi .. " scan freq " .. frequency .. " > /dev/null 2>&1")
@ -105,7 +99,7 @@ function M.reset_network(mode)
os.execute(IW .. " " .. wifi .. " scan > /dev/null 2>&1")
os.execute(IW .. " " .. wifi .. " scan passive > /dev/null 2>&1")
else
log:write("-- unknown")
nixio.syslog("err", "-- unknown")
end
end
@ -148,7 +142,7 @@ function M.monitor_unresponsive_stations()
unresponsive.stations[ipaddr] = val
if val < unresponsive.ignore then
if val > action_limits.unresponsive_report then
log:write("Possible unresponsive node: " .. ipaddr .. " [" .. mac .. "]")
nixio.syslog("err", "Possible unresponsive node: " .. ipaddr .. " [" .. mac .. "]")
end
if val > unresponsive.max then
unresponsive.max = val
@ -265,8 +259,7 @@ function M.start_monitor()
frequency = iwinfo.nl80211.frequency(wifi)
ssid = iwinfo.nl80211.ssid(wifi)
if not (phy and frequency and ssid) then
log:write("Startup failed")
log:flush()
nixio.syslog("err", "Startup failed")
exit_app()
return
end
@ -281,7 +274,7 @@ function M.start_monitor()
return
end
log:write("Monitoring wireless chipset: " .. chipset)
nixio.syslog("notice", "Monitoring wireless chipset: " .. chipset)
M.reset_network("rejoin")
@ -290,7 +283,6 @@ function M.start_monitor()
M.run_monitors()
M.run_actions()
M.save()
log:flush()
wait_for_ticks(60) -- 1 minute
end
end

View File

@ -60,13 +60,10 @@ local files = {
"/tmp/rssi_ath10k.log",
"/tmp/station_monitor.log",
"/tmp/olsrd.log",
"/tmp/manager.log",
"/tmp/manager.log.0",
"/tmp/dnsmasq.d/",
"/tmp/AutoDistReset.log",
"/tmp/lqm.info",
"/tmp/wireless_monitor.info",
"/tmp/wireless_monitor.log",
"/tmp/sysinfo/board_name",
"/tmp/sysinfo/boardid",
"/tmp/sysinfo/hardware_mfg",