From 5e8b0adf2a39debac8354fd98ca7d5b729580ff7 Mon Sep 17 00:00:00 2001 From: onefang Date: Mon, 23 Dec 2019 13:01:05 +1000 Subject: Major refactor, especially of the downloading and processing code. Make the code more readable, less scattered. Use a coroutine to multitask better. Plugable functions for parsing the download results, and figuring out what to download next. Track timeouts at a finer level. Dig for IPs in the forked apt-panopticons, not all at once at the beginning. Various cleanups and tweaks. --- apt-panopticommon.lua | 56 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'apt-panopticommon.lua') diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index 8d6de05..4b0be8b 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua @@ -53,7 +53,19 @@ APT.options = { typ = "number", help = "", - value = 15, + value = 5, + }, + timeouts = + { + typ = "number", + help = "", + value = 3, + }, + retries = + { + typ = "number", + help = "", + value = 3, }, reports = { @@ -290,14 +302,16 @@ local log = function(v, t, s, prot, test, host) t = t .. "(" .. x .. ")" if "" ~= prot then if "" == test then - if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0} end + if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0; timeouts = 0} end if v == 0 then APT.results[prot].errors = APT.results[prot].errors + 1 end if v == 1 then APT.results[prot].warnings = APT.results[prot].warnings + 1 end + if v == 2 then APT.results[prot].timeouts = APT.results[prot].timeouts + 1 end else - if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0} end - if nil == APT.results[prot][test] then APT.results[prot][test] = {errors = 0; warnings = 0} end + if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0; timeouts = 0} end + if nil == APT.results[prot][test] then APT.results[prot][test] = {errors = 0; warnings = 0; timeouts = 0} end if v == 0 then APT.results[prot][test].errors = APT.results[prot][test].errors + 1 end if v == 1 then APT.results[prot][test].warnings = APT.results[prot][test].warnings + 1 end + if v == 2 then APT.results[prot][test].timeouts = APT.results[prot][test].timeouts + 1 end end end end @@ -311,8 +325,9 @@ local log = function(v, t, s, prot, test, host) if -1 == v then colour = "fuchsia" end -- CRITICAL if 0 == v then colour = "red " end -- ERROR if 1 == v then colour = "yellow " end -- WARNING - if 2 == v then colour = "white " end -- INFO - if 3 == v then colour = "gray " end -- DEBUG + if 2 == v then colour = "blue " end -- TIMEOUT + if 3 == v then colour = "white " end -- INFO + if 4 == v then colour = "gray " end -- DEBUG APT.logFile:write(os.date() .. " " .. t .. ": " .. s .. "
\n") else APT.logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") @@ -320,13 +335,15 @@ local log = function(v, t, s, prot, test, host) APT.logFile:flush() end end -APT.D = function(s) log(3, "DEBUG ", s) end -APT.I = function(s) log(2, "INFO ", s) end +APT.D = function(s) log(4, "DEBUG ", s) end +APT.I = function(s) log(3, "INFO ", s) end +APT.T = function(s, p, t, h) log(2, "TIMEOUT ", s, p, t, h) end APT.W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end APT.E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end APT.C = function(s) log(-1, "CRITICAL", s) end local D = APT.D local I = APT.I +local T = APT.T local W = APT.W local E = APT.E local C = APT.C @@ -380,7 +397,7 @@ APT.checkFile = function(f) if nil == h then return false else h:close(); return true end end -APT.plurals = function(e, w) +APT.plurals = function(e, w, t) local result = "" if 1 == e then result = e .. " error" @@ -397,18 +414,29 @@ APT.plurals = function(e, w) end if ("" ~= result) and APT.html then result = "" .. result .. "" end end + if 0 < t then + if (0 < e) or (0 < w) then result = result .. ", " end + if 1 == t then + result = result .. t .. " timeout" + else + result = result .. t .. " timeouts" + end + if ("" ~= result) and APT.html then result = "" .. result .. "" end + end if "" ~= result then result = " (" .. result .. ")" end return result end APT.padResults = function(results) + local c = 0 + if nil == results then results = {}; c = 999 end for k, v in pairs(APT.protocols) do tests = results[v] - if nil == tests then tests = {errors = 0; warnings = 0} end - if nil == tests.Integrity then tests.Integrity = {errors = 0; warnings = 0} end - if nil == tests.Protocol then tests.Protocol = {errors = 0; warnings = 0} end - if nil == tests.Updated then tests.Updated = {errors = 0; warnings = 0} end - if nil == tests.URLSanity then tests.URLSanity = {errors = 0; warnings = 0} end + if nil == tests then tests = {errors = c; warnings = c; timeouts = c} end + if nil == tests.Integrity then tests.Integrity = {errors = c; warnings = c; timeouts = c} end + if nil == tests.Protocol then tests.Protocol = {errors = c; warnings = c; timeouts = c} end + if nil == tests.Updated then tests.Updated = {errors = c; warnings = c; timeouts = c} end + if nil == tests.URLSanity then tests.URLSanity = {errors = c; warnings = c; timeouts = c} end results[v] = tests end if nil == results.timeout then results.timeout = false end -- cgit v1.1