From f5476bd4cf1e54487b4b902778048cf219838234 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 13 Nov 2019 23:48:42 +1000 Subject: Count the errors / warnings in the log files, and mention them on the web page. --- apt-panopticon-report-web.lua | 99 ++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 43 deletions(-) (limited to 'apt-panopticon-report-web.lua') diff --git a/apt-panopticon-report-web.lua b/apt-panopticon-report-web.lua index 5968972..35c61dc 100755 --- a/apt-panopticon-report-web.lua +++ b/apt-panopticon-report-web.lua @@ -74,6 +74,25 @@ dumpTableHTMLSub = function (table, space) return r end +local plurals = function(e, w) + local result = "" + if 1 == e then + result = e .. " error" + elseif e ~= 0 then + result = e .. " errors" + end + if 0 < w then + if 0 < e then result = result .. ", " end + if 1 == w then + result = result .. w .. " warning" + else + result = result .. w .. " warnings" + end + end + if "" ~= result then result = " (" .. result .. ")" end + return result +end + local results = {} local log = function(v, t, s, prot, test, host) @@ -131,27 +150,13 @@ local status = function(host, results, typ) end end - if 0 < e then result = e .. " errors" end - if 1 == e then result = e .. " error" end - if 0 < w then - if 0 < e then result = result .. ", " end - if 1 == w then - result = result .. w .. " warning" - else - result = result .. w .. " warnings" - end - end - if "[OK]" ~= result then - if 0 < e then - result = "[FAILED] (" .. result .. ")" - faulty = faulty .. host .. " (" .. typ .. ")
\n" - elseif 0 < w then - result = "[OK] (" .. result .. ")" - else - result = "[OK]" - end + if 0 < e then + result = "[FAILED]" + faulty = faulty .. host .. " (" .. typ .. ")
\n" + else + result = "[OK]" end - return result + return result .. plurals(e, w) end local collate = function(host, ip, results) @@ -188,6 +193,31 @@ end local mirrors = loadfile("results/mirrors.lua")() local m = {} +local logCount = function(domain, ip) + local nm = "LOG_" .. domain + local log = "" + local extra = "" + if nil ~= ip then nm = nm .. "_" .. ip end + nm = nm .. ".html" + local rfile, e = io.open("results/" .. nm, "r") + if nil ~= rfile then + local errors = 0 + local warnings = 0 + for l in rfile:lines() do + if nil ~= l:match(">ERROR ") then errors = errors + 1 end + if nil ~= l:match(">WARNING ") then warnings = warnings + 1 end + end + rfile:close() + if nil == ip then + log = "" .. domain .. "" + else + log = "" .. ip .. "" + end + log = log .. plurals(errors, warnings) + end + return log +end + local file, e = io.open("results/Report-web.html", "w+") if nil == file then C("opening mirrors file - " .. e) else file:write( "apt-panopticon results\n" .. @@ -229,12 +259,7 @@ if nil == file then C("opening mirrors file - " .. e) else for k, v in pairs(mirrors) do local log = k local n = {} - local nm = "LOG_" .. k .. ".html" - local rfile, e = io.open("results/" .. nm, "r") - if nil ~= rfile then - rfile:close() - log = "" .. k .. "" - end + log = logCount(k) mirrors[k].Protocols = nil mirrors[k].FQDN = nil mirrors[k].Active = nil @@ -246,30 +271,18 @@ if nil == file then C("opening mirrors file - " .. e) else if type(w) == "table" then n[l] = {} for i, u in pairs(w) do - local nm = "LOG_" .. k .. "_" .. i .. ".html" - local rfile, e = io.open("results/" .. nm, "r") - if nil ~= rfile then - rfile:close() - n[l]["" .. i .. ""] = u - else - n[l][i] = u - end + local log = logCount(k, i) + if "" == log then n[l] = u else n[log] = u end end else - local nm = "LOG_" .. k .. "_" .. l .. ".html" - local rfile, e = io.open("results/" .. nm, "r") - if nil ~= rfile then - rfile:close() - n["" .. l .. ""] = w - else - n[l] = w - end + local log = logCount(k, l) + if "" == log then n[l] = w else n[log] = w end end end m[log .. " DNS entries -"] = n end file:write( "

This lists each mirror, and the DNS entries for that mirror. " .. - "The links point to the log files for each FDQN / IP combination that was checked. " .. + "The links point to the log files for " .. logCount("apt-panopticon") .. " for each FDQN / IP combination that was checked. " .. "If a mirror has a CNAME, that CNAME is listed along with that CNAMEs DNS entries. " .. "deb.devuan.org is the DNS round robin, which points to the mirrors that are part of the DNS-RR. " .. "pkgmaster.devuan.org is the master mirror, all the others sync to it. " .. -- cgit v1.1